Blame view

php/classes/AmdaAction.php 52 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',
2e7079bb   Benjamin Renard   First implementat...
13
										'request' => 'Request.xml', 'condition' => 'Request.xml', 'download' => 'Request.xml', 'statistic' => 'Request.xml',
735c653b   Elena.Budnik   rank at observato...
14
15
16
17
										'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;
735c653b   Elena.Budnik   rank at observato...
64
65
		$remoteBase = false;
		$isRemoteDataSet = false;
16035364   Benjamin Renard   First commit
66

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

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

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

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

10200969   Roipoussiere   Remove whitespace...
96
			switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
97
98
99
100
101
			{
				case 'sharedtimeTable':
				case 'sharedcatalog':
					$xmlName = SHAREDPATH.'/SharedObjectTree.xml';
					break;
10200969   Roipoussiere   Remove whitespace...
102
				case 'bkgWorks':
84db3b67   Nathanael Jourdane   Improve job toolt...
103
					// data/<user>/JOBS/jobs.xml
735c653b   Elena.Budnik   rank at observato...
104
105
106
					$xmlName = USERJOBDIR.$this->xmlFiles[$nodeType];
					break;
				case 'source':
10200969   Roipoussiere   Remove whitespace...
107
108
109
110
					$xmlName = DATAPATH.'RemoteData/'.$obj->baseId.'/base.xml';
					break;
				case 'destination':
					$xmlName = USERWSDIR.'RemoteParams.xml';
735c653b   Elena.Budnik   rank at observato...
111
					break;
b0f72ee0   Erdogan Furkan   #10557 For now
112
113
114
				case 'specialParam':
					$xmlName = DATAPATH.'SpecialParameters/SpecialParams.xml';
					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;
735c653b   Elena.Budnik   rank at observato...
134
					if ($child->hasChildNodes())
10200969   Roipoussiere   Remove whitespace...
135
136
						foreach ($child->childNodes as $grandChild)
							if ($grandChild -> nodeType == XML_ELEMENT_NODE)
735c653b   Elena.Budnik   rank at observato...
137
138
139
140
141
142
							{
									$isLeaf = false;
									break;
							}
					if ($child->tagName == 'folder')  $isLeaf = false;

10200969   Roipoussiere   Remove whitespace...
143
144
					//TODO MAKE PROPERLY  as function of nodetype !!!!
					$info = '';
8ba47f72   Benjamin Renard   rest actualisatio...
145
146
					$dim_1 = 1;
					$dim_2 = 1;
735c653b   Elena.Budnik   rank at observato...
147
					$id =  $child->getAttribute('xml:id');
10200969   Roipoussiere   Remove whitespace...
148
					$name = $child->getAttribute('name');
735c653b   Elena.Budnik   rank at observato...
149
					$help = $child->getAttribute('att');
735c653b   Elena.Budnik   rank at observato...
150
151
152
153
154

					$specialNode = false;
					$isParameter = false;
					$isAddable =  false;
					$isSimulation = false;
735c653b   Elena.Budnik   rank at observato...
155
					$rank = null;
e57cb025   Benjamin Renard   Fix most of error...
156
					$skip = FALSE;
698494ac   Benjamin Renard   Add tooltip for s...
157
					$last_update = 0;
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
							$specialNode = true;
84db3b67   Nathanael Jourdane   Improve job toolt...
163
164
165
166
167
168
							$childrenToReturn[] = [
								'text'     => $name,
								'id'       => $id,
								'nodeType' => $nodeType,
								'leaf'     => $isLeaf,
								'pid'      => $child->getAttribute('pid'),
b4bca467   Nathanael Jourdane   job tooltip: use ...
169
								'status'   => $child->getAttribute('status'),
84db3b67   Nathanael Jourdane   Improve job toolt...
170
								'jobType'  => $child->getAttribute('jobType'),
4711b5b4   Erdogan Furkan   Done
171
								'start'	   => $child->getAttribute('start'),
812bc03d   Nathanael Jourdane   update job info o...
172
								'info'     => $child->getAttribute('info')
84db3b67   Nathanael Jourdane   Improve job toolt...
173
							];
b4bca467   Nathanael Jourdane   job tooltip: use ...
174
							break;
33519521   Benjamin Renard   Fix saved request...
175

f569bae5   Benjamin Renard   Save download
176
						case 'download':
735c653b   Elena.Budnik   rank at observato...
177
						case 'condition':
33519521   Benjamin Renard   Fix saved request...
178
						case 'request':
2e7079bb   Benjamin Renard   First implementat...
179
						case 'statistic':
638db58d   Benjamin Renard   RequestMgr constr...
180
							$objectMgr = new RequestMgr($nodeType);
33519521   Benjamin Renard   Fix saved request...
181
							$info = $objectMgr->getObjectInfo($id);
698494ac   Benjamin Renard   Add tooltip for s...
182
183
184
185
							$obj_info = $objectMgr->getObject($id);
							if (!empty($obj_info) && !empty($obj_info->last_update)) {
								$last_update = $obj_info->last_update;
							}
f569bae5   Benjamin Renard   Save download
186
							break;
8b6bb092   Elena.Budnik   icones if rank is...
187
						
735c653b   Elena.Budnik   rank at observato...
188
						case 'timeTable':
10200969   Roipoussiere   Remove whitespace...
189
						case 'catalog':
8dec1016   Benjamin Renard   Add TT and catalo...
190
191
							if ($isLeaf) {
								$info = '<b>Nb intervals:</b> '.$child->getAttribute('intervals').'<br/>';
533ea933   Benjamin Renard   Show description ...
192
193
194
195
196
197
198

								$objectMgr = new TimeTableMgr();
								$obj_info = $objectMgr->getObject($id, $nodeType);
								if (!empty($obj_info) && !empty($obj_info['description'])) {
									$info .= '<b>Description:</b> '. $obj_info['description'] . '<br/>';
								}

8dec1016   Benjamin Renard   Add TT and catalo...
199
								$info .= '<b>ID:</b> '. $child->getAttribute('xml:id');
533ea933   Benjamin Renard   Show description ...
200

8dec1016   Benjamin Renard   Add TT and catalo...
201
							}
735c653b   Elena.Budnik   rank at observato...
202
						break;
10200969   Roipoussiere   Remove whitespace...
203

735c653b   Elena.Budnik   rank at observato...
204
205
						case 'sharedtimeTable':
						case 'sharedcatalog':
10200969   Roipoussiere   Remove whitespace...
206
							if ($isLeaf)
735c653b   Elena.Budnik   rank at observato...
207
208
209
							{
								$info = '<b>Nb intervals:</b> '.$child->getAttribute('nbIntervals').'<br/>';
								$info .= '<b>Shared by:</b> '.$child->getAttribute('sharedBy').' ('.$child->getAttribute('sharedDate').')<br/>';
8dec1016   Benjamin Renard   Add TT and catalo...
210
211
								$info .= '<b>Description:</b> '.$child->getAttribute('description').'<br/>';
								$info .= '<b>ID:</b> ' . $child->getAttribute('xml:id');
8b6bb092   Elena.Budnik   icones if rank is...
212
							} 
735c653b   Elena.Budnik   rank at observato...
213
214
						break;
						case 'derivedParam':
533ea933   Benjamin Renard   Show description ...
215
  							$info = '<b>Expression:</b> '. $child->getAttribute('buildchain').'<br/>';
5f42fc77   Hacene SI HADJ MOHAND   get attributes ko
216
							                                        
dfa8db4f   Hacene SI HADJ MOHAND   correcting derive...
217
218
							if($child->hasAttribute('units') && $child->getAttribute('units') != 'undefined' && $child->getAttribute('units') != '')
                                                                                                                                                  $info .= 'Units: '.$child->getAttribute('units').'<br/>';
5f42fc77   Hacene SI HADJ MOHAND   get attributes ko
219
220
   							$samplingMode = $child->getAttribute('sampling_mode');
 						  	if($samplingMode == 'timestep'){
533ea933   Benjamin Renard   Show description ...
221
      								$info .= '<b>Sampling:</b> '.$child->getAttribute('timestep').' sec'.'<br/>';
5f42fc77   Hacene SI HADJ MOHAND   get attributes ko
222
   							}else if($samplingMode == 'refparam'){
533ea933   Benjamin Renard   Show description ...
223
      								$info .= '<b>Reference Parameter:</b> '.$child->getAttribute('reference_param').'<br/>';
5f42fc77   Hacene SI HADJ MOHAND   get attributes ko
224
			 	 			}			
0fea5567   Benjamin Renard   First step for re...
225

8ba47f72   Benjamin Renard   rest actualisatio...
226
227
228
229
230
							if ($child->hasAttribute('dim_1')) {
								$dim_1 = $child->getAttribute('dim_1');
							}
					                if ($child->hasAttribute('dim_2')) {
                                                                $dim_2 = $child->getAttribute('dim_2');
533ea933   Benjamin Renard   Show description ...
231

8ba47f72   Benjamin Renard   rest actualisatio...
232
233
                                                        }

533ea933   Benjamin Renard   Show description ...
234
235
236
237
238
239
240
241
							$objectMgr = new DerivedParamMgr($nodeType);
							$obj_info = $objectMgr->getObject($child->getAttribute('xml:id')) ;
							if (!empty($obj_info) && array_key_exists('description', $obj_info) && ($obj_info['description'] != "undefined")) {
								$info .= '<b>Description:</b> '. $obj_info['description'].'<br/>';
							}

							$info .= '<b>ID:</b> '. $child->getAttribute('xml:id');

735c653b   Elena.Budnik   rank at observato...
242
243
244
245
							if ($isLeaf) $isParameter = true;
						break;

						case 'localParam':
98c92bbf   Erdogan Furkan   #10557 - Done (Ma...
246
							
735c653b   Elena.Budnik   rank at observato...
247
248
249
250
251
252
							$globalStart = null;
							$globalStop = null;
							$timeRestriction = false;
							$specialNode = true;
							$isParameter = false;
							$needsArgs = false;
10200969   Roipoussiere   Remove whitespace...
253
							$isSpectra = false;
dc9e2c14   Elena.Budnik   init + message + ...
254
							$is2dSpectra = false;
735c653b   Elena.Budnik   rank at observato...
255
							$isStack = false;
e57cb025   Benjamin Renard   Fix most of error...
256
							$not_yet = false;
735c653b   Elena.Budnik   rank at observato...
257

10200969   Roipoussiere   Remove whitespace...
258
259
							if ($child->hasAttribute('desc'))
							{
735c653b   Elena.Budnik   rank at observato...
260
								$info = $child->getAttribute('desc');
10200969   Roipoussiere   Remove whitespace...
261

c57c57c9   Elena.Budnik   info message depe...
262
								if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop')) {
67bd6ed6   Elena.Budnik   rm 8375
263
264
265
266
267
268
269
                                    $dataStart = $child->getAttribute('dataStart');
                                    // check UTC format
                                    if ( !preg_match('/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/', $dataStart ) ) {
                                        if ( $dataStart == "MissionDependent" )
                                            $info .= "<br/>Time Range : depending on mission selection"; 
                                        else 
                                            $info .= "<br/>Time Range : undefined"; 
3a8eaaff   Hacene SI HADJ MOHAND   resolue
270
271
                                        $child->setAttribute('dataStart', date("Y-m-d\TH:i:s.u\Z", strtotime(' -1 day')));
                                        $child->setAttribute('dataStop', date("Y-m-d\TH:i:s.u\Z", time()));                                        
67bd6ed6   Elena.Budnik   rm 8375
272
273
274
275
                                    } else {
                                        $info .= "<br/>Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop');
                                    }
                                    
a7316784   Elena.Budnik   add LastUpdate to...
276
277
278
									if ($child->hasAttribute('lastUpdate')) {
										$info .= "<br/>Last Updated: : ".$child->getAttribute('lastUpdate');
									}
735c653b   Elena.Budnik   rank at observato...
279
								}
735c653b   Elena.Budnik   rank at observato...
280
							}
