class.tx_nG6_eid.php 47.8 KB
Newer Older
1
2


Penom Nom's avatar
Penom Nom committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2009 PF bioinformatique de Toulouse <>
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

27
28
29
30
31
32
33
34
//require_once(PATH_t3lib.'class.t3lib_befunc.php');
//require_once(PATH_t3lib.'stddb/tables.php');
//require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('cms','ext_tables.php'));
//require_once(PATH_t3lib.'class.t3lib_db.php');
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/lib/class.tx_nG6_db.php');
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/lib/class.tx_nG6_utils.php');
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/lib/class.tx_nG6_process.php');
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/libs/Smarty.class.php');
Penom Nom's avatar
Penom Nom committed
35
36
37
38
39
40
41
42
43
44
45
46
47

/**
 * Class 'tx_nG6_eid' for the 'nG6' extension.
 * This class is in charge of all communication between the client and the server using AJAX
 *
 * @author	PF bioinformatique de Toulouse <>
 */
class tx_nG6_eid {

    /**
     * The main function of the tx_nG6_eid, this function is the one called when using ajax
     */
    function main() {
48
    	
Penom Nom's avatar
Penom Nom committed
49
    	// Connect to the databse
50
51
52
    	//\TYPO3\CMS\Frontend\Utility\EidUtility::connectDB();
    	$type = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('type'));
    	$user_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_id'));
53
    	$GLOBALS['TSFE'] = $tsfe = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', $GLOBALS['TYPO3_CONF_VARS'], \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'), '');
54
55
56
57
58
59
60
61
62
    	/** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe */
    	$tsfe->connectToDB();
    	$tsfe->initFEuser();
    	\TYPO3\CMS\Frontend\Utility\EidUtility::initTCA();
    	$tsfe->determineId();
    	$tsfe->initTemplate();
    	$tsfe->getConfigArray();
    	$tsfe->settingLanguage();
    	
Gerald Salin's avatar
Gerald Salin committed
63
    	//error_log("tx_nG6_eid ".$type." \n ", 3, "/work/tmp/mes-erreurs.log");
Penom Nom's avatar
Penom Nom committed
64
65
    	// If the type of data requested is project
    	if ($type == 'project') {
66
    		$project_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('object_id'));
Penom Nom's avatar
Penom Nom committed
67
	    	// Select all runs linked to the project
Penom Nom's avatar
Penom Nom committed
68
	    	$project_runs = tx_nG6_db::get_user_project_runs($user_id, $project_id, 'tx_nG6_run.date DESC');
Penom Nom's avatar
Penom Nom committed
69
70
71
	    	// for each run
	    	$html_tree = '';
			foreach($project_runs as $run_id => $run_values) {
72
				$html_tree .= '<li class="jstree-closed" name=\''.str_replace(array('###SPAN_NAME###', '###SPAN_DATE###'), array($run_values['name'], strftime('%d-%m-%y',$run_values['date'])), trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('run_short_description'))).'\' id=\''.$run_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###', '###SPAN_DATE###', '###SPAN_NB_SEQ###', '###SPAN_SPECIES###'), array($run_values['name'], strftime('%d-%m-%y',$run_values['date']), $run_values['nb_sequences'], $run_values['species']), trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('run_description'))).'</a></li>';
Penom Nom's avatar
Penom Nom committed
73
74
			}
	    	// Then all project analysis
Penom Nom's avatar
Penom Nom committed
75
	    	$project_analysis = tx_nG6_db::get_user_project_analysis($user_id, $project_id, 'tx_nG6_analyze.name');
Penom Nom's avatar
Penom Nom committed
76
			foreach($project_analysis as $analyse_id => $analyse_values) {  
77
				$html_tree .= '<li name=\''.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('analyse_description'))).'\' id=\''.$analyse_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('analyse_description'))).'</a></li>';
Penom Nom's avatar
Penom Nom committed
78
79
80
81
82
			}
			// Return the html_tree
	    	print $html_tree;
	    	
	    // If the type of data requested is run
83
84
    	}
        elseif ($type == 'run'){
85
			$run_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('object_id'));
Penom Nom's avatar
Penom Nom committed
86
			// Select all analysis linked to the run and the run information
Penom Nom's avatar
Penom Nom committed
87
			$run_analysis = tx_nG6_db::get_user_run_analysis($user_id, $run_id, 'tx_nG6_analyze.name');
Penom Nom's avatar
Penom Nom committed
88
89
90
			$run_info = tx_nG6_db::select_run($run_id);
	    	// for each analysis
	    	$html_tree = '';
91
			$html_tree .= '<li name=\'run_'.$run_id.'_'.trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP("raw_data_description")).'\'  id=\'data_'.$run_id.'\'> <a href=\'#\'>'.trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP("raw_data_description")).'</a></li>';
Penom Nom's avatar
Penom Nom committed
92
			foreach($run_analysis as $analyse_id => $analyse_values) {   
93
				$html_tree .= '<li name=\'run_'.$run_id.'_'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('analyse_description'))).'\' id=\''.$analyse_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('analyse_description'))).'</a></li>';
Penom Nom's avatar
Penom Nom committed
94
95
96
97
98
			}
			// Return the html_tree
			print $html_tree;
	    	
    	// If asked to check a job status
99
100
    	}
        elseif($type == 'check_status') {
101
102
    		$pid = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pid'));
    		$archive_path = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('archive_path'));
Penom Nom's avatar
Penom Nom committed
103
104
105
106
107
108
109
110
111
112
113
    		$process = new Process();
    		$process->setPid($pid);
    		// If the job is done
    		if ($process->status()) {
    			print "pid=0&archive_path=".$archive_path;
    		// If the job is still runing
    		} else {
    			print "pid=".$process->getPid()."&archive_path=".$archive_path;
    		}
            
    	// If asked to hide a {project/run}
114
    	} elseif ($type == 'hide') {
Penom Nom's avatar
Penom Nom committed
115
    		
116
    		$ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ids'));
Penom Nom's avatar
Penom Nom committed
117
118
    		// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
119
    		$hide_level = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('hide_level'));
Penom Nom's avatar
Penom Nom committed
120
121
122
    		
    		if ($hide_level == 'project') {
	    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
123
		    		tx_nG6_db::hide_project($value);
Penom Nom's avatar
Penom Nom committed
124
	    		}
