Blame view

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


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

	private $user, $amdaStat;

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

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

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

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

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

		return $childrenToReturn;

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

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

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

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

		// to correct 'restricted' parameters
		if (strpos($node, restricted) !== false)
735c653b   Elena.Budnik   rank at observato...
68
69
70
		{
			$node = str_replace(restricted,"",$node);
		}
16035364   Benjamin Renard   First commit
71

735c653b   Elena.Budnik   rank at observato...
72
73
74
		$nodeType = $obj->nodeType;
		$remoteBase = false;
		$isRemoteDataSet = false;
16035364   Benjamin Renard   First commit
75

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

735c653b   Elena.Budnik   rank at observato...
82
		if ($obj->baseId) $remoteBase = true;
16035364   Benjamin Renard   First commit
83

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

10200969   Roipoussiere   Remove whitespace...
86
87
		if ($node == 'root' && !$remoteBase)
		{
735c653b   Elena.Budnik   rank at observato...
88
			$json_o = json_decode(file_get_contents(DATAPATH.$nodeType.'.json'));
10200969   Roipoussiere   Remove whitespace...
89
90
91
			$childrenToReturn = $json_o->nodes;
		}
		else
735c653b   Elena.Budnik   rank at observato...
92
93
94
		{
			$Dom = new DomDocument("1.0");

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

10200969   Roipoussiere   Remove whitespace...
114
115
			if ($remoteBase)
			{
735c653b   Elena.Budnik   rank at observato...
116
				$nodeType = 'remoteParam';
10200969   Roipoussiere   Remove whitespace...
117
118
			}

735c653b   Elena.Budnik   rank at observato...
119
			$Dom->load($xmlName);
10200969   Roipoussiere   Remove whitespace...
120
121

			if ($node == "myRemoteSimuData-treeRootNode")
735c653b   Elena.Budnik   rank at observato...
122
				$node = "myRemoteData-treeRootNode";
10200969   Roipoussiere   Remove whitespace...
123

735c653b   Elena.Budnik   rank at observato...
124
125
			$nodeToOpen = $Dom->getElementById($node);
			$children = $nodeToOpen->childNodes;
16035364   Benjamin Renard   First commit
126

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

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

10200969   Roipoussiere   Remove whitespace...
141
142
					//TODO MAKE PROPERLY  as function of nodetype !!!!
					$info = '';
735c653b