10200969   Roipoussiere   Remove whitespace...
281

cbbbdc34   Elena.Budnik   param description...
282
							if ($child->hasAttribute('units')) {
0fea5567   Benjamin Renard   First step for re...
283

cbbbdc34   Elena.Budnik   param description...
284
								$units = $child->getAttribute('units');
0fea5567   Benjamin Renard   First step for re...
285

cbbbdc34   Elena.Budnik   param description...
286
287
								if ($child->hasAttribute('description'))
									$info = $child->getAttribute('description')."<br/>".$units;
0fea5567   Benjamin Renard   First step for re...
288
								else
cbbbdc34   Elena.Budnik   param description...
289
290
									$info = $units;
							}
71b9368c   Benjamin Renard   Fix bug with tool...
291
292
293
294
							else {
								if ($child->hasAttribute('description'))
									$info = $child->getAttribute('description');
							}
0fea5567   Benjamin Renard   First step for re...
295

f29c5e66   Elena.Budnik   plot only option
296
							if ($child->tagName == 'parameter') {
735c653b   Elena.Budnik   rank at observato...
297
								$isParameter = true;
67bd6ed6   Elena.Budnik   rm 8375
298
299
                                if ($child->hasAttribute('TemplatedParameter'))
                                    $needsArgs = true;
2fa56f95   Benjamin Renard   Predefined templa...
300

b0f72ee0   Erdogan Furkan   #10557 For now
301
302
								if ($child->hasAttribute('PredefinedTemplatedParameter'))
									$predefinedArgs = true;
67bd6ed6   Elena.Budnik   rm 8375
303
                                    
c57c57c9   Elena.Budnik   info message depe...
304
								if ($child->parentNode->hasAttribute('dataStart')) {
735c653b   Elena.Budnik   rank at observato...
305
									$globalStart = $child->parentNode->getAttribute('dataStart');
10200969   Roipoussiere   Remove whitespace...
306
									$globalStop = $child->parentNode->getAttribute('dataStop');
735c653b   Elena.Budnik   rank at observato...
307
								}
0fea5567   Benjamin Renard   First step for re...
308

f29c5e66   Elena.Budnik   plot only option
309
310
311
312
								if ($child->parentNode->hasAttribute('restriction')) {
									if ($child->parentNode->getAttribute('restriction') == "plotOnly") {
										$not_yet = true;
									}
10200969   Roipoussiere   Remove whitespace...
313
								}
3afe4f59   Benjamin Renard   Add datasets time...
314
315
316
317

								if ($child->parentNode->hasAttribute('timeRestriction')) {
									$timeRestriction = $child->parentNode->getAttribute('timeRestriction');
								}
735c653b   Elena.Budnik   rank at observato...
318
							}
10200969   Roipoussiere   Remove whitespace...
319

735c653b   Elena.Budnik   rank at observato...
320
321
322
323
							$component_info = array();
							if ($child->tagName == 'component')
							{
								$isParameter = true;
735c653b   Elena.Budnik   rank at observato...
324

c57c57c9   Elena.Budnik   info message depe...
325
								if ($child->parentNode->parentNode->hasAttribute('dataStart')) {
735c653b   Elena.Budnik   rank at observato...
326
									$globalStart = $child->parentNode->parentNode->getAttribute('dataStart');
10200969   Roipoussiere   Remove whitespace...
327
328
									$globalStop = $child->parentNode->parentNode->getAttribute('dataStop');
								}
0fea5567   Benjamin Renard   First step for re...
329

f29c5e66   Elena.Budnik   plot only option
330
331
332
333
								if ($child->parentNode->parentNode->hasAttribute('restriction')) {
									if ($child->parentNode->parentNode->getAttribute('restriction') == "plotOnly") {
										$not_yet = true;
									}
10200969   Roipoussiere   Remove whitespace...
334
								}
3afe4f59   Benjamin Renard   Add datasets time...
335
336
337
338

								if ($child->parentNode->parentNode->hasAttribute('timeRestriction')) {
									$timeRestriction = $child->parentNode->parentNode->getAttribute('timeRestriction');
								}
735c653b   Elena.Budnik   rank at observato...
339
340
341
342
343

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

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

f29c5e66   Elena.Budnik   plot only option
348
							if ($child->tagName == 'parameter' && $child->hasAttribute('display_type')){
c57c57c9   Elena.Budnik   info message depe...
349
								if ($child->getAttribute('display_type') == 'spectrogram') {
10200969   Roipoussiere   Remove whitespace...
350
351
										$needsArgs = true;
										$isSpectra = true;
dc9e2c14   Elena.Budnik   init + message + ...
352
353
										if (strpos($child->getAttribute('name'),'2D') !== false)
											$is2dSpectra = true;
735c653b   Elena.Budnik   rank at observato...
354
								}
c57c57c9   Elena.Budnik   info message depe...
355
								elseif ($child->getAttribute('display_type') == 'stackplot') {
735c653b   Elena.Budnik   rank at observato...
356
										$isStack = true;
735c653b   Elena.Budnik   rank at observato...
357
								}
10200969   Roipoussiere   Remove whitespace...
358
359
							}

f31bea1c   Benjamin Renard   wip for save plot
360

c57c57c9   Elena.Budnik   info message depe...
361
							if ($isParameter) {
735c653b   Elena.Budnik   rank at observato...
362
363
								$objectMgr = new AliasMgr();
								$alias = $objectMgr->getAlias($id);
c3b20775   Elena.Budnik   not show ID for p...
364
365
								
                                if (! ($child->parentNode->hasAttribute('group') || $child->parentNode->parentNode->hasAttribute('group'))) $info .= '</br><i>ID : '.$id.'</i>';
661293d7   Elena.Budnik   parse ## and @@ i...
366
								$childrenToReturn[] = array('text' => $name,'alias' => $alias,
735c653b   Elena.Budnik   rank at observato...
367
368
									'id' => $id,'nodeType' => $nodeType, 'info' => $info, "component_info" => $component_info,
									'globalStart' => $globalStart, 'globalStop' => $globalStop, 'timeRestriction' => $timeRestriction,
dc9e2c14   Elena.Budnik   init + message + ...
369
									'leaf' => $isLeaf, 'isParameter' => $isParameter,'isSpectra' => $isSpectra,
2fa56f95   Benjamin Renard   Predefined templa...
370
									'is2dSpectra' => $is2dSpectra,'isStack' => $isStack, 'needsArgs' => $needsArgs, 'predefinedArgs' => $predefinedArgs, 'help' => $help, 'notyet' => $not_yet);
735c653b   Elena.Budnik   rank at observato...
371
							}
c57c57c9   Elena.Budnik   info message depe...
372
							else {
8b6bb092   Elena.Budnik   icones if rank is...
373
								if ($child->hasAttribute('rank')) {
735c653b   Elena.Budnik   rank at observato...
374
375
									$rank = $child->getAttribute('rank');
								}
0fea5567   Benjamin Renard   First step for re...
376

3afe4f59   Benjamin Renard   Add datasets time...
377
378
379
380
								if ($child->hasAttribute("timeRestriction")) {
									$timeRestriction = $child->getAttribute("timeRestriction");
								}
								$disable = TRUE;
acf87705   Elena.Budnik   bug in disable param
381

222e562d   Benjamin Renard   Give the possibil...
382
383
384
385
386
								$hideIfRestricted = FALSE;
								if ($child->hasAttribute("hideIfRestricted") && ($child->getAttribute("hideIfRestricted") == "1")) {
									$hideIfRestricted = TRUE;
								}

3afe4f59   Benjamin Renard   Add datasets time...
387
								if ($child->hasAttribute('group')) {
c3976709   Elena.Budnik   rm 7589 + clean u...
388
389
									if ($child->getAttribute("group") === "TBD") {
											$info .=  "<br/><b>Under Testing</b>";
3afe4f59   Benjamin Renard   Add datasets time...
390
									}
1c2f5368   Elena.Budnik   message for TimeR...
391
									else {	
3afe4f59   Benjamin Renard   Add datasets time...
392
393
										if (!empty($timeRestriction)) {
											$disable = FALSE;
3a8eaaff   Hacene SI HADJ MOHAND   resolue
394
											$formattedTimeRestriction = date("Y-m-d\TH:i:s.u\Z",strtotime($timeRestriction)+1);
1c2f5368   Elena.Budnik   message for TimeR...
395
396
397
398
											$info .= "<br/><b>After $formattedTimeRestriction data are restricted to group ".$child->getAttribute('group')."</b>";
										}
										else {
                                            $info .= "<br/><b>Restricted Access : Group ".$child->getAttribute('group')."</b>";
3afe4f59   Benjamin Renard   Add datasets time...
399
										}
735c653b   Elena.Budnik   rank at observato...
400
									}
0fea5567   Benjamin Renard   First step for re...
401
								}
acf87705   Elena.Budnik   bug in disable param
402
								else {
3afe4f59   Benjamin Renard   Add datasets time...
403
									$disable = FALSE;
acf87705   Elena.Budnik   bug in disable param
404
405
									if ($child->hasAttribute('restriction') && $child->getAttribute('restriction') == 'plotOnly')
										$info .=  "<br/><b>Plot Only!!!</b>";
735c653b   Elena.Budnik   rank at observato...
406
								}
222e562d   Benjamin Renard   Give the possibil...
407
								$visible = !($disable && $hideIfRestricted);
735c653b   Elena.Budnik   rank at observato...
408

698494ac   Benjamin Renard   Add tooltip for s...
409
								$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType,  'info' => $info, 'last_update' => $last_update,
222e562d   Benjamin Renard   Give the possibil...
410
									'leaf' => false, 'help' => $help, 'disable' => $disable, 'visible' => $visible, 'rank' => $rank, 'timeRestriction' => $timeRestriction);
735c653b   Elena.Budnik   rank at observato...
411
412
413
414
							}
						break;

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

bf74fc2d   Elena.Budnik   IMPEX
416
							$globalStart = null;
6657f68b   Elena.Budnik   monitor impex ser...
417
							$service_down = false;
735c653b   Elena.Budnik   rank at observato...
418
							$isSimulation = true;
10200969   Roipoussiere   Remove whitespace...
419
420

			            if ($child->getAttribute('isAddable')) // 'spase://IMPEX/SimulationModel/FMI/GUMICS'
735c653b   Elena.Budnik   rank at observato...
421
422
423
424
							{
								$isLeaf = false;
								$isAddable = true;
							}
10200969   Roipoussiere   Remove whitespace...
425
426

							if ($child->tagName == 'dataCenter')
735c653b   Elena.Budnik   rank at observato...
427
							{
10200969   Roipoussiere   Remove whitespace...
428
								if ($child->getAttribute('isSimulation'))
6657f68b   Elena.Budnik   monitor impex ser...
429
								{
10200969   Roipoussiere   Remove whitespace...
430
431
									$service_down = !($child->getAttribute('available'));
									break;
6657f68b   Elena.Budnik   monitor impex ser...
432
								}
10200969   Roipoussiere   Remove whitespace...
433
								else
735c653b   Elena.Budnik   rank at observato...
434
435
436
437
438
								{
									$skip = true;
									break;
								}
							}
10200969   Roipoussiere   Remove whitespace...
439
440

							if ($child->hasAttribute('rank'))
735c653b   Elena.Budnik   rank at observato...
441
442
443
							{
								$rank = $child->getAttribute('rank');
							}
10200969   Roipoussiere   Remove whitespace...
444