125
    		} elseif ($hide_level == 'run') {
Penom Nom's avatar
Penom Nom committed
126
	    		foreach($tab_ids as $id => $value) {
127
		    		tx_nG6_db::hide_run($value, $user_id);
Penom Nom's avatar
Penom Nom committed
128
	    		}
129
    		} elseif ($hide_level == 'analysis') {
Penom Nom's avatar
Penom Nom committed
130
	    		foreach($tab_ids as $id => $value) {
131
		    		tx_nG6_db::hide_analysis($value, $user_id);
Penom Nom's avatar
Penom Nom committed
132
133
134
135
	    		}
    		}

        // If asked to unhide a {project/run}
136
    	} elseif ($type == 'unhide') {
Penom Nom's avatar
Penom Nom committed
137
    		    		
138
    		$ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ids'));
Penom Nom's avatar
Penom Nom committed
139
140
    		// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
141
    		$unhide_level = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('unhide_level'));
Penom Nom's avatar
Penom Nom committed
142
143
144

    		if ($unhide_level == 'project') {
	    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
145
		    		tx_nG6_db::unhide_project($value);
Penom Nom's avatar
Penom Nom committed
146
	    		}
147
    		} elseif ($unhide_level == 'run') {
Penom Nom's avatar
Penom Nom committed
148
	    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
149
		    		tx_nG6_db::unhide_run($value, true);
Penom Nom's avatar
Penom Nom committed
150
	    		}
151
    		} elseif ($unhide_level == 'analysis') {
Penom Nom's avatar
Penom Nom committed
152
	    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
153
		    		tx_nG6_db::unhide_analysis($value, true);
Penom Nom's avatar
Penom Nom committed
154
155
156
157
	    		}
    		}
    		
    	// If asked to delete a {project/run/analyze}	
158
159
    	}
        elseif ($type == 'delete') {
Penom Nom's avatar
Penom Nom committed
160

161
    		$ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ids'));
Penom Nom's avatar
Penom Nom committed
162
163
    		// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
164
165
166
167
    		$delete_level = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('del_level'));
    		$data_folder = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('data_folder'));
			$user_login = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_login'));
			$user_pwd = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_pwd'));
Penom Nom's avatar
Penom Nom committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

    		$res = 0;
    		// check login and password
    		if (isset($user_login) && isset($user_pwd) && $user_login != 'undefined' && $user_pwd != 'undefined') {
    			$res = 0;
		    	$connection = ssh2_connect('127.0.0.1', 22);
				if (!$connection) { $res = 3; }
				if (!ssh2_auth_password($connection, $user_login, $user_pwd)) { $res=2;}
    		} else {
    			$res = 3;
    		}
			
			if ($res == 0) {
	    		if ($delete_level == 'project') {
		    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
183
			    		$res = tx_nG6_db::delete_project($value, $user_login, $user_pwd, $data_folder);
Penom Nom's avatar
Penom Nom committed
184
185
			    		if ($res != 0) { break; }
		    		}
186
	    		} elseif ($delete_level == 'run') {
Penom Nom's avatar
Penom Nom committed
187
		    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
188
			    		$res = tx_nG6_db::delete_run($value, $user_login, $user_pwd, $data_folder);
Penom Nom's avatar
Penom Nom committed
189
190
			    		if ($res != 0) { break; }
		    		}
191
	    		} elseif ($delete_level == 'analysis') {
Penom Nom's avatar
Penom Nom committed
192
193
194
195
196
197
198
199
200
		    		foreach($tab_ids as $id => $value) {
			    		$res = tx_nG6_db::delete_analysis($value, $user_login, $user_pwd, $data_folder);
			    		if ($res != 0) { break; }
		    		}
	    		}
			}
    		print $res;

        // If asked to publish a project
201
    	} elseif ($type == 'publish') {
Penom Nom's avatar
Penom Nom committed
202
    		    		
203
    		$ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ids'));
Penom Nom's avatar
Penom Nom committed
204
205
206
    		// project_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
207
	    		tx_nG6_db::publish_project($value);
Penom Nom's avatar
Penom Nom committed
208
209
210
    		}
    		
        // If asked to unpublish a project
211
    	} elseif ($type == 'unpublish') {
Penom Nom's avatar
Penom Nom committed
212
    		    		
213
    		$ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ids'));
Penom Nom's avatar
Penom Nom committed
214
215
216
217
218
219
220
    		// project_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
    		foreach($tab_ids as $id => $value) {
	    		tx_nG6_db::unpublish_project($value);
    		}
    		
        // If asked the size
221
    	} elseif ($type == 'get_size') {
222
223
    		$ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ids'));
    		$view = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('view'));
Penom Nom's avatar
Penom Nom committed
224
225
226
227
    		$tab_ids = explode(",",$ids);
    		$full_size = 0;
    		foreach($tab_ids as $id => $value) {
    			if ($view == "run") {
228
    				$full_size += tx_nG6_db::get_run_size($value, true);
229
    			} elseif ($view == "project") {
230
    				$full_size += tx_nG6_db::get_project_size($value, true);
Penom Nom's avatar
Penom Nom committed
231
232
233
234
    			}
    		}
    		print tx_nG6_utils::get_octet_string_representation($full_size);
    	
Penom Nom's avatar
Penom Nom committed
235
    	// data size
236
    	}elseif ($type == 'get_data_size'){
237
238
239
    		$run_ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('run_ids'));
    		$data_ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('data_ids'));
    		$analysis_ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('analysis_ids'));
Penom Nom's avatar
Penom Nom committed
240
241
242
243
    		$full_size = 0;
    		
    		if ($run_ids){
    			$data = explode(',', $run_ids);
244
245
    			foreach($data as $id => $value) {
    				$full_size += tx_nG6_db::get_run_size($value, true);
Penom Nom's avatar
Penom Nom committed
246
247
    			}
    		}
248
    		if ($data_ids){
Penom Nom's avatar
Penom Nom committed
249
250
251
    			$data = explode(',', $data_ids);
    			foreach($data as $id => $value) {
    				$full_size += tx_nG6_db::get_run_size($value, false);
252
    			}
Penom Nom's avatar
Penom Nom committed
253
    		}
254
    		if ($analysis_ids){
Penom Nom's avatar
Penom Nom committed
255
256
257
    			$data = explode(',', $analysis_ids);
    			foreach($data as $id => $value) {
    				$full_size += tx_nG6_db::get_analysis_size($value);
258
    			}
Penom Nom's avatar
Penom Nom committed
259
260
261
    		}
    		print $full_size . ":::" . tx_nG6_utils::get_octet_string_representation($full_size);
    		