bf74fc2d   Elena.Budnik   IMPEX
445
446
							if ( $child->tagName == 'parameter')
							{
abb54096   Elena.Budnik   time interval by ...
447
								if ($child->parentNode->hasAttribute('globalStart'))
bf74fc2d   Elena.Budnik   IMPEX
448
									{
abb54096   Elena.Budnik   time interval by ...
449
450
										$globalStart = $child->parentNode->getAttribute('globalStart');
										$globalStop = $child->parentNode->getAttribute('globalStop');
bf74fc2d   Elena.Budnik   IMPEX
451
452
									}
							}
10200969   Roipoussiere   Remove whitespace...
453

bf74fc2d   Elena.Budnik   IMPEX
454
455
							if ( $child->tagName == 'component')
							{
abb54096   Elena.Budnik   time interval by ...
456
								if ($child->parentNode->parentNode->hasAttribute('globalStart'))
bf74fc2d   Elena.Budnik   IMPEX
457
									{
abb54096   Elena.Budnik   time interval by ...
458
459
										$globalStart = $child->parentNode->parentNode->getAttribute('globalStart');
										$globalStop = $child->parentNode->parentNode->getAttribute('globalStop');
bf74fc2d   Elena.Budnik   IMPEX
460
461
									}
							}
10200969   Roipoussiere   Remove whitespace...
462

735c653b   Elena.Budnik   rank at observato...
463
						case 'remoteParam' :
10200969   Roipoussiere   Remove whitespace...
464
465

							if ($child->getAttribute('isSimulation') && $child->tagName == 'dataCenter')
735c653b   Elena.Budnik   rank at observato...
466
467
468
469
470
471
472
							{
								$skip = true;
								break;
							}

							$isDeletable = $child->hasAttribute('isDeletable');
							$specialNode = true;
10200969   Roipoussiere   Remove whitespace...
473
474
475
476
477
							$isParameter = false;

							$isSpectra = false;

							switch ($id)
735c653b   Elena.Budnik   rank at observato...
478
							{
10200969   Roipoussiere   Remove whitespace...
479
								case 'CDAWEB'  :
735c653b   Elena.Budnik   rank at observato...
480
481
482
								case 'THEMIS' :
									$rank = 5;
									break;
735c653b   Elena.Budnik   rank at observato...
483
484
								default:
							}
10200969   Roipoussiere   Remove whitespace...
485

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

10200969   Roipoussiere   Remove whitespace...
488
489
							if ($info && !$isSimulation)
							{
735c653b   Elena.Budnik   rank at observato...
490
								$info = str_replace(';', "<br/>Time Range: ", $info);
10200969   Roipoussiere   Remove whitespace...
491
492
493
							}

							if (($child->tagName == 'parameter') || ($child->tagName == 'component'))
735c653b   Elena.Budnik   rank at observato...
494
495
							{
								$isParameter = true;
735c653b   Elena.Budnik   rank at observato...
496
							}
10200969   Roipoussiere   Remove whitespace...
497

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

10200969   Roipoussiere   Remove whitespace...
500
							if ($remoteBase)
735c653b   Elena.Budnik   rank at observato...
501
							{
10200969   Roipoussiere   Remove whitespace...
502
								if ($child->tagName == 'dataset') $isRemoteDataSet = true;
735c653b   Elena.Budnik   rank at observato...
503
							}
0fea5567   Benjamin Renard   First step for re...
504

a0f13ed1   Elena.Budnik   small format + ti...
505
506
							if ($child->tagName == 'parameter'){
								if ($child->parentNode->hasAttribute('dataStart')){
3a8eaaff   Hacene SI HADJ MOHAND   resolue
507
508
									$globalStart = date('Y-m-d\TH:i:s.u\Z', strtotime($child->parentNode->getAttribute('dataStart')));
									$globalStop = date('Y-m-d\TH:i:s.u\Z',  strtotime($child->parentNode->getAttribute('dataStop')));
a0f13ed1   Elena.Budnik   small format + ti...
509
510
								}
							}
735c653b   Elena.Budnik   rank at observato...
511

a0f13ed1   Elena.Budnik   small format + ti...
512
513
							if ( $child->tagName == 'component'){
								if ($child->parentNode->parentNode->hasAttribute('dataStart')){
3a8eaaff   Hacene SI HADJ MOHAND   resolue
514
515
									$globalStart = date('Y-m-d\TH:i:s.u\Z', strtotime($child->parentNode->getAttribute('dataStart')));
									$globalStop = date('Y-m-d\TH:i:s.u\Z',  strtotime($child->parentNode->getAttribute('dataStop')));
a0f13ed1   Elena.Budnik   small format + ti...
516
517
								}
							}
0fea5567   Benjamin Renard   First step for re...
518

10200969   Roipoussiere   Remove whitespace...
519
							if ($isParameter)
735c653b   Elena.Budnik   rank at observato...
520
							{
10200969   Roipoussiere   Remove whitespace...
521
								$disable = $child->parentNode->getAttribute('disabled');
735c653b   Elena.Budnik   rank at observato...
522
523
524
525
526
								$objectMgr = new AliasMgr();
								$alias = $objectMgr->getAlias($id);

								if ($child->hasAttribute('display_type') && $child->getAttribute('display_type') == 'spectrogram')
								{
10200969   Roipoussiere   Remove whitespace...
527
									$needsArgs = true;
735c653b   Elena.Budnik   rank at observato...
528
									$isSpectra = true;
10200969   Roipoussiere   Remove whitespace...
529
								}
bf74fc2d   Elena.Budnik   IMPEX
530
								if ($globalStart)
10200969   Roipoussiere   Remove whitespace...
531
								 $childrenToReturn[] = array('text' => $name,'alias' => $alias,
bf74fc2d   Elena.Budnik   IMPEX
532
										'id' => $id,'nodeType' => $nodeType,  'info' => $info, 'help' => $help,  'globalStart' => $globalStart,
10200969   Roipoussiere   Remove whitespace...
533
										'globalStop' => $globalStop, 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
1c007ca2   Elena.Budnik   vector icon for M...
534
										'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => isset($component_info) ? $component_info : NULL);
bf74fc2d   Elena.Budnik   IMPEX
535
								else
10200969   Roipoussiere   Remove whitespace...
536
									$childrenToReturn[] = array('text' => $name,'alias' => $alias,
bf74fc2d   Elena.Budnik   IMPEX
537
										'id' => $id,'nodeType' => $nodeType,  'info' => $info, 'help' => $help,
10200969   Roipoussiere   Remove whitespace...
538
										'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
1c007ca2   Elena.Budnik   vector icon for M...
539
										'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
735c653b   Elena.Budnik   rank at observato...
540
							}
10200969   Roipoussiere   Remove whitespace...
541
542
							else
							{
e57cb025   Benjamin Renard   Fix most of error...
543
								$restricted = FALSE;
0fea5567   Benjamin Renard   First step for re...
544

735c653b   Elena.Budnik   rank at observato...
545
								if ($child->tagName == 'dataset')
6657f68b   Elena.Budnik   monitor impex ser...
546
								{
735c653b   Elena.Budnik   rank at observato...
547
									$nonavailable = ($child->getAttribute('disabled'));
6657f68b   Elena.Budnik   monitor impex ser...
548
								}
735c653b   Elena.Budnik   rank at observato...
549
								else
6657f68b   Elena.Budnik   monitor impex ser...
550
								{
735c653b   Elena.Budnik   rank at observato...
551
									$nonavailable = false;
6657f68b   Elena.Budnik   monitor impex ser...
552
								}
10200969   Roipoussiere   Remove whitespace...
553

735c653b   Elena.Budnik   rank at observato...
554
555
556
557
558
559
								if ($nonavailable)
									$info .= "<br/><b>Not available yet</b>";

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

10200969   Roipoussiere   Remove whitespace...
560
								if ($child->hasAttribute('obsolete'))
735c653b   Elena.Budnik   rank at observato...
561
562
563
564
565
566
567
568
								{
									$info = $child->getAttribute('desc');
									$obsolete = true;
								}
								else
									$obsolete = false;

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

735c653b   Elena.Budnik   rank at observato...
570
								$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType,  'isAddable' => $isAddable,
10200969   Roipoussiere   Remove whitespace...
571
572
573
								'info' => $info, 'leaf' => false, 'isRemoteDataSet' => $isRemoteDataSet, 'disable' => $disable,
								'isSimulation' => $isSimulation, 'rank' => $rank, 'isDeletable' => $isDeletable, 'help' => $help);
							}
735c653b   Elena.Budnik   rank at observato...
574
						break;
10200969   Roipoussiere   Remove whitespace...
575
576
577

						case 'myData' :
							$info = $child->hasAttribute('info') ? $child->getAttribute('info') : $child->nodeValue;
735c653b   Elena.Budnik   rank at observato...
578
579
580
581
582
583
584
585
						break;

						case 'myDataParam' :

							$globalStart = null;
							$globalStop = null;
							$specialNode = true;
							$size = $child->getAttribute('size');
735c653b   Elena.Budnik   rank at observato...
586
							$mask = $child->getAttribute('mask');
19dcd963   Elena.Budnik   redmine #4903 : s...
587
							$sampling = null;
0fea5567   Benjamin Renard   First step for re...
588
							if ($child->hasAttribute('minsampling'))
19dcd963   Elena.Budnik   redmine #4903 : s...
589
								$sampling = $child->getAttribute('minsampling');
735c653b   Elena.Budnik   rank at observato...
590
							$isSpectra = false;
10200969   Roipoussiere   Remove whitespace...
591
592

							if ($isLeaf)
735c653b   Elena.Budnik   rank at observato...
593
594
595
							{
									$isParameter = true;
									$info = "Size: ".$size."<br/>".$child->getAttribute('desc')."<br/> Mask: ".$mask;
19dcd963   Elena.Budnik   redmine #4903 : s...
596
597
									if ($sampling)
										$info .= "<br/> Sampling : ".$sampling;
735c653b   Elena.Budnik   rank at observato...
598
599
600
									$isSpectra = $child->getAttribute('plottype') === 'Spectra';
							}

10200969   Roipoussiere   Remove whitespace...
601
							if ($child->hasAttribute('desc'))
735c653b   Elena.Budnik   rank at observato...
602
603
604
605
606
							{
									$globalStart = substr($child->getAttribute('desc'), 0, 19);
									$globalStop =  substr($child->getAttribute('desc'), 20);
							}

10200969   Roipoussiere   Remove whitespace...
607
							$childrenToReturn[] = array('text' => $name, 'size' =>  $size, 'id' => $id,
735c653b   Elena.Budnik   rank at observato...
608
								'globalStart' => $globalStart, 'globalStop' => $globalStop,
1c007ca2   Elena.Budnik   vector icon for M...
609
								'nodeType' => $nodeType, 'info' => $info,  'leaf' => $isLeaf,
735c653b   Elena.Budnik   rank at observato...
610
611
612
								'isParameter' => $isParameter, 'linkedMask' => $mask, 'isSpectra' => $isSpectra);

						break;
b0f72ee0   Erdogan Furkan   #10557 For now
613
614
						
						case 'specialParam':
98c92bbf   Erdogan Furkan   #10557 - Done (Ma...
615
616
617
							$specialNode=TRUE;
							$isParameter=($child->tagName == 'parameter');
							$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'isParameter' => $isParameter, 'needsArgs' => $isParameter, 'leaf' => $isParameter);
b0f72ee0   Erdogan Furkan   #10557 For now
618
619
							break;
						
10200969   Roipoussiere   Remove whitespace...
620
						default:
735c653b   Elena.Budnik   rank at observato...
621
					}
10200969   Roipoussiere   Remove whitespace...
622
623

					if (!$specialNode && !$skip)
735c653b   Elena.Budnik   rank at observato...
624
					{
10200969   Roipoussiere   Remove whitespace...
625
						if ($child->hasAttribute('desc'))
735c653b   Elena.Budnik   rank at observato...
626
							$info = $child->getAttribute('desc');
10200969   Roipoussiere   Remove whitespace...
627
628

						if ($isSimulation && $service_down)
6657f68b   Elena.Budnik   monitor impex ser...
629
630
631
						{
							$info = "<b>Service is currently down</b>";
						}
10200969   Roipoussiere   Remove whitespace...
632
633

						$childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info,
2048f5bc   Benjamin Renard   Fix save & edit plot
634
													'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter, 'dim_1' => $dim_1, 'dim_2' => $dim_2,
0fea5567   Benjamin Renard   First step for re...
635
													'component_info' => isset($component_info) ? $component_info : NULL,
698494ac   Benjamin Renard   Add tooltip for s...
636
													'iconCls' => isset($iconCls) ? $iconCls : NULL, 'last_update' => $last_update );
735c653b   Elena.Budnik   rank at observato...
637
638
639
					}
				}
				// if $childrenToReturn we have to return []
e57cb025   Benjamin Renard   Fix most of error...
640
				if (empty($childrenToReturn))
10200969   Roipoussiere   Remove whitespace...
641
				{
735c653b   Elena.Budnik   rank at observato...
642
643
644
					$childrenToReturn = array('nodeType' => $nodeType, 'text' => null);
				}
			}
16035364   Benjamin Renard   First commit
645
      return  $childrenToReturn;
735c653b   Elena.Budnik   rank at observato...
646
	}
16035364   Benjamin Renard   First commit
647

0dc31ba8   Elena.Budnik   remoteParamManage...
648
649
650
	/*
	*  add Remote Parameter to user RemoteParams.xml
	*  send request to DDServer to AddVi if Vi doesn't exist
0fea5567   Benjamin Renard   First step for re...
651
	*  create Remote Parameter Description
0dc31ba8   Elena.Budnik   remoteParamManage...
652
	*/
10200969   Roipoussiere   Remove whitespace...
653
	public  function saveTree($obj)
735c653b   Elena.Budnik   rank at observato...
654
	{
0dc31ba8   Elena.Budnik   remoteParamManage...
655
		$paramMgr = new RemoteParamManager();
2b8ea2a7   Elena.Budnik   RemoteParamManage...
656
		$res = $paramMgr->init();
0fea5567   Benjamin Renard   First step for re...
657

2b8ea2a7   Elena.Budnik   RemoteParamManage...
658
659
		if ($res['success'])
			return $paramMgr->saveTree($obj);
0fea5567   Benjamin Renard   First step for re...
660
		else
2b8ea2a7   Elena.Budnik   RemoteParamManage...
661
			return $res;
735c653b   Elena.Budnik   rank at observato...
662
	}
0fea5567   Benjamin Renard   First step for re...
663

0dc31ba8   Elena.Budnik   remoteParamManage...
664
665
666
	/*
	*  delete Remote Parameter from user RemoteParams.xml
	*/
10200969   Roipoussiere   Remove whitespace...
667
668
	public  function deleteFromTree($obj)
	{
0dc31ba8   Elena.Budnik   remoteParamManage...
669
		$paramMgr = new RemoteParamManager();
2b8ea2a7   Elena.Budnik   RemoteParamManage...
670
		$res = $paramMgr->init();
0fea5567   Benjamin Renard   First step for re...
671

2b8ea2a7   Elena.Budnik   RemoteParamManage...
672
673
		if ($res['success'])
			return $paramMgr->deleteFromTree($obj);
0fea5567   Benjamin Renard   First step for re...
674
		else
2b8ea2a7   Elena.Budnik   RemoteParamManage...
675
			return $res;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
676
	}
0fea5567   Benjamin Renard   First step for re...
677

0dc31ba8   Elena.Budnik   remoteParamManage...
678
679
680
681
	public  function doNothing($obj)
	{
		return array("res" => 'ok');
	}
16035364   Benjamin Renard   First commit
682

0dc31ba8   Elena.Budnik   remoteParamManage...
683
684
685
	/*
	*  get temporary object from Upload
	*/
9a63b7f6   Elena.Budnik   needsArgs to Simu...
686
	public  function getUploadedObject($name, $format, $nodeType)