Penom Nom's avatar
Penom Nom committed
262
    	// If update a field
263
    	} elseif ($type == 'update_db_field') {
264
    		
Penom Nom's avatar
Penom Nom committed
265
    		//Retrieve infomation
266
267
268
269
    		$table = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('table'));
    		$id     = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pk'));
    		$field  = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('field'));
    		$value  = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('value'));
Penom Nom's avatar
Penom Nom committed
270
271
    	
    		//If change concernes a date
272
    		if( $field == "date" || $field == "crdate" ) {
Penom Nom's avatar
Penom Nom committed
273
    			//Change date format
274
275
    			$date = explode('-', $value);
    			$timestamp = mktime (0, 0, 1, $date[1], $date[2], $date[0]);
Penom Nom's avatar
Penom Nom committed
276
    			//Update the entity
277
    			tx_nG6_db::update_field($table, $id, $field, $timestamp);
Penom Nom's avatar
Penom Nom committed
278
    		}
279
    		else {
Penom Nom's avatar
Penom Nom committed
280
    			//Update the entity
281
    			tx_nG6_db::update_field($table, $id, $field, $value);
Penom Nom's avatar
Penom Nom committed
282
283
    		}
    		print $value;
284
285
286

    	}
    	// add comment
287
    	elseif ($type == 'add_comment') {	
288
289
290
291
    		$view 			= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('view'));
    		$view_id    	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('view_id')); // project_id or run_id or analyze_id
    		$new_comment  	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('new_comment'));
    		$cruser_id		= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cruser_id'));
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
    		$res = 0 ;
    		
    		if ($new_comment){
	    			if($view == 'project'){
	    				$res = tx_nG6_db::add_project_comment($view_id, $cruser_id, $new_comment) ;
	    			}
	    			elseif ($view == 'run') {
	    				$res = tx_nG6_db::add_run_comment($view_id, $cruser_id, $new_comment) ;
	    			}
	    			elseif ($view == 'analyze') {
	    				$res = tx_nG6_db::add_analyze_comment($view_id, $cruser_id, $new_comment) ;
	    			}
    		}
    		
    		print $res;
    	}
    	//delete comment
309
    	elseif ($type == 'delete_comment') {
310
311
312
313
314
315
316
317
318
319
320
321
322
323
    		$view 			= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('view'));
    		$view_id    	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('view_id')); // project_id or run_id or analyze_id
    		$comment_id		= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('comment_id'));
    		$res = 0 ;
    		if($view == 'project'){
    			$res = tx_nG6_db::delete_project_comment($view_id, $comment_id);
    		}
    		elseif ($view == 'run') {
    			$res = tx_nG6_db::delete_run_comment($view_id, $comment_id);
    		}
    		elseif ($view == 'analyze') {
    			$res = tx_nG6_db::delete_analyze_comment($view_id, $comment_id);
    		}
    		print $res;
324
    	}
325
    	//update comment
326
    	elseif ($type == 'update_comment') {
327
328
    		$comment_id		= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('comment_id'));
    		$new_comment  	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('new_comment'));
329
    		$res = 0;
330
    		$new_comment = urldecode($new_comment);
331
   			$res = tx_nG6_db::update_comment($comment_id, $new_comment);
332
   			print $res;
Penom Nom's avatar
Penom Nom committed
333
334
    	
    	// If asked the krona page
335
    	} elseif ($type == 'get_krona') {
Penom Nom's avatar
Penom Nom committed
336
    		
337
338
339
    		$data_folder = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('data_folder'));
    		$file_name = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('file_name'));
    		$sequence_name = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('sequence_name'));
Penom Nom's avatar
Penom Nom committed
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
    		
    		$doc = new DomDocument();
    		$data_root = $doc->createElement('data');
    		$doc->appendChild($data_root);
    		$attr_data_root = $doc->createAttribute("xml:id");
    		$data_root->appendChild($attr_data_root);
    		
    		$t_data_root = $doc->createTextNode('data_root');
    		$attr_data_root->appendChild($t_data_root);
    		$data_root->setIdAttribute("xml:id", true);
    		
    		$magnitude = $doc->createElement('magnitude');
    		$magnitude->setAttribute("attribute", "g");
    		$magnitude = $data_root->appendChild($magnitude);
    		$magnitudet = $doc->createTextNode('');
    		$magnitudet = $magnitude->appendChild($magnitudet); 
    		
    		$color = $doc->createElement('color');
    		$color = $data_root->appendChild($color);    		
    		$colort = $doc->createTextNode('');
    		$colort = $color->appendChild($colort); 
    		
    		$attributes = $doc->createElement('attributes');
    		$attributes->setAttribute("g", $sequence_name);
    		$attributes = $data_root->appendChild($attributes);  
    		$attributest = $doc->createTextNode('');
    		$attributest = $attributes->appendChild($attributest); 
    		
    		$datasets = $doc->createElement('datasets');
    		$datasets->setAttribute("names", $file_name);
    		$datasets = $data_root->appendChild($datasets); 
    		$datasetst = $doc->createTextNode('');
    		$datasetst = $datasets->appendChild($datasetst); 

374
			$file_path = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('file_path'));