10200969   Roipoussiere   Remove whitespace...
687
	{
5f8bd1f5   Nathanaël Jourdane   Fix Windows-files...
688
689
690
		$fileContent = preg_replace(['~\R~u', "/\t/"], ["\n", ' '], trim(file_get_contents(USERTEMPDIR . $name)));
		file_put_contents(USERTEMPDIR . $name, $fileContent);

42e2e019   Benjamin Renard   Next step for cac...
691
		$isTTCat = FALSE;
10200969   Roipoussiere   Remove whitespace...
692
		switch ($nodeType)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
693
		{
10200969   Roipoussiere   Remove whitespace...
694
695
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
42e2e019   Benjamin Renard   Next step for cac...
696
				$isTTCat = TRUE;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
697
				break;
10200969   Roipoussiere   Remove whitespace...
698
699
700
701
702
			case 'myDataParam' :
				$objectMgr = new FilesMgr();
				break;
			case 'catalog' :
				$objectMgr = new CatalogMgr();
42e2e019   Benjamin Renard   Next step for cac...
703
				$isTTCat = TRUE;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
704
				break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
705
706
707
			default:
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
42e2e019   Benjamin Renard   Next step for cac...
708
709
710
711
712
713
		if ($isTTCat) {
			//Pre-process: convert to INTERNAL format if needed
			if (($format == 'ASCII') || ($format == 'VOT')) {
				$result = $this->executeRequest((Object) array(
					'compression' => 'none',
					'fileformat' => 'internal',
217e6c35   Hacene SI HADJ MOHAND   affichage oki
714
                                        'timeformat' => 'YYYY-MM-DDThh:mm:ss.u',
42e2e019   Benjamin Renard   Next step for cac...
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
					'sendToSamp' => FALSE,
					'list' => array(
						(Object) array(
							'path' => USERTEMPDIR . $name,
							'format' => $format,
							'name' => pathinfo($name, PATHINFO_FILENAME),
						)
					),
				), FunctionTypeEnumClass::TTCONVERT);
				if (!$result['success']) {
					return array("error" => "Error during file conversion");
				}
				$name = basename($result['download']);
				$convertedFile = USERDIR.'/DOWNLOAD.TEMP/'.$name;
				if (!file_exists($convertedFile)) {
					return array("error" => "Error during file conversion");
				}

				$format = 'internal';
				rename($convertedFile, USERTEMPDIR . '/' . $name);
			}
		}
bf74fc2d   Elena.Budnik   IMPEX
737
		return  $objectMgr->getUploadedObject($name, $format, true);
10200969   Roipoussiere   Remove whitespace...
738
	}
16035364   Benjamin Renard   First commit
739

0dc31ba8   Elena.Budnik   remoteParamManage...
740
741
742
	/*
	*  fill ascii file into grid
	*/
10200969   Roipoussiere   Remove whitespace...
743
744
745
	public  function getAsciiFile($obj)
	{
		$objectMgr = new FilesMgr();
bf74fc2d   Elena.Budnik   IMPEX
746
		return  $objectMgr->getAsciiFile($obj->fileName);
735c653b   Elena.Budnik   rank at observato...
747
	}
10200969   Roipoussiere   Remove whitespace...
748
749
750
751

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

0dc31ba8   Elena.Budnik   remoteParamManage...
755
756
757
	/*
	*  get temporary object from Search
	*/
10200969   Roipoussiere   Remove whitespace...
758
759
760
	public  function getTmpObject($folderId, $name, $nodeType)
	{
		switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
761
		{
10200969   Roipoussiere   Remove whitespace...
762
763
764
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
			break;
735c653b   Elena.Budnik   rank at observato...
765
			case 'catalog' :
10200969   Roipoussiere   Remove whitespace...
766
767
				$objectMgr = new CatalogMgr();
			break;
735c653b   Elena.Budnik   rank at observato...
768
769
770
			default:
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
771
		return  $objectMgr->getTmpObject($folderId, $name, true);
fdf1413b   Elena.Budnik   TT download
772
	}
735c653b   Elena.Budnik   rank at observato...
773

10200969   Roipoussiere   Remove whitespace...
774
775
776
777

	public  function getObject($id, $nodeType)
	{
		switch ($nodeType)
735c653b   Elena.Budnik   rank at observato...
778
779
		{
			case 'myDataParam':
10200969   Roipoussiere   Remove whitespace...
780
781
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($nodeType);
735c653b   Elena.Budnik   rank at observato...
782
				break;
10200969   Roipoussiere   Remove whitespace...
783
			case 'timeTable' :
735c653b   Elena.Budnik   rank at observato...
784
			case 'sharedtimeTable' :
10200969   Roipoussiere   Remove whitespace...
785
786
				$objectMgr = new TimeTableMgr();
				break;
735c653b   Elena.Budnik   rank at observato...
787
788
			case 'catalog' :
			case 'sharedcatalog' :
10200969   Roipoussiere   Remove whitespace...
789
790
791
				$objectMgr = new CatalogMgr();
				break;
			case 'condition' :
735c653b   Elena.Budnik   rank at observato...
792
			case 'request' :
f569bae5   Benjamin Renard   Save download
793
			case 'download' :
2e7079bb   Benjamin Renard   First implementat...
794
			case 'statistic':
10200969   Roipoussiere   Remove whitespace...
795
796
				$objectMgr = new RequestMgr($nodeType);
				break;
0fea5567   Benjamin Renard   First step for re...
797
			case 'bkgWorks' :
735c653b   Elena.Budnik   rank at observato...
798
799
800
				return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO);
				break;
			case 'myData' :
10200969   Roipoussiere   Remove whitespace...
801
				$objectMgr = new FilesMgr();
735c653b   Elena.Budnik   rank at observato...
802
				break;
10200969   Roipoussiere   Remove whitespace...
803
			default:
735c653b   Elena.Budnik   rank at observato...
804
805
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
806
		return  $objectMgr->getObject($id, $nodeType);
fdf1413b   Elena.Budnik   TT download
807
	}
10200969   Roipoussiere   Remove whitespace...
808

16035364   Benjamin Renard   First commit
809
810
811
/*
*   $obj = { id: node.id, leaf: node.leaf, nodeType: node.nodeType }
*/
10200969   Roipoussiere   Remove whitespace...
812
813
814
815
816
817
818
	public  function deleteObject($obj)
	{
		switch ($obj->nodeType)
		{
			case 'myDataParam' :
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($obj->nodeType);
735c653b   Elena.Budnik   rank at observato...
819
				break;
10200969   Roipoussiere   Remove whitespace...
820
821
822
823
824
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
				break;
			case 'catalog' :
				$objectMgr = new CatalogMgr();
735c653b   Elena.Budnik   rank at observato...
825
				break;
10200969   Roipoussiere   Remove whitespace...
826
			case 'condition' :
735c653b   Elena.Budnik   rank at observato...
827
			case 'request' :
f569bae5   Benjamin Renard   Save download
828
			case 'download' :
2e7079bb   Benjamin Renard   First implementat...
829
			case 'statistic' :
10200969   Roipoussiere   Remove whitespace...
830
				$objectMgr = new RequestMgr($obj->nodeType);
735c653b   Elena.Budnik   rank at observato...
831
832
833
834
				break;
			case 'alias' :
				$objectMgr = new AliasMgr();
				$obj->id = substr($obj->id,strlen('alias_'));
10200969   Roipoussiere   Remove whitespace...
835
				break;
735c653b   Elena.Budnik   rank at observato...
836
			case 'bkgWorks' :
735c653b   Elena.Budnik   rank at observato...
837
838
839
				return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSDELETE);

			case 'myData' :
16035364   Benjamin Renard   First commit
840
				$objectMgr = new FilesMgr();
735c653b   Elena.Budnik   rank at observato...
841
842
843
844
845
846
				break;
			default:
					return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> deleteObject($obj);
	}
16035364   Benjamin Renard   First commit
847
848
849
850

/*
*   $obj = { id: node.id, old_name: node.text, name: value,  parent : node.parentNode.id, leaf: node.leaf, nodeType: node.nodeType }
*/
10200969   Roipoussiere   Remove whitespace...
851
852
853
	public  function renameObject($obj)
	{
		switch ($obj->nodeType)
735c653b   Elena.Budnik   rank at observato...
854
		{
10200969   Roipoussiere   Remove whitespace...
855

16035364   Benjamin Renard   First commit
856
		  case 'myDataParam' :
10200969   Roipoussiere   Remove whitespace...
857
858
859
860
861
		  case 'derivedParam' :
			   $objectMgr = new DerivedParamMgr($obj->nodeType);
			   break;
		  case 'timeTable' :
			   $objectMgr = new TimeTableMgr();
16035364   Benjamin Renard   First commit
862
			   break;
10200969   Roipoussiere   Remove whitespace...
863
864
		  case 'catalog' :
			   $objectMgr = new CatalogMgr();
d18b535d   elena   catalog draft + c...
865
			   break;
10200969   Roipoussiere   Remove whitespace...
866
867
		  case 'condition' :
		  case 'request' :
f569bae5   Benjamin Renard   Save download
868
		  case 'download' :
2e7079bb   Benjamin Renard   First implementat...
869
		  case 'statistic' :
10200969   Roipoussiere   Remove whitespace...
870
			   $objectMgr = new RequestMgr($obj->nodeType);
16035364   Benjamin Renard   First commit
871
872
			   break;
		  case 'alias' :
10200969   Roipoussiere   Remove whitespace...
873
874
		  	   $objectMgr = new AliasMgr();
		  	   break;
16035364   Benjamin Renard   First commit
875
876
		  default:
			    return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
735c653b   Elena.Budnik   rank at observato...
877
		}
16035364   Benjamin Renard   First commit
878

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

10200969   Roipoussiere   Remove whitespace...
882
/*
16035364   Benjamin Renard   First commit
883
884
*   $obj = { name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
10200969   Roipoussiere   Remove whitespace...
885
886
887
	public  function createObject($obj, $folder)
	{
		switch ($obj->nodeType)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
888
		{
10200969   Roipoussiere   Remove whitespace...
889
			case 'myDataParam' :
9a63b7f6   Elena.Budnik   needsArgs to Simu...
890
			case 'derivedParam' :
10200969   Roipoussiere   Remove whitespace...
891
				if ($obj->nodeType == 'derivedParam' &&  $this->amdaStat->success)
2dab1b1b   Elena.Budnik   change input args...
892
						$this->amdaStat->addTask($this->user, 'create', null);
10200969   Roipoussiere   Remove whitespace...
893
				$objectMgr = new DerivedParamMgr($obj->nodeType);
8ba47f72   Benjamin Renard   rest actualisatio...
894
                 	break;
10200969   Roipoussiere   Remove whitespace...
895
896
897
898
899
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
				break;
			case 'catalog' :
				$objectMgr = new CatalogMgr();
16035364   Benjamin Renard   First commit
900
			   break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
901
			case 'condition' :
10200969   Roipoussiere   Remove whitespace...
902
			case 'request' :
f569bae5   Benjamin Renard   Save download
903
			case 'download' :
2e7079bb   Benjamin Renard   First implementat...
904
			case 'statistic' :
10200969   Roipoussiere   Remove whitespace...
905
906
				$objectMgr = new RequestMgr($obj->nodeType);
				break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
907
			case 'alias' :
10200969   Roipoussiere   Remove whitespace...
908
909
				$objectMgr = new AliasMgr();
				break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
910
911
912
913
914
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> createObject($obj, $folder);
	}
16035364   Benjamin Renard   First commit
915

10200969   Roipoussiere   Remove whitespace...
916
/*
16035364   Benjamin Renard   First commit
917
918
*   $obj = { id:obj.id, name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
10200969   Roipoussiere   Remove whitespace...
919
	public  function modifyObject($obj)
9a63b7f6   Elena.Budnik   needsArgs to Simu...
920
	{
10200969   Roipoussiere   Remove whitespace...
921
922
923
924
925
		switch ($obj->nodeType)
		{
			case 'myDataParam' :
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($obj->nodeType);
9a63b7f6   Elena.Budnik   needsArgs to Simu...
926
				break;
10200969   Roipoussiere   Remove whitespace...
927
928
			case 'timeTable' :
				$objectMgr = new TimeTableMgr();
9a63b7f6   Elena.Budnik   needsArgs to Simu...
929
				break;
10200969   Roipoussiere   Remove whitespace...
930
931
932
933
			case 'catalog' :
				$objectMgr = new CatalogMgr();
				break;
			case 'condition' :
9a63b7f6   Elena.Budnik   needsArgs to Simu...
934
			case 'request' :
f569bae5   Benjamin Renard   Save download
935
			case 'download' :
2e7079bb   Benjamin Renard   First implementat...
936
			case 'statistic' :
10200969   Roipoussiere   Remove whitespace...
937
				$objectMgr = new RequestMgr($obj->nodeType);
9a63b7f6   Elena.Budnik   needsArgs to Simu...
938
939
940
941
942
				break;
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> modifyObject($obj);
10200969   Roipoussiere   Remove whitespace...
943
	}
16035364   Benjamin Renard   First commit
944
945
946
947
948
949
950
951
952
953
/*
 * {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...
954
			case 'sharedtimeTable' :
16035364   Benjamin Renard   First commit
955
956
				$objectMgr = new TimeTableMgr();
				break;
d18b535d   elena   catalog draft + c...
957
			case 'catalog' :
169f14d2   Benjamin Renard   Add shared object...
958
			case 'sharedcatalog' :
d18b535d   elena   catalog draft + c...
959
960
				$objectMgr = new CatalogMgr();
				break;
16035364   Benjamin Renard   First commit
961
962
			case 'condition' :
			case 'request' :
f569bae5   Benjamin Renard   Save download
963
			case 'download' :
2e7079bb   Benjamin Renard   First implementat...
964
			case 'statistic' :
16035364   Benjamin Renard   First commit
965
966
967
968
969
970
971
972
973
974
				$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...
975
*   Get running jobs
16035364   Benjamin Renard   First commit
976
*/
bae6f5da   Nathanael Jourdane   bugFix fileName f...
977
	public function getJobs($obj = null)
6acb8d2a   Elena.Budnik   checkRequest in R...
978
	{
812bc03d   Nathanael Jourdane   update job info o...
979
		$obj = (object) array();
10200969   Roipoussiere   Remove whitespace...
980
		return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO);
6acb8d2a   Elena.Budnik   checkRequest in R...
981
	}
16035364   Benjamin Renard   First commit
982
983
984
985
986
987
988


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

16035364   Benjamin Renard   First commit
994
		if (isset($obj->username) && isset($obj->password) && isset($obj->sessionID))
735c653b   Elena.Budnik   rank at observato...
995
		{
e5ab198f   Nathanael Jourdane   simple getStatus
996
			$dd = new WSUserMgr();
039d19ac   Benjamin Renard   Fix getParameter ...
997
			$dd->initWS($obj->username,$obj->password,$obj->sessionID, false, false);
735c653b   Elena.Budnik   rank at observato...
998
		}
a21497cc   Elena.Budnik   redmine #5645
999
		else {
16035364   Benjamin Renard   First commit
1000
			$dd = new UserMgr();
a21497cc   Elena.Budnik   redmine #5645
1001
1002
			$dd->setSpecialSettings();
		}
10200969   Roipoussiere   Remove whitespace...
1003
1004

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

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

98c5bd44   Benjamin Renard   Introduce anonymo...
1012
		if ($dd->user == WSConfigClass::getAnonymousUserName())
16035364   Benjamin Renard   First commit
1013
1014
1015
		{
			//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
1016
//			return array('success' => false, "message" => "AKKA-KERNEL-INT - WS support for IMPEx not implemented");
6acb8d2a   Elena.Budnik   checkRequest in R...
1017
		}
32bb889b   Elena.Budnik   #5532 to process ...
1018
		else {
0fea5567   Benjamin Renard   First step for re...
1019
			// check disk space
2c7f2cb6   Benjamin Renard   Remove old log fi...
1020
1021
1022
1023
1024
1025
			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...
1026
		}
10200969   Roipoussiere   Remove whitespace...
1027

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

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

6acb8d2a   Elena.Budnik   checkRequest in R...
1033
	private function executeRequest($obj, $function)
0fea5567   Benjamin Renard   First step for re...
1034
1035
	{

32bb889b   Elena.Budnik   #5532 to process ...
1036
1037
1038
		// 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...
1039
1040
				$function == FunctionTypeEnumClass::PARAMSGEN ||
				$function == FunctionTypeEnumClass::PARAMSINFOGEN )
32bb889b   Elena.Budnik   #5532 to process ...
1041
		{
7ac3e07e   Elena.Budnik   do not check user...
1042
1043
1044
			$res = $this->checkUser($obj);
			if (!$res['success']) return $res;
		}
8ba47f72   Benjamin Renard   rest actualisatio...
1045

16035364   Benjamin Renard   First commit
1046
		$requestManager = new RequestManagerClass();
32bb889b   Elena.Budnik   #5532 to process ...
1047
		try {
e57cb025   Benjamin Renard   Fix most of error...
1048
			$res = $requestManager->runIHMRequest($this->user, !empty($res['userHost']) ? $res['userHost'] : NULL, $function, $obj);
32bb889b   Elena.Budnik   #5532 to process ...
1049
		} catch (Exception $e) {
16035364   Benjamin Renard   First commit
1050
			return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage());
10200969   Roipoussiere   Remove whitespace...
1051
		}
16035364   Benjamin Renard   First commit
1052
1053
		return $res;
	}
10200969   Roipoussiere   Remove whitespace...
1054
1055
1056

/*
*    Main EXECUTE PROCEDURE
16035364   Benjamin Renard   First commit
1057
*/
735c653b   Elena.Budnik   rank at observato...
1058
1059
	public  function execute($node, $obj)
	{
fdf1413b   Elena.Budnik   TT download
1060
1061
1062
1063
		// 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
1064
			return $this->executeRequest($obj, FunctionTypeEnumClass::ACTION);
10200969   Roipoussiere   Remove whitespace...
1065
1066
		else
		{
6acb8d2a   Elena.Budnik   checkRequest in R...
1067
1068
			$res = RequestMgr::checkRequest($obj);
			if (!$res['success']) return $res;
10200969   Roipoussiere   Remove whitespace...
1069

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

16035364   Benjamin Renard   First commit
1074
/*
a0b3d64e   Benjamin Renard   Derived parameter...
1075
1076
 * Generate derived parameter compilation
 */
735c653b   Elena.Budnik   rank at observato...
1077
1078
	public function compilParam($obj)
	{
735c653b   Elena.Budnik   rank at observato...
1079
1080
		return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMSGEN);
	}
a0b3d64e   Benjamin Renard   Derived parameter...
1081

8ba47f72   Benjamin Renard   rest actualisatio...
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093

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




a0b3d64e   Benjamin Renard   Derived parameter...
1094
1095
1096
/*
 * Delete derived parameter compilation
 */
735c653b   Elena.Budnik   rank at observato...
1097
1098
	public function compilParamDelete($obj)
	{
a0b3d64e   Benjamin Renard   Derived parameter...
1099
		$res = $this->checkUser($obj);
10200969   Roipoussiere   Remove whitespace...
1100

a0b3d64e   Benjamin Renard   Derived parameter...
1101
1102
		if (!$res['success'])
			return $res;
10200969   Roipoussiere   Remove whitespace...
1103

a0b3d64e   Benjamin Renard   Derived parameter...
1104
1105
1106
1107
		IHMConfigClass::setUserName($this->user);
		$libParamPath = IHMConfigClass::getCompilationPath()."lib/".$obj->paramId.".so";
		if (file_exists($libParamPath))
			unlink($libParamPath);
735c653b   Elena.Budnik   rank at observato...
1108
1109
		return array("success" => true);
	}
10200969   Roipoussiere   Remove whitespace...
1110

a0b3d64e   Benjamin Renard   Derived parameter...
1111
/*
e6e5b259   Benjamin Renard   Add kill plot req...
1112
 * kill plot process
16035364   Benjamin Renard   First commit
1113
 */
10200969   Roipoussiere   Remove whitespace...
1114

735c653b   Elena.Budnik   rank at observato...
1115
	public function killPlotRequest()
10200969   Roipoussiere   Remove whitespace...
1116
	{
735c653b   Elena.Budnik   rank at observato...
1117
1118
		return $this->executeRequest((object) array('nodeType' => 'killplot'), FunctionTypeEnumClass::PARAMS);
	}
16035364   Benjamin Renard   First commit
1119
1120
1121
1122

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

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

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

10200969   Roipoussiere   Remove whitespace...
1133

16035364   Benjamin Renard   First commit
1134
1135
1136
/*
 * intersect time tables
 */
10200969   Roipoussiere   Remove whitespace...
1137
	public  function intersect($obj)
735c653b   Elena.Budnik   rank at observato...
1138
1139
	{
		if ($this->amdaStat->success)
2dab1b1b   Elena.Budnik   change input args...
1140
				$this->amdaStat->addTask($this->user, 'ttoper', null);
16035364   Benjamin Renard   First commit
1141

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

735c653b   Elena.Budnik   rank at observato...
1145
1146
		return  $result;
	}
10200969   Roipoussiere   Remove whitespace...
1147

0fea5567   Benjamin Renard   First step for re...
1148
	public function initObjectCache($isCatalog = false, $nparams = 1)
735c653b   Elena.Budnik   rank at observato...
1149
1150
1151
	{
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
		else              $cacheMgr = new CatalogCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1152

0fea5567   Benjamin Renard   First step for re...
1153
		return $cacheMgr->initObjectCache(array('nparams' => $nparams));
735c653b   Elena.Budnik   rank at observato...
1154
	}
10200969   Roipoussiere   Remove whitespace...
1155
1156


342b20ca   Benjamin Renard   Fix inheritence b...
1157
	public function initObjectCacheFromObject($id, $type)
735c653b   Elena.Budnik   rank at observato...
1158
1159
1160
	{
		if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1161

0fea5567   Benjamin Renard   First step for re...
1162
		return $cacheMgr->initFromObject($id, $type);
735c653b   Elena.Budnik   rank at observato...
1163
	}
10200969   Roipoussiere   Remove whitespace...
1164

0fea5567   Benjamin Renard   First step for re...
1165
	public function initObjectCacheFromCatalog($id, $type)
d547a559   Hacene SI HADJ MOHAND   rm_6903 ok
1166
1167
1168
1169
1170
1171
        {
                $cacheMgr = new TimeTableCacheMgr();

                return $cacheMgr->initFromCatalog($id, $type);
        }

19eca0a6   Hacene SI HADJ MOHAND   ok
1172
1173
1174
1175
        public function initObjectCacheFromTimeTable($id, $type, $nparams)
        {
                $cacheMgr = new CatalogCacheMgr();

ceac8bd0   Hacene SI HADJ MOHAND   us ok
1176
                return $cacheMgr->initFromTimeTable($id, $nparams, $type);
19eca0a6   Hacene SI HADJ MOHAND   ok
1177
1178
        }

0fea5567   Benjamin Renard   First step for re...
1179
	public function initObjectCacheFromTmpObject($folderId, $name, $isCatalog = false)
735c653b   Elena.Budnik   rank at observato...
1180
	{
10200969   Roipoussiere   Remove whitespace...
1181
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
735c653b   Elena.Budnik   rank at observato...
1182
1183
1184
1185
		else  $cacheMgr = new CatalogCacheMgr();

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

0fea5567   Benjamin Renard   First step for re...
1187
	public function initObjectCacheFromUploadedFile($name, $format, $isCatalog = false)
735c653b   Elena.Budnik   rank at observato...
1188
	{
901ba3f3   Elena.Budnik   upload catalog
1189
1190
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
		else  $cacheMgr = new CatalogCacheMgr();
735c653b   Elena.Budnik   rank at observato...
1191
1192
		return $cacheMgr->initFromUploadedFile($name, $format);
	}
10200969   Roipoussiere   Remove whitespace...
1193

342b20ca   Benjamin Renard   Fix inheritence b...
1194
	public function readCacheIntervals($o)
735c653b   Elena.Budnik   rank at observato...
1195
	{
e57cb025   Benjamin Renard   Fix most of error...
1196
		if (isset($o->typeTT) && ($o->typeTT == 'catalog' || $o->typeTT == 'sharedcatalog')) $cacheMgr = new CatalogCacheMgr();
735c653b   Elena.Budnik   rank at observato...
1197
		else $cacheMgr = new TimeTableCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1198

e57cb025   Benjamin Renard   Fix most of error...
1199
		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...
1200
	}
10200969   Roipoussiere   Remove whitespace...
1201

735c653b   Elena.Budnik   rank at observato...
1202
1203
	public function readIntervalsForChart($o)
	{
1a0151a5   Benjamin Renard   wip
1204
		$objMgr = new CatalogCacheMgr(TRUE);
b0720b91   Benjamin Renard   Finalize catalog ...
1205
		$objMgr->initFromObject($o->id, $o->type);
1a0151a5   Benjamin Renard   wip
1206
		return $objMgr->getIntervalsForChart();
735c653b   Elena.Budnik   rank at observato...
1207
	}
10200969   Roipoussiere   Remove whitespace...
1208

735c653b   Elena.Budnik   rank at observato...
1209
1210
1211
	public function saveTTCacheIntervalsInTT($o)
	{
		$cacheMgr = new TimeTableCacheMgr();
0fea5567   Benjamin Renard   First step for re...
1212
		return $cacheMgr->saveInObject($o->ttId,$o->action,$o->cacheToken);
735c653b   Elena.Budnik   rank at observato...
1213
	}
10200969   Roipoussiere   Remove whitespace...
1214

342b20ca   Benjamin Renard   Fix inheritence b...
1215
	public function addCacheInterval($o)
735c653b   Elena.Budnik   rank at observato...
1216
1217
1218
1219
1220
1221
	{
		if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();

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

735c653b   Elena.Budnik   rank at observato...
1223
1224
1225
1226
1227
1228
1229
	public function removeTTCacheIntervalFromId($id, $isCatalog = false)
	{
		if ($isCatalog) $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();

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

342b20ca   Benjamin Renard   Fix inheritence b...
1231
	public function modifyCacheInterval($o)
735c653b   Elena.Budnik   rank at observato...
1232
	{
10200969   Roipoussiere   Remove whitespace...
1233
		if ($o->isCatalog)
735c653b   Elena.Budnik   rank at observato...
1234
		{
f9c8b272   elena   edit catalog
1235
			$cacheMgr = new CatalogCacheMgr();
f9c8b272   elena   edit catalog
1236
		}
735c653b   Elena.Budnik   rank at observato...
1237
		else $cacheMgr = new TimeTableCacheMgr();
10200969   Roipoussiere   Remove whitespace...
1238

342b20ca   Benjamin Renard   Fix inheritence b...
1239
		return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->data);
735c653b   Elena.Budnik   rank at observato...
1240
	}
10200969   Roipoussiere   Remove whitespace...
1241

f3e15e49   Erdogan Furkan   #10700 - Done
1242
	public function operationTTCacheIntervals($extendTime, $shiftTime, $isCat)
735c653b   Elena.Budnik   rank at observato...
1243
	{
f3e15e49   Erdogan Furkan   #10700 - Done
1244
1245
1246
1247
1248
1249
		if($isCat){
			$cacheMgr = new CatalogCacheMgr();
		}
		else{
			$cacheMgr = new TimeTableCacheMgr();
		}
735c653b   Elena.Budnik   rank at observato...
1250
1251
		return $cacheMgr->operationIntervals($extendTime, $shiftTime);
	}
10200969   Roipoussiere   Remove whitespace...
1252

735c653b   Elena.Budnik   rank at observato...
1253
1254
1255
1256
1257
	public function mergeTTCacheIntervals()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->mergeIntervals();
	}
10200969   Roipoussiere   Remove whitespace...
1258

0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
1259
	public function getTTCacheStatistics($obj)
735c653b   Elena.Budnik   rank at observato...
1260
	{
0fea5567   Benjamin Renard   First step for re...
1261
                if($obj->name == "timeTableUi"){
0318dbe6   Hacene SI HADJ MOHAND   rm_6998 ok
1262
1263
1264
1265
1266
1267
				$cacheMgr = new TimeTableCacheMgr();
                 }elseif($obj->name == "catalogUI"){
                      $cacheMgr = new CatalogCacheMgr();
                 }else{
                      return array('success' => false, 'message' => 'unkown type: '.$obj->name);
               }
735c653b   Elena.Budnik   rank at observato...
1268
1269
		return $cacheMgr->getStatistics();
	}
10200969   Roipoussiere   Remove whitespace...
1270

735c653b   Elena.Budnik   rank at observato...
1271
1272
1273
1274
1275
	public function getTTCacheStatus()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->getStatus();
	}
aa94fd24   elena   Merge with last svn
1276

16035364   Benjamin Renard   First commit
1277
1278
/*
 * Send a feedback
10200969   Roipoussiere   Remove whitespace...
1279
 *
16035364   Benjamin Renard   First commit
1280
 */
735c653b   Elena.Budnik   rank at observato...
1281
1282
1283
1284
1285
	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...
1286

16035364   Benjamin Renard   First commit
1287
1288
/*
 * Save state
10200969   Roipoussiere   Remove whitespace...
1289
 *
16035364   Benjamin Renard   First commit
1290
 */
735c653b   Elena.Budnik   rank at observato...
1291
1292
1293
1294
1295
	public function saveState($datas)
	{
		$myStateMgr = new StateMgr();
		return $myStateMgr->saveState($datas);
	}
10200969   Roipoussiere   Remove whitespace...
1296

16035364   Benjamin Renard   First commit
1297
1298
/*
 * Load state
10200969   Roipoussiere   Remove whitespace...
1299
1300
 *
 */
735c653b   Elena.Budnik   rank at observato...
1301
	public function loadState($o)
10200969   Roipoussiere   Remove whitespace...
1302
	{
735c653b   Elena.Budnik   rank at observato...
1303
1304
1305
		$myStateMgr = new StateMgr();
		return $myStateMgr->loadState();
	}
10200969   Roipoussiere   Remove whitespace...
1306
1307

/*
16035364   Benjamin Renard   First commit
1308
1309
 * HST Images
 */
735c653b   Elena.Budnik   rank at observato...
1310
1311
1312
	public function getHstImagesUrl($o)
	{
		if ($this->amdaStat->success)
2dab1b1b   Elena.Budnik   change input args...
1313
			$this->amdaStat->addTask($this->user, 'images', null);
10200969   Roipoussiere   Remove whitespace...
1314

735c653b   Elena.Budnik   rank at observato...
1315
1316
1317
1318
1319
1320
		$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...
1321

735c653b   Elena.Budnik   rank at observato...
1322
1323
	public function getAPISImagesUrl($o)
	{
10200969   Roipoussiere   Remove whitespace...
1324
		if ($this->amdaStat->success)
2dab1b1b   Elena.Budnik   change input args...
1325
			$this->amdaStat->addTask($this->user, 'images', null);
10200969   Roipoussiere   Remove whitespace...
1326

735c653b   Elena.Budnik   rank at observato...
1327
1328
1329
1330
		$apisMgr = new APISMgr();
		$res = $apisMgr->get($o->target, $o->startTime, $o->stopTime, $o->datasets);

		return $res;
10200969   Roipoussiere   Remove whitespace...
1331
	}
16035364   Benjamin Renard   First commit
1332
1333
1334
/*
 * Filters
 */
e57cb025   Benjamin Renard   Fix most of error...
1335
	public function loadFilterList()
735c653b   Elena.Budnik   rank at observato...
1336
	{
10200969   Roipoussiere   Remove whitespace...
1337
		$filtersMgr = new FiltersMgr();
735c653b   Elena.Budnik   rank at observato...
1338
1339
1340
		$res = $filtersMgr->loadList();
		return $res;
	}
16035364   Benjamin Renard   First commit
1341

735c653b   Elena.Budnik   rank at observato...
1342
1343
1344
1345
1346
1347
1348
1349
1350
	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...
1351

735c653b   Elena.Budnik   rank at observato...
1352
1353
	public function saveFilter($o)
	{
10200969   Roipoussiere   Remove whitespace...
1354
		$filtersMgr = new FiltersMgr();
735c653b   Elena.Budnik   rank at observato...
1355
1356
		return $filtersMgr->save($o);
	}
10200969   Roipoussiere   Remove whitespace...
1357

735c653b   Elena.Budnik   rank at observato...
1358
1359
	public function createFilter($o)
	{
10200969   Roipoussiere   Remove whitespace...
1360
		$filtersMgr = new FiltersMgr();
735c653b   Elena.Budnik   rank at observato...
1361
1362
		return $filtersMgr->create($o);
	}
10200969   Roipoussiere   Remove whitespace...
1363

735c653b   Elena.Budnik   rank at observato...
1364
1365
1366
1367
1368
1369
	public function destroyFilter($o)
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->delete($o);
		return;
	}
10200969   Roipoussiere   Remove whitespace...
1370

735c653b   Elena.Budnik   rank at observato...
1371
1372
1373
1374
1375
1376
1377
	public function getCrtFilterId()
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->getCrtId();
		return $res;
	}