Penom Nom's avatar
Penom Nom committed
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
			$file_path = $data_folder."/".$file_path;
			
			// If the file exists
			$total = 0;
			if (file_exists($file_path)) {
				$lines = file($file_path);
				// Loop through our array
				foreach ($lines as $line_num => $line) {
					if ($line != "") {
						$mparts = explode("\t", trim($line));
						if ($mparts[0] != "taxlevel" and $mparts[0] != "0") {
							// If this guy doesnt exist yet
							$id_searched = str_replace(".", "_", "node_".$mparts[1]);
							if (is_null($doc->getElementById($id_searched))) {
    	        				$parentl = implode("_", array_slice(explode(".", $mparts[1]), 0, -1));
        	        			// If no parent yet, this is the root
        	        			if (is_null($doc->getElementById("node_".$parentl))) {
        	        				$current_node = $doc->createElement('node');
        	        				$current_node->setAttribute("name", $mparts[2]);
        	        				$current_node->setAttribute("g", $mparts[4]);
        	        				$id = $doc->getElementById("data_root");
        	        				$id->appendChild($current_node);
        	        				$attr_current_node = $doc->createAttribute("xml:id");
									$current_node->appendChild($attr_current_node);	        	        				
        	        				$t_current_node = $doc->createTextNode("node_".str_replace(".", "_", $mparts[1]));
									$attr_current_node->appendChild($t_current_node);
									$current_node->setIdAttribute("xml:id", true);
						    		$current_nodet = $doc->createTextNode('');
						    		$current_nodet = $current_node->appendChild($current_nodet);
        	        			} else {
        	        				$current_node = $doc->createElement('node');
        	        				$current_node->setAttribute("name", $mparts[2]);
        	        				$current_node->setAttribute("g", $mparts[4]);
        	        				$id = $doc->getElementById("node_".$parentl);
        	        				$id->appendChild($current_node);
        	        				$attr_current_node = $doc->createAttribute("xml:id");
									$current_node->appendChild($attr_current_node);	        	        				
        	        				$t_current_node = $doc->createTextNode("node_".str_replace(".", "_", $mparts[1]));
									$attr_current_node->appendChild($t_current_node);
									$current_node->setIdAttribute("xml:id", true);
						    		$current_nodet = $doc->createTextNode('');
						    		$current_nodet = $current_node->appendChild($current_nodet); 
        	        			}
    	        			}
						}
						if ($mparts[0] == "1") {
							$total += (int)$mparts[4];
						}
					}
				}
			}    			
			
    		$color->setAttribute("attribute", "g");
    		$color->setAttribute("valueStart", "0");
    		$color->setAttribute("valueEnd", (string)$total);
    		$color->setAttribute("hueStart", "120");
    		$color->setAttribute("hueEnd", "360");
			
			$xml_string = $doc->saveXML();
			$xml_parts = explode("\n", $xml_string);
    		$val = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
    		$val .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">';
    		$val .= '<head>';
    		$val .= '</head>';
    		$val .= '<body>';
    		$val .= '<div id="options" style="position:absolute;left:0;top:0"></div>';
    		$val .= '<div id="details" style="position:absolute;top:1%;right:2%;text-align:right;"></div>';
    		$val .= '<canvas id="canvas" width="100%" height="100%">This browser does not support HTML5</canvas><div>';
    		$val .= '<img id="hiddenImage" src="http://krona.sourceforge.net/img/hidden.png" visibility="hide"/>';
444
    		$val .= '<script name="tree" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('nG6').'res/js/krona-1.1.js"></script>';
Penom Nom's avatar
Penom Nom committed
445
446
447
448
449
    		$val .= $xml_parts[1];
    		$val .= '</div>';
    		$val .= '</body>';
    		$val .= '</html>';
    		print $val;
Jerome Mariette's avatar
Jerome Mariette committed
450
    		
451
    	} elseif ($type == 'delete_users') {
Jerome Mariette's avatar
Jerome Mariette committed
452
    		
453
    		$ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ids'));
Jerome Mariette's avatar
Jerome Mariette committed
454
455
    		// users_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
456
			$project_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project_id'));
Jerome Mariette's avatar
Jerome Mariette committed
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
			
			// try to delete users in project ...
			if($project_id != "") {				
				$none_access = "";
				foreach($tab_ids as $id => $del_user_id) {
					tx_nG6_db::delete_access_to_project($del_user_id, $project_id);
					
					// find if user can't access to any project
					$users_access = tx_nG6_db::count_number_of_project_access($del_user_id);
					if($users_access == '0'){
						$none_access .= $del_user_id.";";
					}
				}
				
				if($none_access == ""){		// everybody has at least one access to a project
					$others_access = '0';	
				}else{						// list separate by coma of users who can't access to any project
					$others_access = substr($none_access, 0, -1);
				}
				
				print $others_access;
				
			// delete users of DB...
			}else{
				
				foreach($tab_ids as $k_id => $v_id){
					// delete group
					$gid = tx_nG6_db::get_user_usergroup($v_id);
					// delete user
					tx_nG6_db::delete_user($v_id);
					if(tx_nG6_db::count_users_in_group($gid) == 0){
						tx_nG6_db::delete_group($gid);
					}
				}
				
			}
			
		// to change users' right on project
495
    	} elseif ($type == 'change_right') {
Jerome Mariette's avatar
Jerome Mariette committed
496
    		
497
498
499
			$project_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project_id'));
			$c_user_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('c_user_id'));
			$right_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('right_id'));
Jerome Mariette's avatar
Jerome Mariette committed
500
501
502
503

			tx_nG6_db::change_access_to_project($c_user_id, $project_id, $right_id);
			
		// jquery autocomplete
504
    	} elseif ($type == 'autocomplete') {
Jerome Mariette's avatar
Jerome Mariette committed
505
    		
506
507
508
    		$col = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('gender'));
    		$project_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project_id'));
    		$name_start = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('name_start'));
509
    		
Jerome Mariette's avatar
Jerome Mariette committed
510
    		// user search
511
    		if($col != 'title' && $col != 'location' && $col != 'organism'){
Jerome Mariette's avatar
Jerome Mariette committed
512
513
514
515
516
517
518
519
520
521
522
523
    			$res = tx_nG6_db::get_all_names_starting_with($name_start, $col);
	    		foreach($res as $res_id => $res_val){
	    			// find right on project
	    			$res[$res_id]['right_id'] = tx_nG6_db::get_user_right_on_project($res_val['uid'], $project_id);
	    			
	    			// find creator username 
	    			$cruser_infos = tx_nG6_db::get_user_informations($res[$res_id]['cruser_id']);
	    			$res[$res_id]['cruser_username'] = $cruser_infos['username'];
	    		}
	    		
	    	// group search
    		}else{
524
    			if ($col == "location" || $col == "organism") { $col = "tx_nG6_".$col; }
525
    			$res = tx_nG6_db::get_all_starts_with_in_group($name_start, $col);
Jerome Mariette's avatar
Jerome Mariette committed
526
527
528
529
530
    		}
    		$json_res = json_encode($res);
    		print $json_res;
    	
    	// add a new member on project
531
    	} elseif ($type == 'add_user') {
Jerome Mariette's avatar
Jerome Mariette committed
532
    		
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    		$part 		= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('part'));
    		$user_name	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('username'));
    		$project_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project_id'));
    		$right_id	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('right'));
    		$group_name	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('title'));
    		$location	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('location'));
    		$organism	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('organism'));
    		$email = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('email'));
    		$first_name = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('first_name'));
    		$last_name = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('last_name'));
    		$password = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('password'));
			$cruser_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('creator'));
			$from_email = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('from_email'));
			$pid = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pid'));
			$project_url = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project_url'));
			$send_an_email = filter_var(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('send_an_email')), FILTER_VALIDATE_BOOLEAN);
549
			
Jerome Mariette's avatar
Jerome Mariette committed
550
551
552
553
    		// if group not exists, create group
    		$group_id = tx_nG6_db::get_group_id($group_name);
    		if( !isset($group_id) ){
    			
554
    			$cruser_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('creator'));
555
    			tx_nG6_db::create_new_group($cruser_id, $group_name, $organism, $location);
Jerome Mariette's avatar
Jerome Mariette committed
556
557
558
559
    			$group_id = tx_nG6_db::get_group_id($group_name);
    			
    		}
    			
Jerome Mariette's avatar
Jerome Mariette committed
560
    		$user = tx_nG6_db::select_user_by_username($user_name);
Jerome Mariette's avatar
Jerome Mariette committed
561

Jerome Mariette's avatar
Jerome Mariette committed
562
    		// if user does not exists in DB
Jerome Mariette's avatar
Jerome Mariette committed
563
    		if(!isset($user)){
564
    		
565
566
    			$create_user_email = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('create_user_email'));
    			$create_user_title = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('create_user_title'));
Jerome Mariette's avatar
Jerome Mariette committed
567
    			
568
    			$res_code = tx_nG6_db::add_user($user_name, $first_name, $last_name, $email, tx_nG6_utils::hash_password($password), $cruser_id, $group_id, $pid);
Jerome Mariette's avatar
Jerome Mariette committed
569
    			
Jerome Mariette's avatar
Jerome Mariette committed
570
571
    			if ($res_code == 0) {
	    			// find the new user id
Jerome Mariette's avatar
Jerome Mariette committed
572
	    			$user = tx_nG6_db::select_user_by_username($user_name);
Jerome Mariette's avatar
Jerome Mariette committed
573
574
	    			
	    			// authorize new access
Jerome Mariette's avatar
Jerome Mariette committed
575
	    			tx_nG6_db::add_access_to_project($user["uid"], $project_id, $right_id);
Jerome Mariette's avatar
Jerome Mariette committed
576
577
578
579
580
581
	    			
	    			if ($send_an_email) {
		    			// send an email to the new user
		    			$message = str_replace("###USER_FIRST_NAME###", $first_name, $create_user_email);
		    			$message = str_replace("###USER_LAST_NAME###", $last_name, $message);
		    			$message = str_replace("###USER_LOGIN###", $user_name, $message);
582
		    			$message = str_replace("###USER_PASSWORD###", $password, $message);
Jerome Mariette's avatar
Jerome Mariette committed
583
584
585
586
587
588
		    			$message = str_replace("###PROJECT_LINK###", $project_url, $message);
		    			$msg_table = explode('\n', $message);
		    			$message = implode("\n", $msg_table);
		    			mail($email, $create_user_title, $message, "From: <".$from_email.">");
		    		}
	    			print '2'; // ok
589
	    		} elseif ($res_code == 1) {
Jerome Mariette's avatar
Jerome Mariette committed
590
	    			print '4'; // username exists
591
	    		} elseif ($res_code == 2) {
Jerome Mariette's avatar
Jerome Mariette committed
592
	    			print '5'; // email exists
Jerome Mariette's avatar
Jerome Mariette committed
593
	    		}
Jerome Mariette's avatar
Jerome Mariette committed
594
	    		
Jerome Mariette's avatar
Jerome Mariette committed
595
    		// user exists in DB
596
    		} elseif ($user["username"] != $user_name || $user["email"] != $email || $user["first_name"] != $first_name || $user["last_name"] != $last_name) {
Jerome Mariette's avatar
Jerome Mariette committed
597
598
599
    			// there is difference between information provided and the user account
    			print '3';
    		} else {
Jerome Mariette's avatar
Jerome Mariette committed
600
    			// can user access to the project ? 
Jerome Mariette's avatar
Jerome Mariette committed
601
    			if(tx_nG6_db::get_user_right_on_project($user["uid"], $project_id) == -1){
Jerome Mariette's avatar
Jerome Mariette committed
602
603

    				// authorize new access
Jerome Mariette's avatar
Jerome Mariette committed
604
    				tx_nG6_db::add_access_to_project($user["uid"], $project_id, $right_id);
Jerome Mariette's avatar
Jerome Mariette committed
605
606
    				
	    			// send an email to the  user
Jerome Mariette's avatar
Jerome Mariette committed
607
	    			if ($email != "" && $send_an_email) {
Jerome Mariette's avatar
Jerome Mariette committed
608
	    			
609
610
		    			$add_user_email = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('add_user_email'));
		    			$add_user_title = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('add_user_title'));
Jerome Mariette's avatar
Jerome Mariette committed
611
612
613
614
615
	    				$project = tx_nG6_db::select_project($project_id);
		    			$message = str_replace("###USER_FIRST_NAME###", $first_name, $add_user_email);
		    			$message = str_replace("###USER_LAST_NAME###", $last_name, $message);
		    			$message = str_replace("###PROJECT_NAME###", $project["name"], $message);
		    			$message = str_replace("###PROJECT_DESCRIPTION###", $project["description"], $message);
616
		    			$message = str_replace("###PROJECT_LINK###", $project_url, $message);
Jerome Mariette's avatar
Jerome Mariette committed
617
618
619
		    			$msg_table = explode('\n', $message);
		    			$message = implode("\n", $msg_table);
		    			mail($email, $add_user_title, $message, "From: <".$from_email.">");
Jerome Mariette's avatar
Jerome Mariette committed
620
		    			
Jerome Mariette's avatar
Jerome Mariette committed
621
		    		}
Jerome Mariette's avatar
Jerome Mariette committed
622
    				print '0';
Jerome Mariette's avatar
Jerome Mariette committed
623
    				
Jerome Mariette's avatar
Jerome Mariette committed
624
625
626
627
    			} else {
    				print '1';	// already access to the project
    			}
    		}
Jerome Mariette's avatar
Jerome Mariette committed
628