fdf1413b   Elena.Budnik   TT download
1378
1379
	public function getCrtFilterResult()
	{
10200969   Roipoussiere   Remove whitespace...
1380
		$filtersMgr = new FiltersMgr();
fdf1413b   Elena.Budnik   TT download
1381
1382
		return $filtersMgr->getCrtResult();
	}
10200969   Roipoussiere   Remove whitespace...
1383

fdf1413b   Elena.Budnik   TT download
1384
1385
	public function setCrtFilterId($o)
	{
10200969   Roipoussiere   Remove whitespace...
1386
		$filtersMgr = new FiltersMgr();
fdf1413b   Elena.Budnik   TT download
1387
1388
		return $filtersMgr->setCrtId($o->id);
	}
10200969   Roipoussiere   Remove whitespace...
1389

fdf1413b   Elena.Budnik   TT download
1390
1391
1392
1393
1394
1395
	public function resetFilter()
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->reset();
		return $res;
	}
10200969   Roipoussiere   Remove whitespace...
1396

16035364   Benjamin Renard   First commit
1397
1398
	public function logout($isGuest)
	{
10200969   Roipoussiere   Remove whitespace...
1399
		if ($isGuest)
735c653b   Elena.Budnik   rank at observato...
1400
		{
fdf1413b   Elena.Budnik   TT download
1401
1402
1403
			$guestMgr = new Guest($this->user);
			$guestMgr->deleteGuest();
		}
10200969   Roipoussiere   Remove whitespace...
1404
		else
735c653b   Elena.Budnik   rank at observato...
1405
		{
fdf1413b   Elena.Budnik   TT download
1406
			$this->cleanUserWS();
10200969   Roipoussiere   Remove whitespace...
1407
		}
16035364   Benjamin Renard   First commit
1408
		return;
10200969   Roipoussiere   Remove whitespace...
1409
	}
16035364   Benjamin Renard   First commit
1410

fdf1413b   Elena.Budnik   TT download
1411
1412
	public function getInfo($obj)
	{
10200969   Roipoussiere   Remove whitespace...
1413
		if (file_exists(HELPPATH.$obj->name))
fdf1413b   Elena.Budnik   TT download
1414
		{
10200969   Roipoussiere   Remove whitespace...
1415
			$content = file_get_contents(HELPPATH.$obj->name);
fdf1413b   Elena.Budnik   TT download
1416
1417
			return  array('success' => true, 'result' => $content);
		}
10200969   Roipoussiere   Remove whitespace...
1418
1419
1420
		return array('success' => false);
	}

fdf1413b   Elena.Budnik   TT download
1421
1422
1423
1424
1425
	public function getUserInfo()
	{
		$dd = new UserMgr();
		return $dd->getUserInfo();
	}
16035364   Benjamin Renard   First commit
1426

fdf1413b   Elena.Budnik   TT download
1427
1428
1429
1430
1431
1432
	// $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...
1433
1434

		return  $res;
fdf1413b   Elena.Budnik   TT download
1435
	}
10200969   Roipoussiere   Remove whitespace...
1436
1437

	//$obj = array of IDs