Penom Nom's avatar
Penom Nom committed
629
    	}
630
    	elseif ($type == 'check_ssh_user'){
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
			$user_login = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_login'));
			$user_pwd = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_pwd'));
			$project_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project_id'));
			
			$path_to_check = tx_nG6_utils::get_project_data_save_dir($project_id);

    		$res = 3;
    		// check login and password
    		if (isset($user_login) && isset($user_pwd) && $user_login != 'undefined' && $user_pwd != 'undefined') {
				$ssh_command = 'touch '.$path_to_check.'/test ; rm -f '.$path_to_check.'/test' ;
				$connection = ssh2_connect('127.0.0.1', 22);
				
    			if (!$connection) {
    				//1st test, basic SSH connection
    				$res = 3;
646
    			} elseif( !ssh2_auth_password($connection, $user_login,$user_pwd ) ){
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
    				//2nd test, SSH connection with user + pwd
    				$res = 2;
    			}else{
    				//3rd test, excuting the SSH command
					$stream = ssh2_exec($connection, $ssh_command );
    				$errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
    				// Enable blocking for both streams
    				stream_set_blocking($errorStream, true);
    				stream_set_blocking($stream, true);
    				
    				if(stream_get_contents($errorStream)) {
    					// Close the streams
    					fclose($errorStream);
    					fclose($stream);
    					$res = 4;
    				}else{
    					fclose($errorStream);
    					fclose($stream);
						$res = 0;
    				}
    			}
	
    		} else {
    			//The user and/or password is missing
    			$res = 3;
    		}
    		print $res;
    		

    	}
677
    	elseif ( $type == 'add_to_ng6_admin'){
678
    		$userid = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('userid'));
Penom Nom's avatar
Penom Nom committed
679
680
    		tx_nG6_db::add_to_ng6_admin($userid);
    	}
681
    	elseif ( $type == 'delete_from_ng6_admin'){
682
683
684
    		$userids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('userids'));
    		$userids = explode(',', $userids);
    		tx_nG6_db::remove_from_ng6_admin($userids);
Penom Nom's avatar
Penom Nom committed
685
    	}
686
    	elseif ( $type == 'add_to_ng6_superadmin'){
687
688
689
    		$userid = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('userid'));
    		tx_nG6_db::add_to_ng6_superadmin($userid);
    	}
690
    	elseif ( $type == 'delete_from_ng6_superadmin'){
691
692
693
694
    		$userids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('userids'));
    		$userids = explode(',', $userids);
    		tx_nG6_db::remove_from_ng6_superadmin($userids);
    	}
695
    	elseif($type == 'update_user'){
696
697
698
699
700
701
    		$email = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('email'));
    		$first_name = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('first_name'));
    		$last_name = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('last_name'));
    		$group_name	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('title'));
    		$location	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('location'));
    		$organism	= trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('organism'));
Gerald Salin's avatar
Gerald Salin committed
702
    		$user_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_id'));
703
704
705
706
    		$password = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('password'));
    		$cruser_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('creator'));
    		$send_an_email = filter_var(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('send_an_email')), FILTER_VALIDATE_BOOLEAN);
    		$from_email = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('from_email'));
707
708
709
710
711
712
713
714
715
716
    		
    		$updated = tx_nG6_db::update_user($user_id, $first_name, $last_name, $email, $group_name, $organism, $location, tx_nG6_utils::hash_password($password)) ;
    		
    		$nb_updated = count($updated);
    		
    		if ( $nb_updated > 0 && $send_an_email){
    			$user_infos = tx_nG6_db::get_user_informations($user_id);
    			$email = $user_infos['email'];
    			$first_name =  $user_infos['first_name'];
    			$last_name =  $user_infos['last_name'];
717
718
    			$username = $user_infos['username'];
    			
719
    			$mail_title = "[NG6]Your user informations have been updated.";
720
    			$mail_content = "Dear " . $first_name . " " . $last_name . " (user name : ".$username."),\n\nSome of your personnal informations have been updated : \n\n";
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
    			if ($email != ''){
    				foreach($updated as $key => $value){
    					
    					if($key == 'password'){
    						$mail_content .= 'password' . "\t: " . $password . "\n" ;
    					}
    					elseif ($key == 'usergroup'){
    						$mail_content .= 'title' . "\t: " . $group_name . "\n" ;
    						$mail_content .= 'location' . "\t: " . $location . "\n" ;
    						$mail_content .= 'organism' . "\t: " . $organism . "\n" ;
    					}
    					else {
    						$mail_content .= ucwords(str_replace("_", " ", $key)) . "\t: " . $value . "\n" ;
    					}
    				}
736
    				$mail_content .= "\nThe NG6 team";
737
738
739
740
    				mail($email, $mail_title, $mail_content, "From: <".$from_email.">");
    			}
    		}
    		
741
    		print $nb_updated;
Penom Nom's avatar
Penom Nom committed
742
    	}
743
    	elseif ($type == 'get_user_group'){
Gerald Salin's avatar
Gerald Salin committed
744
    		$id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_id'));
745
    		print json_encode(tx_nG6_db::get_group_informations(tx_nG6_db::get_user_usergroup($id)));
Penom Nom's avatar
Penom Nom committed
746
    	}
Penom Nom's avatar
Penom Nom committed
747
    	elseif($type == 'runs_table') {
748
749
750
751
752
753
    		$smarty = new Smarty();
    		$smarty->setTemplateDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/pi1');
    		$smarty->setCompileDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/templates_c');
    		$smarty->setCacheDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/cache');
    		$smarty->setConfigDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/configs');
    		$smarty->security = true;
Jerome Mariette's avatar
Jerome Mariette committed
754
    		$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
755
756
757
758
    		$project_id = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project_id')));
    		$user_id = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_id')));
    		$login_user = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('login_user')));
    		$page_id = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('page_id')));
Jerome Mariette's avatar
Jerome Mariette committed
759
    		$project_runs = tx_nG6_db::get_project_runs($project_id);
760
    		$is_project_admin = tx_nG6_db::is_administrator($user_id, 'project', $project_id);
761
    		$is_at_least_admin_of_1_run = false;
Jerome Mariette's avatar
Jerome Mariette committed
762
    		foreach($project_runs as $run_id => $run_values) {
763
    			$is_admin = tx_nG6_db::is_administrator($user_id, 'run', $run_values['id']);
Jerome Mariette's avatar
Jerome Mariette committed
764
765
    			$project_runs[$run_id]['is_admin'] = $is_admin;
    			if ($is_admin) { $is_at_least_admin_of_1_run = true; }
766
767
768
    			$href = '<a href="index.php?id='.$page_id.'&tx_nG6_pi1[run_id]='.$run_values['id'].'&tx_nG6_pi1[project_id]='.$run_values['project_id'].'">'.$run_values['name'].'</a>';
    			$project_runs[$run_id]['href'] = $href;
    		}
Jerome Mariette's avatar
Jerome Mariette committed
769
    		$smarty->assign('runs', $project_runs);
770
    		$smarty->assign('is_project_admin', $is_project_admin);
Jerome Mariette's avatar
Jerome Mariette committed
771
772
773
    		$smarty->assign('is_at_least_admin_of_1_run', $is_at_least_admin_of_1_run);
    		$smarty->assign('login_user', $login_user);
    		print $smarty->fetch('run_table.tpl');
774
    		
775
776
    	}
        elseif($type == 'projects_table') {
777
    		$smarty = new Smarty();
778
779
780
781
    		$smarty->setTemplateDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/pi1');
    		$smarty->setCompileDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/templates_c');
    		$smarty->setCacheDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/cache');
    		$smarty->setConfigDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/configs');
782
783
    		$smarty->security = true;
    		$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
784
785
786
787
788
    		$user_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_id'));
    		$login_user = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('login_user')));
    		$page_id = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('page_id')));
    		$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.uid DESC');
    		//$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.name');
789
790
791
    		$is_at_least_admin_of_1_project = false;
    		foreach($projects as $project_id => $project_values) {
    			$is_admin = tx_nG6_db::is_project_administrator($user_id, $project_values['id']);
792
793
794
795
796
    			if ($is_admin) { $is_at_least_admin_of_1_project = true; }
    			$projects[$project_id]['is_admin'] = $is_admin;
    			$projects[$project_id]['is_manager'] = tx_nG6_db::is_project_manager($user_id, $project_values['id']);
    			$projects[$project_id]['is_member'] = tx_nG6_db::is_project_member($user_id, $project_values['id']);
    			$href = '<a href="index.php?id='.$page_id.'&tx_nG6_pi1[project_id]='.$project_values['id'].'">'.$project_values['name'].'</a>';
797
798
799
800
801
    			$projects[$project_id]['href'] = $href;
    		}
    		$smarty->assign('projects', $projects);
    		$smarty->assign('is_at_least_admin_of_1_project', $is_at_least_admin_of_1_project);
    		$smarty->assign('login_user', $login_user);
Penom Nom's avatar
Penom Nom committed
802
    		$smarty->assign('is_ng6_admin', tx_nG6_db::is_ng6_administrator($user_id) ? true : false);
803
    		print $smarty->fetch('project_table.tpl');
804
805
806
    		
    	} elseif($type == 'analyses_table') {    		
    		$smarty = new Smarty();
807
808
809
810
    		$smarty->setTemplateDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/pi1');
    		$smarty->setCompileDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/templates_c');
    		$smarty->setCacheDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/cache');
    		$smarty->setConfigDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/configs');
811
812
    		$smarty->security = true;
    		$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
813
814
815
816
817
    		$user_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_id'));
    		$login_user = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('login_user')));
    		$page_id = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('page_id')));
    		$project_id = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project_id')));
    		$run_id = intVal(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('run_id')));
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
    		if ($run_id != "") {
    			$analysis = tx_nG6_db::get_run_analysis($run_id);
    		} else {
    			$analysis = tx_nG6_db::get_project_analysis($project_id);
    		}
			// Add some information to the table
			foreach($analysis as $analysis_id => $analysis_values) {
				if (tx_nG6_db::is_administrator($user_id, 'analyze', $analysis_values['id'])) { $is_admin = true; }
				$analysis[$analysis_id]['is_admin'] = tx_nG6_db::is_administrator($user_id, 'analyze', $analysis_values['id']);
				if ($run_id != "") {
					$href = '<a href="index.php?id='.$page_id.'&tx_nG6_pi1[project_id]='.$project_id.'&tx_nG6_pi1[run_id]='.$run_id.'&tx_nG6_pi1[analyze_id]='.$analysis_values['id'].'">'.$analysis_values['name'].'</a>';
				} else {
					$href = '<a href="index.php?id='.$page_id.'&tx_nG6_pi1[project_id]='.$project_id.'&tx_nG6_pi1[analyze_id]='.$analysis_values['id'].'">'.$analysis_values['name'].'</a>';
				}
				$analysis[$analysis_id]['href'] = $href;
			}
			$smarty->assign('display_analysis_result', $is_admin);
			$smarty->assign('is_admin', $is_admin);
    		$smarty->assign('h_analysis', tx_nG6_utils::trace_hierarchy($analysis));
    		$smarty->assign('login_user', $login_user);
    		print $smarty->fetch('analysis_table.tpl');
Celine Noirot's avatar
Celine Noirot committed
839
840
841
    	} elseif($type == 'install') {
    		$res = tx_nG6_db::select_user_by_username("admin_install");
    		if ($res != null){
Jerome Mariette's avatar
Jerome Mariette committed
842
    			$res2 = tx_nG6_db::finalize_installation($res["uid"],
843
844
845
846
847
848
    					trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('username')),
    					trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('first_name')),
    					trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('last_name')),
    					trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('email')),
    					tx_nG6_utils::hash_password(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('password'))),
    					trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pid')),
849
    					"Demo project",
Penom Nom's avatar
Penom Nom committed
850
    					"This project presents demonstration workflows",
851
852
853
    					trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('title')),
    					trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('organism')),
    					trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('location'))
Penom Nom's avatar
Penom Nom committed
854
    					
Celine Noirot's avatar
Celine Noirot committed
855
    			);
Jerome Mariette's avatar
Jerome Mariette committed
856
857
    			// if there is a result, then log the user
    			if ($res2) {
858
    				$GLOBALS['TSFE'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'), '');
Jerome Mariette's avatar
Jerome Mariette committed
859
860
861
    				$GLOBALS['TSFE']->initFEuser();
    				$GLOBALS['TSFE']->fe_user->createUserSession(array('uid' =>$res["uid"]));
    			}
Celine Noirot's avatar
Celine Noirot committed
862
    		}