fdf1413b   Elena.Budnik   TT download
1438
1439
1440
	public function addRun($obj)
	{
		$myBestRunsMgr = new BestRunsMgr();
10200969   Roipoussiere   Remove whitespace...
1441

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

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

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

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

fdf1413b   Elena.Budnik   TT download
1452
1453
1454
1455
	//AKKA - New action to clean user WS
	public function cleanUserWS()
	{
		$this->rrmdir(USERDIR.'DOWNLOAD.TEMP');
278185de   Benjamin Renard   Upload catalog fr...
1456
		$this->rrmdir(USERDIR.'TEMP');
bf74fc2d   Elena.Budnik   IMPEX
1457
		IHMConfigClass::setUserName($this->user);
10200969   Roipoussiere   Remove whitespace...
1458
1459

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

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

fdf1413b   Elena.Budnik   TT download
1467
1468
1469
	public function rrmdir($dir){
		if (is_dir($dir)) {
			$objects = scandir($dir);
10200969   Roipoussiere   Remove whitespace...
1470
1471
			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
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
					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...
1485
		if (file_exists(USERDIR.$name))
fdf1413b   Elena.Budnik   TT download
1486
1487
1488
					unlink(USERDIR.$name);
		return array('success' => true);
	}
10200969   Roipoussiere   Remove whitespace...
1489

46c5751e   Benjamin Renard   Cleanup
1490
	public function interactivePlot($obj)
fdf1413b   Elena.Budnik   TT download
1491
	{
fdf1413b   Elena.Budnik   TT download
1492
1493
		$inputobj = (Object)array(
			'action' => $obj,
fdf1413b   Elena.Budnik   TT download
1494
1495
1496
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION);
	}
10200969   Roipoussiere   Remove whitespace...
1497

735c653b   Elena.Budnik   rank at observato...
1498
1499
	public function getParamPlotInit($obj)
	{
bf74fc2d   Elena.Budnik   IMPEX
1500
1501
1502
1503
1504
		// IMPEX param
		if (preg_match("#^spase___IMPEX_#",$obj->paramId))
			$type = 'impex_plot_init';
		else
		   $type = 'plot_init';
10200969   Roipoussiere   Remove whitespace...
1505

735c653b   Elena.Budnik   rank at observato...
1506
1507
		$inputobj = (Object)array(
				'paramId' => $obj->paramId,
bf74fc2d   Elena.Budnik   IMPEX
1508
				'type' => $type
735c653b   Elena.Budnik   rank at observato...
1509
1510
1511
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
	}
10200969   Roipoussiere   Remove whitespace...
1512

735c653b   Elena.Budnik   rank at observato...
1513
1514
	public function getParamInfo($obj)
	{
bf74fc2d   Elena.Budnik   IMPEX
1515
1516
1517
1518
1519
		// IMPEX param
		if (preg_match("#^spase___IMPEX_#",$obj->paramId))
			$type = 'impex_param_info';
		else
		   $type = 'param_info';
10200969   Roipoussiere   Remove whitespace...
1520

735c653b   Elena.Budnik   rank at observato...
1521
1522
		$inputobj = (Object)array(
				'paramId' => $obj->paramId,
2fa56f95   Benjamin Renard   Predefined templa...
1523
				'predefinedArgs' => !empty($obj->predefinedArgs),
bf74fc2d   Elena.Budnik   IMPEX
1524
				'type' => $type
735c653b   Elena.Budnik   rank at observato...
1525
1526
1527
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
	}
bf776dc8   Benjamin Renard   working
1528
	public function getDerivedParamInfo($obj)
0fea5567   Benjamin Renard   First step for re...
1529
	{
bf776dc8   Benjamin Renard   working
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
                 $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);
		  	}
0fea5567   Benjamin Renard   First step for re...
1542

bf776dc8   Benjamin Renard   working
1543
		}
0fea5567   Benjamin Renard   First step for re...
1544
		return array('success'=>false, 'message'=>'unkown parameter (derived parameter arguments are not handled)');
bf776dc8   Benjamin Renard   working
1545
	}
0fea5567   Benjamin Renard   First step for re...
1546

22d8d756   Hacene SI HADJ MOHAND   resolu
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
       public function getMyDataParamInfo($obj)
        {
                 $dom = new DomDocument("1.0");
                 $xmlName=USERWSDIR.$this->xmlFiles['derivedParam'];
                 @$dom->load($xmlName);
                 $params=$dom->getElementsByTagName("mydata");
                 foreach($params as $param)
                 {
                        if($param->hasAttribute("name") && ("wsd_" . ($param->getAttribute("name")))==$obj->paramId)
                        {
                         $dim_1=$param->getAttribute("size");
                         $dim_2=1;
                         return $this->createDerivedParamInfo($dim_1,$dim_2,$obj->paramId);
                        }

                }
                return array('success'=>false, 'message'=>'unkown parameter (derived parameter arguments are not handled)');
        }


bf776dc8   Benjamin Renard   working
1567
1568
1569
1570
1571
1572
	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");
0fea5567   Benjamin Renard   First step for re...
1573
		}elseif(($dim_1==1 && $dim_2>1 && $dim_2<=3)||($dim_2==1 && $dim_1>1 && $dim_1<=3) )
bf776dc8   Benjamin Renard   working
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
		/* 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
			    );
0fea5567   Benjamin Renard   First step for re...
1601

10200969   Roipoussiere   Remove whitespace...
1602

bf776dc8   Benjamin Renard   working
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
			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();
0fea5567   Benjamin Renard   First step for re...
1617

bf776dc8   Benjamin Renard   working
1618
1619
1620
1621
1622
1623
1624
			for($i=0;$i<$sizes[$j];$i++)
				{
				$c=array('min'=>'L' . $i,'max'=>'L' . ($i+1));
				array_push($compts,$c);
				}

			$tab=array(
0fea5567   Benjamin Renard   First step for re...
1625
				'relatedDim'=>'dim' . ($j+1),
bf776dc8   Benjamin Renard   working
1626
1627
1628
1629
1630
1631
1632
1633
1634
				'name'=>'component' . ($j+1),
				'units'=>"",
				'variable'=>"",
				'channels'=>$compts,
				'minmax'=>""
				);

			array_push($tables,$tab);
			}
0fea5567   Benjamin Renard   First step for re...
1635

bf776dc8   Benjamin Renard   working
1636
1637
1638
1639
1640
1641
                  $data=array(
				'dimensions'=>$dims,
				'tables'=>$tables
			     );
		return array('success'=>true,'data'=>$data);
                }
0fea5567   Benjamin Renard   First step for re...
1642

bf776dc8   Benjamin Renard   working
1643
	}
735c653b   Elena.Budnik   rank at observato...
1644
1645
1646
1647
1648
1649
	public function getSharedObjectFolders($obj)
	{
		$mgr = new SharedObjectsMgr();
		$folders = $mgr->getFolders($obj->type);
		return array('success' => true, 'folders' => $folders);
	}
10200969   Roipoussiere   Remove whitespace...
1650

735c653b   Elena.Budnik   rank at observato...
1651
1652
1653
	public function shareObjects($obj)
	{
		$mgr = new SharedObjectsMgr();
10200969   Roipoussiere   Remove whitespace...
1654
		switch ($obj->type)
735c653b   Elena.Budnik   rank at observato...
1655
1656
1657
1658
1659
		{
			case 'timeTable' :
			case 'catalog' :
				$src_object_path = USERTTDIR.$obj->object->id.".xml";
				break;
10200969   Roipoussiere   Remove whitespace...
1660

735c653b   Elena.Budnik   rank at observato...
1661
1662
1663
			default:
				return array('success' => false, 'message' => 'Unknown object type');
		}
10200969   Roipoussiere   Remove whitespace...
1664

735c653b   Elena.Budnik   rank at observato...
1665
1666
1667
		$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...
1668

735c653b   Elena.Budnik   rank at observato...
1669
1670
1671
		$mgr->updateTree();
		return $result;
	}
10200969   Roipoussiere   Remove whitespace...
1672

735c653b   Elena.Budnik   rank at observato...
1673
1674
1675
1676
1677
1678
	public function isSharedObjectNameAlreadyUsed($obj)
	{
		$mgr = new SharedObjectsMgr();
		$alreadyUsed = $mgr->isNameAlreadyUsed($obj->type, $obj->name);
		return array('success' => true, 'alreadyUsed' => $alreadyUsed);
	}
10200969   Roipoussiere   Remove whitespace...
1679

0bda97f3   Benjamin Renard   Fix SAMP export f...
1680
1681
	public function getRequestByProcessId($obj)
	{
0bda97f3   Benjamin Renard   Fix SAMP export f...
1682
1683
		return $this->executeRequest($obj->processId, FunctionTypeEnumClass::PROCESSGETREQUEST);
	}
2fa56f95   Benjamin Renard   Predefined templa...
1684
1685
1686
1687
1688
1689
1690
1691
1692

	public function parseTemplatedParam($paramTemplateId)
	{
		$args = (Object)array(
			'paramId' => $paramTemplateId,
			'type' => 'param_parse_template'
		);
		return $this->executeRequest($args, FunctionTypeEnumClass::PARAMINFO);
	}
3d95b0a6   furkan   Adding the Delete...
1693
1694
1695
1696
1697
1698

	public function deleteColumn($id){
		$cacheMgr = new CatalogCacheMgr();

		return $cacheMgr->deleteColumn($id);
	}
42c4ccd3   Erdogan Furkan   #9660 - Done
1699

ce347c54   Erdogan Furkan   Done.
1700
	public function addColumn($id, $name, $type, $size, $description, $status){
42c4ccd3   Erdogan Furkan   #9660 - Done
1701
		$cacheMgr = new CatalogCacheMgr();
ce347c54   Erdogan Furkan   Done.
1702
		return $cacheMgr->addColumn($id,$name, $type,$size,$description, $status);
42c4ccd3   Erdogan Furkan   #9660 - Done
1703
1704
1705
1706
1707
1708
1709
	}

	public function getCatColumnInfo($id){
		$cacheMgr = new CatalogCacheMgr();
		return $cacheMgr->getCatColumnInfo($id);
	}

ce347c54   Erdogan Furkan   Done.
1710
	public function editColumn($id, $name, $type, $size,$description, $status){
42c4ccd3   Erdogan Furkan   #9660 - Done
1711
		$cacheMgr = new CatalogCacheMgr();
ce347c54   Erdogan Furkan   Done.
1712
		return $cacheMgr->editColumn($id,$name, $type,$size,$description, $status);
42c4ccd3   Erdogan Furkan   #9660 - Done
1713
	}
851cf2f0   Erdogan Furkan   For now
1714
1715
1716

	public function getNodeValues($data,&$transformed){
		$iconCls = "task-folder";
851cf2f0   Erdogan Furkan   For now
1717
		foreach ($data as $parameter => $value) {
4f728fd9   Erdogan Furkan   For now 2
1718
			if(is_array($value) && !$value['modified']){
851cf2f0   Erdogan Furkan   For now
1719
1720
1721
1722
1723
1724
1725
				$child = [
					"parameter" => $parameter,
					"value" => "",
					"iconCls" => $iconCls,
					"expanded" => false,
					"children" => []
				];
4f728fd9   Erdogan Furkan   For now 2
1726

851cf2f0   Erdogan Furkan   For now
1727
1728
1729
				$this->getNodeValues($value,$child['children']);
				$transformed[] = $child;
			}
4f728fd9   Erdogan Furkan   For now 2
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
			else if (is_array($value) && $value['modified']){
				$child =[
					"parameter" => $parameter,
					"value" => $value["value"],
					"iconCls" => "task",
					"leaf" => true,
					"modified" => $value["modified"],
					"default" => $value["defaultValue"]
				];
				$transformed[] = $child;
			}
851cf2f0   Erdogan Furkan   For now
1741
1742
1743
1744
1745
			else{
				$child =[
					"parameter" => $parameter,
					"value" => $value,
					"iconCls" => "task",
4f728fd9   Erdogan Furkan   For now 2
1746
1747
1748
					"leaf" => true,
					"modified" => false,
					"default" =>$value
851cf2f0   Erdogan Furkan   For now
1749
				];
851cf2f0   Erdogan Furkan   For now
1750
1751
1752
1753
				$transformed[] = $child;
			}
		}
	}
4f728fd9   Erdogan Furkan   For now 2
1754
1755
	public function getDefaultValueConfigs(){
		if (file_exists(DATAPATH.'defaultValuesConfig.json'))
b1dc2eb3   Erdogan Furkan   More modifications
1756
			return array('success' => true , 'configs' => json_decode(file_get_contents(DATAPATH.'defaultValuesConfig.json'), true));
4f728fd9   Erdogan Furkan   For now 2
1757
		else
b1dc2eb3   Erdogan Furkan   More modifications
1758
			return array('success' => false , 'configs' => array(), 'message'=>'Error : No default value configs file.');
4f728fd9   Erdogan Furkan   For now 2
1759
1760
1761
	}

	public function getDefaultValueLinks(){
b1dc2eb3   Erdogan Furkan   More modifications
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
		if (!file_exists(DATAPATH.'defaultValuesLinks.json'))
			return array('success' => false , 'links' => array(), 'message'=>'Error : No default value links file.');

		$json_links = json_decode(file_get_contents(DATAPATH.'defaultValuesLinks.json'), true);
		if (!file_exists(DATAPATH.'defaultValuesConfig.json'))
			return  array('success' => false , 'links' => array(), 'message'=>'Error : No default value configs file.');
			
		$json_configs= json_decode(file_get_contents(DATAPATH.'defaultValuesConfig.json'), true);
		foreach ($json_links as $parameter => &$links){
			if(!empty($links['store']))
				$links['store']= $json_configs[$links['store']];
		}
		return array('success' => true , 'links' => $json_links);
		
4f728fd9   Erdogan Furkan   For now 2
1776
	}
851cf2f0   Erdogan Furkan   For now
1777

4f728fd9   Erdogan Furkan   For now 2
1778
	public function getDefaultValueTree($isTree=TRUE){
851cf2f0   Erdogan Furkan   For now
1779
1780
		$childrenToReturn = array();
		$children = [];
b1dc2eb3   Erdogan Furkan   More modifications
1781
		if (!file_exists(DATAPATH.'defaultValues.json')) 
a2b8ec19   Benjamin Renard   Fix userDefaults....
1782
			return array('success' => false , 'defaultValues' => array(), 'message'=>'Defaultvalues file not found.');
b1dc2eb3   Erdogan Furkan   More modifications
1783
1784
1785
1786
		$json_o = json_decode(file_get_contents(DATAPATH.'defaultValues.json'), true);
		if (empty($json_o)) 
			return array('success' => false , 'defaultValues' => array(), 'message'=>'Error : defaultValues file empty.');

a2b8ec19   Benjamin Renard   Fix userDefaults....
1787
1788
1789
1790
1791
1792
		$json_user = array();
		if (file_exists(USERDIR.'userDefaults.json')) 
			$json_user = json_decode(file_get_contents(USERDIR.'userDefaults.json'), true);
		if (empty($json_user)) {
			$json_user = array();
		}
b1dc2eb3   Erdogan Furkan   More modifications
1793
1794
1795
1796
1797
1798

		foreach($json_user as $key => $value){
			$keys = explode(".", $key);
			$results = &$json_o; // Use a reference to update the original array
			foreach($keys as $parameter){
				$results = &$results[$parameter];
851cf2f0   Erdogan Furkan   For now
1799
			}
b1dc2eb3   Erdogan Furkan   More modifications
1800
1801
1802
1803
			if($isTree)
				$results = array("value" => $value, "modified" => true, "defaultValue" => $results);
			else
				$results = $value;
851cf2f0   Erdogan Furkan   For now
1804
		}
b1dc2eb3   Erdogan Furkan   More modifications
1805
1806
1807
1808
		
		if($isTree){
			$this->getNodeValues($json_o,$children);
			return [ "text" => ".", "children" => $children ];
851cf2f0   Erdogan Furkan   For now
1809
		}
b1dc2eb3   Erdogan Furkan   More modifications
1810
1811

		return array('success' => true , 'defaultValues' => $json_o);
851cf2f0   Erdogan Furkan   For now
1812
	}
239d9f8f   Erdogan Furkan   First Working ver...
1813
1814
1815

	public function setUserDefaultValues($data){
		$json_user = json_encode($data, true);
b1dc2eb3   Erdogan Furkan   More modifications
1816
1817
1818
		if (empty($json_user)) 
			return array('success' => false , 'message'=>'Error : No modifications to write.');

239d9f8f   Erdogan Furkan   First Working ver...
1819
1820
1821
1822
		file_put_contents(USERDIR.'userDefaults.json',$json_user);

		return array('success' => true);
	}
e995f4ad   Erdogan Furkan   Added codeTextAre...
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843

	public function getParametersList(){
		$xml = simplexml_load_string(file_get_contents(LocalData.'LocalParams.xml'));
		$parameters = [];
		if (empty($xml)) 
			return array();
		foreach($xml->xpath('//parameter') as $parameter) {
			$parameters[] = (string) $parameter->attributes('xml', true)['id'];
		}

		$xml_derived = simplexml_load_string(file_get_contents(USERDIR.'/WS/WsParams.xml'));
		if(empty($xml_derived))
			return $parameters;
		foreach($xml_derived->xpath('//param') as $param) {
			$parameters[] = "ws_".(string) $param->attributes()->name;
		}
		foreach($xml_derived->xpath('//mydata') as $param) {
			$parameters[] = "wsd_".(string) $param->attributes()->name;
		}
		return $parameters;
	}
16035364   Benjamin Renard   First commit
1844
1845
}
?>