Celine Noirot's avatar
Celine Noirot committed
863
    		print $res;
Jerome Mariette's avatar
Jerome Mariette committed
864
    	} elseif($type == 'project_data_repartition') {
865
866
    		$role = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('role'));    		
    		$by = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('by'));
867
    		print json_encode(tx_nG6_db::select_projects_repartition($role, $by));
868
    	} elseif($type == 'project_distribution') {
869
    		$values = explode(",", trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('values')));
870
871
    		$by = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('by'));
    		$role = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('role'));
872
    		print json_encode(tx_nG6_db::select_projects_distribution($values, $by, $role));
Penom Nom's avatar
Penom Nom committed
873
    	} elseif($type == 'project_evolution') {
874
    		$values = explode(",", trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('values')));
875
876
    		$by = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('by'));
    		$role = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('role'));
877
    	    $cumulate = false;
878
    		if(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cumulate')) == '1'){
879
880
881
    			$cumulate = true;
    		}
    		print json_encode(tx_nG6_db::select_projects_evolution($values, $by, $role, $cumulate));
882
    		
Jerome Mariette's avatar
Jerome Mariette committed
883
    	} elseif($type == 'data_distribution'){
884
    		$values = explode(",", trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('values')));
885
886
    		$by = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('by'));
    		$role = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('role'));
Jerome Mariette's avatar
Jerome Mariette committed
887
    		$get_analyzes = false;
888
    		if(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('get_analyzes')) == '1'){
Jerome Mariette's avatar
Jerome Mariette committed
889
890
    			$get_analyzes = true;
    		}
Jerome Mariette's avatar
Jerome Mariette committed
891
    		$octet = true;
892
    		if(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('bases')) == '1'){
Jerome Mariette's avatar
Jerome Mariette committed
893
    			$octet = false;
Jerome Mariette's avatar
Jerome Mariette committed
894
    		}
Jerome Mariette's avatar
Jerome Mariette committed
895
    		print json_encode(tx_nG6_db::select_storage_distribution($values, $by, $role, $get_analyzes, $octet));
896
    		
897
		} elseif($type == 'data_evolution'){
898
    		$values = explode(",", trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('values')));
899
900
    		$by = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('by'));
    		$role = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('role'));
901
    		$get_analyzes = false;
902
    		if(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('get_analyzes')) == '1'){
903
904
905
    			$get_analyzes = true;
    		}
    		$octet = true;
906
    		if(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('bases')) == '1'){
907
908
909
    			$octet = false;
    		}
    		$cumulate = false;
910
    		if(trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cumulate')) == '1'){
911
912
913
    			$cumulate = true;
    		}
    		print json_encode(tx_nG6_db::select_storage_evolution($values, $by, $role, $get_analyzes, $octet, $cumulate));
914
    		
915
    	} elseif ($type == 'purge_managment_mail') {
916
                $all_projects = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('project')); 
Celine Noirot's avatar
Celine Noirot committed
917
918
                print json_encode(tx_nG6_pi6::send_purge_demand_mail($all_projects));
        } elseif ($type == 'purge_managment_resend_mail') {
919
                        $purge_ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('purge_demand'));    
Celine Noirot's avatar
Celine Noirot committed
920
                         print json_encode(tx_nG6_pi6::resend_purge_demand_mail($purge_ids));
921
922
        } elseif ($type == 'refresh_purge_demand') {
                $purge_delay = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('purge_delay'));
Celine Noirot's avatar
Celine Noirot committed
923
                print json_encode(tx_nG6_db::get_purge_demand_list($purge_delay));
924
    	}  elseif ($type == 'refresh_purge_list') {
925
                $max_retention_date = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('max_retention_date'));
Romain Therville's avatar
Romain Therville committed
926
    		$filter_space = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('filter_space'));
927
    		
928
    		$without_laboratories_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('without_lab'));
929
                $with_laboratories_id = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('with_lab'));
930
    		$create_users = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('create_users'));
931
    		//Change date format
932
                //print ('test');
933
    		print json_encode(tx_nG6_db::filter_list_retention_data_info($filter_space,$max_retention_date,$create_users, $without_laboratories_id,$with_laboratories_id));
Celine Noirot's avatar
Celine Noirot committed
934
        } elseif ($type == 'delete_purge_data') {
Celine Noirot's avatar
Celine Noirot committed
935
                 //Delete data link to the list of purge demand
936
937
938
939
                 $purge_ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('purge_demand'));    
                        $data_folder = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('data_folder'));
			$user_login = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_login'));
			$user_pwd = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('user_pwd'));
940
941
942

                $res = tx_nG6_db::delete_purge_demand($purge_ids,$user_login, $user_pwd, $data_folder);
                print $res;
943
        } elseif ($type == 'extend_retention_date_from_demand') {
Celine Noirot's avatar
Celine Noirot committed
944
                //Extend the retention date for the
945
946
947
                        $purge_ids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('purge_demand'));    		
                        $value =  trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('date_value'));
                        $type_extend =  trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('type_extend')); //all project or only run/analyse obsolete
Celine Noirot's avatar
Celine Noirot committed
948
949
950
                        //Change date format
                        $date = explode('/', $value);
                        $timestamp = mktime (0, 0, 1, $date[1], $date[0], $date[2]);
951
952
953
                        print json_encode(tx_nG6_db::extend_retention_date_from_demand(explode(',',$purge_ids),$timestamp,$type_extend));
        } elseif ($type == 'extend_retention_date_from_project') {
                //Extend the retention date for the
954
955
                        $projects_id_str = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('projects_id'));    		
                        $value =  trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('date_value'));
956
957
958
959
960
961
962
963
                        //Change date format
                        $date = explode('/', $value);
                        $timestamp = mktime (0, 0, 1, $date[1], $date[0], $date[2]);
                        //TODO project
                        print json_encode(tx_nG6_db::extend_retention_date_from_project($projects_id_str,$timestamp, TRUE));
        } elseif ($type == 'get_all_project') {
                print json_encode(tx_nG6_db::select_all_projects());
        }				
Penom Nom's avatar
Penom Nom committed
964
965
966
967
968
969
970
971
972
    }

}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_eid.php']) {
    include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_eid.php']);
}

// Instanciation
973
$SOBE = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_nG6_eid');
Penom Nom's avatar
Penom Nom committed
974
975
$SOBE->main();

976
?>