class.tx_nG6_eid.php 38.5 KB
Newer Older
Penom Nom's avatar
Penom Nom committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?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!
***************************************************************/

require_once(PATH_t3lib.'class.t3lib_befunc.php');
require_once(PATH_t3lib.'stddb/tables.php');
require_once(t3lib_extMgm::extPath('cms','ext_tables.php'));
require_once(PATH_t3lib.'class.t3lib_db.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_db.php');
30
require_once(t3lib_extMgm::extPath('nG6').'/pi6/class.tx_nG6_pi6.php');
Penom Nom's avatar
Penom Nom committed
31
32
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_utils.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_process.php');
Jerome Mariette's avatar
Jerome Mariette committed
33
require_once(t3lib_extMgm::extPath('nG6').'/res/smarty/libs/Smarty.class.php');
Penom Nom's avatar
Penom Nom committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

/**
 * 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() {

    	// Connect to the databse
    	tslib_eidtools::connectDB();
    	$type = trim(t3lib_div::_GP('type'));
51
    	$user_id = trim(t3lib_div::_GP('user_id'));
Penom Nom's avatar
Penom Nom committed
52

Penom Nom's avatar
Penom Nom committed
53
54
55
56
    	// If the type of data requested is project
    	if ($type == 'project') {
    		$project_id = trim(t3lib_div::_GP('id'));
	    	// Select all runs linked to the project
Penom Nom's avatar
Penom Nom committed
57
	    	$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
58
59
60
61
62
63
	    	// for each run
	    	$html_tree = '';
			foreach($project_runs as $run_id => $run_values) {
				$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(t3lib_div::_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(t3lib_div::_GP('run_description'))).'</a></li>';
			}
	    	// Then all project analysis
Penom Nom's avatar
Penom Nom committed
64
	    	$project_analysis = tx_nG6_db::get_user_project_analysis($user_id, $project_id, 'tx_nG6_analyze.name');
Penom Nom's avatar
Penom Nom committed
65
66
67
68
69
70
71
72
73
74
			foreach($project_analysis as $analyse_id => $analyse_values) {  
				$html_tree .= '<li name=\''.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'\' id=\''.$analyse_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'</a></li>';
			}
			// Return the html_tree
	    	print $html_tree;
	    	
	    // If the type of data requested is run
    	} else if ($type == 'run'){
			$run_id = trim(t3lib_div::_GP('id'));
			// Select all analysis linked to the run and the run information
Penom Nom's avatar
Penom Nom committed
75
			$run_analysis = tx_nG6_db::get_user_run_analysis($user_id, $run_id, 'tx_nG6_analyze.name');
Penom Nom's avatar
Penom Nom committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
			$run_info = tx_nG6_db::select_run($run_id);
	    	// for each analysis
	    	$html_tree = '';
			$html_tree .= '<li name=\'run_'.$run_id.'_'.trim(t3lib_div::_GP("raw_data_description")).'\'  id=\'data_'.$run_id.'\'> <a href=\'#\'>'.trim(t3lib_div::_GP("raw_data_description")).'</a></li>';
			foreach($run_analysis as $analyse_id => $analyse_values) {   
				$html_tree .= '<li name=\'run_'.$run_id.'_'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'\' id=\''.$analyse_id.'\'> <a href=\'#\'>'.str_replace(array('###SPAN_NAME###'), array($analyse_values["name"]), trim(t3lib_div::_GP('analyse_description'))).'</a></li>';
			}
			// Return the html_tree
			print $html_tree;
	    	
    	// If asked to check a job status
    	} else if($type == 'check_status') {
    		$pid = trim(t3lib_div::_GP('pid'));
    		$archive_path = trim(t3lib_div::_GP('archive_path'));
    		$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}
    	} else if ($type == 'hide') {
    		
    		$ids = trim(t3lib_div::_GP('ids'));
    		// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
    		$hide_level = trim(t3lib_div::_GP('hide_level'));
    		
    		if ($hide_level == 'project') {
	    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
110
		    		tx_nG6_db::hide_project($value);
Penom Nom's avatar
Penom Nom committed
111
112
113
	    		}
    		} else if ($hide_level == 'run') {
	    		foreach($tab_ids as $id => $value) {
114
		    		tx_nG6_db::hide_run($value, $user_id);
Penom Nom's avatar
Penom Nom committed
115
116
117
	    		}
    		} else if ($hide_level == 'analysis') {
	    		foreach($tab_ids as $id => $value) {
118
		    		tx_nG6_db::hide_analysis($value, $user_id);
Penom Nom's avatar
Penom Nom committed
119
120
121
122
123
124
125
126
127
128
129
130
131
	    		}
    		}

        // If asked to unhide a {project/run}
    	} else if ($type == 'unhide') {
    		    		
    		$ids = trim(t3lib_div::_GP('ids'));
    		// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
    		$unhide_level = trim(t3lib_div::_GP('unhide_level'));

    		if ($unhide_level == 'project') {
	    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
132
		    		tx_nG6_db::unhide_project($value);
Penom Nom's avatar
Penom Nom committed
133
134
135
	    		}
    		} else if ($unhide_level == 'run') {
	    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
136
		    		tx_nG6_db::unhide_run($value, true);
Penom Nom's avatar
Penom Nom committed
137
138
139
	    		}
    		} else if ($unhide_level == 'analysis') {
	    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
140
		    		tx_nG6_db::unhide_analysis($value, true);
Penom Nom's avatar
Penom Nom committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
	    		}
    		}
    		
    	// If asked to delete a {project/run/analyze}	
    	} else if ($type == 'delete') {

    		$ids = trim(t3lib_div::_GP('ids'));
    		// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
    		$delete_level = trim(t3lib_div::_GP('del_level'));
    		$data_folder = trim(t3lib_div::_GP('data_folder'));
			$user_login = trim(t3lib_div::_GP('user_login'));
			$user_pwd = trim(t3lib_div::_GP('user_pwd'));

    		$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
169
			    		$res = tx_nG6_db::delete_project($value, $user_login, $user_pwd, $data_folder);
Penom Nom's avatar
Penom Nom committed
170
171
172
173
			    		if ($res != 0) { break; }
		    		}
	    		} else if ($delete_level == 'run') {
		    		foreach($tab_ids as $id => $value) {
Jerome Mariette's avatar
Jerome Mariette committed
174
			    		$res = tx_nG6_db::delete_run($value, $user_login, $user_pwd, $data_folder);
Penom Nom's avatar
Penom Nom committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
			    		if ($res != 0) { break; }
		    		}
	    		} else if ($delete_level == 'analysis') {
		    		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
    	} else if ($type == 'publish') {
    		    		
    		$ids = trim(t3lib_div::_GP('ids'));
    		// 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
193
	    		tx_nG6_db::publish_project($value);
Penom Nom's avatar
Penom Nom committed
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
    		}
    		
        // If asked to unpublish a project
    	} else if ($type == 'unpublish') {
    		    		
    		$ids = trim(t3lib_div::_GP('ids'));
    		// 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
    	} else if ($type == 'get_size') {
    		$ids = trim(t3lib_div::_GP('ids'));
    		$view = trim(t3lib_div::_GP('view'));
    		$tab_ids = explode(",",$ids);
    		$full_size = 0;
    		foreach($tab_ids as $id => $value) {
    			if ($view == "run") {
214
    				$full_size += tx_nG6_db::get_run_size($value, true);
Penom Nom's avatar
Penom Nom committed
215
    			} else if ($view == "project") {
216
    				$full_size += tx_nG6_db::get_project_size($value, true);
Penom Nom's avatar
Penom Nom committed
217
218
219
220
    			}
    		}
    		print tx_nG6_utils::get_octet_string_representation($full_size);
    	
Penom Nom's avatar
Penom Nom committed
221
    	// data size
Penom Nom's avatar
Penom Nom committed
222
    	}else if ($type == 'get_data_size'){
Penom Nom's avatar
Penom Nom committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
    		$run_ids = trim(t3lib_div::_GP('run_ids'));
    		$data_ids = trim(t3lib_div::_GP('data_ids'));
    		$analysis_ids = trim(t3lib_div::_GP('analysis_ids'));
    		$full_size = 0;
    		
    		if ($run_ids){
    			$data = explode(',', $run_ids);
    			foreach($data as $id => $value) {
    				$full_size += tx_nG6_db::get_run_size($value, true);
    			}
    		}
    		if ($data_ids){
    			$data = explode(',', $data_ids);
    			foreach($data as $id => $value) {
    				$full_size += tx_nG6_db::get_run_size($value, false);
    			}
    		}
    		if ($analysis_ids){
    			$data = explode(',', $analysis_ids);
    			foreach($data as $id => $value) {
    				$full_size += tx_nG6_db::get_analysis_size($value);
    			}
    		}
    		print $full_size . ":::" . tx_nG6_utils::get_octet_string_representation($full_size);
    		
Penom Nom's avatar
Penom Nom committed
248
249
    	// If update a field
    	} else if ($type == 'update_db_field') {
250
    		
Penom Nom's avatar
Penom Nom committed
251
    		//Retrieve infomation
252
    		$table = trim(t3lib_div::_GP('table'));
253
    		$id     = trim(t3lib_div::_GP('pk'));
Penom Nom's avatar
Penom Nom committed
254
255
256
257
    		$field  = trim(t3lib_div::_GP('field'));
    		$value  = trim(t3lib_div::_GP('value'));
    	
    		//If change concernes a date
258
    		if( $field == "date" || $field == "crdate" ) {
Penom Nom's avatar
Penom Nom committed
259
    			//Change date format
260
261
    			$date = explode('-', $value);
    			$timestamp = mktime (0, 0, 1, $date[1], $date[2], $date[0]);
Penom Nom's avatar
Penom Nom committed
262
    			//Update the entity
263
    			tx_nG6_db::update_field($table, $id, $field, $timestamp);
Penom Nom's avatar
Penom Nom committed
264
    		}
265
    		else {
Penom Nom's avatar
Penom Nom committed
266
    			//Update the entity
267
    			tx_nG6_db::update_field($table, $id, $field, $value);
Penom Nom's avatar
Penom Nom committed
268
269
    		}
    		print $value;
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

    	}
    	// add comment
    	else if ($type == 'add_comment') {	
    		$view 			= trim(t3lib_div::_GP('view'));
    		$view_id    	= trim(t3lib_div::_GP('view_id')); // project_id or run_id or analyze_id
    		$new_comment  	= trim(t3lib_div::_GP('new_comment'));
    		$cruser_id		= trim(t3lib_div::_GP('cruser_id'));
    		$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
    	else if ($type == 'delete_comment') {
    		$view 			= trim(t3lib_div::_GP('view'));
    		$view_id    	= trim(t3lib_div::_GP('view_id')); // project_id or run_id or analyze_id
    		$comment_id		= trim(t3lib_div::_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;
    	}
    	//update comment
    	else if ($type == 'update_comment') {
    		$comment_id		= trim(t3lib_div::_GP('comment_id'));
    		$new_comment  	= trim(t3lib_div::_GP('new_comment'));
    		$res = 0;
    		$new_comment = urldecode($new_comment);
   			$res = tx_nG6_db::update_comment($comment_id, $new_comment);
   			print $res;
Penom Nom's avatar
Penom Nom committed
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
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
374
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
    	
    	// If asked the krona page
    	} else if ($type == 'get_krona') {
    		
    		$data_folder = trim(t3lib_div::_GP('data_folder'));
    		$file_name = trim(t3lib_div::_GP('file_name'));
    		$sequence_name = trim(t3lib_div::_GP('sequence_name'));
    		
    		$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); 

			$file_path = trim(t3lib_div::_GP('file_path'));
			$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"/>';
    		$val .= '<script name="tree" src="'.t3lib_extMgm::siteRelPath('nG6').'res/js/krona-1.1.js"></script>';
    		$val .= $xml_parts[1];
    		$val .= '</div>';
    		$val .= '</body>';
    		$val .= '</html>';
    		print $val;
Jerome Mariette's avatar
Jerome Mariette committed
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
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
    		
    	} else if ($type == 'delete_users') {
    		
    		$ids = trim(t3lib_div::_GP('ids'));
    		// users_id to array (1;2;3;...) -> [1;2;3;...]
    		$tab_ids = explode(";",$ids);
			$project_id = trim(t3lib_div::_GP('project_id'));
			
			// 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
    	} else if ($type == 'change_right') {
    		
			$project_id = trim(t3lib_div::_GP('project_id'));
			$c_user_id = trim(t3lib_div::_GP('c_user_id'));
			$right_id = trim(t3lib_div::_GP('right_id'));

			tx_nG6_db::change_access_to_project($c_user_id, $project_id, $right_id);
			
		// jquery autocomplete
    	} else if ($type == 'autocomplete') {
    		
    		$col = trim(t3lib_div::_GP('gender'));
    		$project_id = trim(t3lib_div::_GP('project_id'));
494
495
    		$name_start = trim(t3lib_div::_GP('name_start'));
    		
Jerome Mariette's avatar
Jerome Mariette committed
496
    		// user search
497
    		if($col != 'title' && $col != 'location' && $col != 'organism'){
Jerome Mariette's avatar
Jerome Mariette committed
498
499
500
501
502
503
504
505
506
507
508
509
    			$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{
510
    			if ($col == "location" || $col == "organism") { $col = "tx_nG6_".$col; }
511
    			$res = tx_nG6_db::get_all_starts_with_in_group($name_start, $col);
Jerome Mariette's avatar
Jerome Mariette committed
512
513
514
515
516
    		}
    		$json_res = json_encode($res);
    		print $json_res;
    	
    	// add a new member on project
Jerome Mariette's avatar
Jerome Mariette committed
517
    	} else if ($type == 'add_user') {
Jerome Mariette's avatar
Jerome Mariette committed
518
519
520
521
522
    		
    		$part 		= trim(t3lib_div::_GP('part'));
    		$user_name	= trim(t3lib_div::_GP('username'));
    		$project_id = trim(t3lib_div::_GP('project_id'));
    		$right_id	= trim(t3lib_div::_GP('right'));
523
524
525
    		$group_name	= trim(t3lib_div::_GP('title'));
    		$location	= trim(t3lib_div::_GP('location'));
    		$organism	= trim(t3lib_div::_GP('organism'));
526
527
528
529
530
531
532
    		$email = trim(t3lib_div::_GP('email'));
    		$first_name = trim(t3lib_div::_GP('first_name'));
    		$last_name = trim(t3lib_div::_GP('last_name'));
    		$password = trim(t3lib_div::_GP('password'));
			$cruser_id = trim(t3lib_div::_GP('creator'));
			$from_email = trim(t3lib_div::_GP('from_email'));
			$pid = trim(t3lib_div::_GP('pid'));
533
			$project_url = trim(t3lib_div::_GP('project_url'));
Jerome Mariette's avatar
Jerome Mariette committed
534
			$send_an_email = filter_var(trim(t3lib_div::_GP('send_an_email')), FILTER_VALIDATE_BOOLEAN);
535
			
Jerome Mariette's avatar
Jerome Mariette committed
536
537
538
539
540
    		// if group not exists, create group
    		$group_id = tx_nG6_db::get_group_id($group_name);
    		if( !isset($group_id) ){
    			
    			$cruser_id = trim(t3lib_div::_GP('creator'));
541
    			tx_nG6_db::create_new_group($cruser_id, $group_name, $organism, $location);
Jerome Mariette's avatar
Jerome Mariette committed
542
543
544
545
    			$group_id = tx_nG6_db::get_group_id($group_name);
    			
    		}
    			
Jerome Mariette's avatar
Jerome Mariette committed
546
    		$user = tx_nG6_db::select_user_by_username($user_name);
Jerome Mariette's avatar
Jerome Mariette committed
547

Jerome Mariette's avatar
Jerome Mariette committed
548
    		// if user does not exists in DB
Jerome Mariette's avatar
Jerome Mariette committed
549
    		if(!isset($user)){
550
551
552
    		
    			$create_user_email = trim(t3lib_div::_GP('create_user_email'));
    			$create_user_title = trim(t3lib_div::_GP('create_user_title'));
Jerome Mariette's avatar
Jerome Mariette committed
553
    			
554
    			$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
555
    			
Jerome Mariette's avatar
Jerome Mariette committed
556
557
    			if ($res_code == 0) {
	    			// find the new user id
Jerome Mariette's avatar
Jerome Mariette committed
558
	    			$user = tx_nG6_db::select_user_by_username($user_name);
Jerome Mariette's avatar
Jerome Mariette committed
559
560
	    			
	    			// authorize new access
Jerome Mariette's avatar
Jerome Mariette committed
561
	    			tx_nG6_db::add_access_to_project($user["uid"], $project_id, $right_id);
Jerome Mariette's avatar
Jerome Mariette committed
562
563
564
565
566
567
	    			
	    			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);
568
		    			$message = str_replace("###USER_PASSWORD###", $password, $message);
Jerome Mariette's avatar
Jerome Mariette committed
569
570
571
572
573
574
575
576
577
578
		    			$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
	    		} else if ($res_code == 1) {
	    			print '4'; // username exists
	    		} else if ($res_code == 2) {
	    			print '5'; // email exists
Jerome Mariette's avatar
Jerome Mariette committed
579
	    		}
Jerome Mariette's avatar
Jerome Mariette committed
580
	    		
Jerome Mariette's avatar
Jerome Mariette committed
581
    		// user exists in DB
Jerome Mariette's avatar
Jerome Mariette committed
582
583
584
585
    		} else if ($user["username"] != $user_name || $user["email"] != $email || $user["first_name"] != $first_name || $user["last_name"] != $last_name) {
    			// there is difference between information provided and the user account
    			print '3';
    		} else {
Jerome Mariette's avatar
Jerome Mariette committed
586
    			// can user access to the project ? 
Jerome Mariette's avatar
Jerome Mariette committed
587
    			if(tx_nG6_db::get_user_right_on_project($user["uid"], $project_id) == -1){
Jerome Mariette's avatar
Jerome Mariette committed
588
589

    				// authorize new access
Jerome Mariette's avatar
Jerome Mariette committed
590
    				tx_nG6_db::add_access_to_project($user["uid"], $project_id, $right_id);
Jerome Mariette's avatar
Jerome Mariette committed
591
592
    				
	    			// send an email to the  user
Jerome Mariette's avatar
Jerome Mariette committed
593
	    			if ($email != "" && $send_an_email) {
Jerome Mariette's avatar
Jerome Mariette committed
594
	    			
595
596
		    			$add_user_email = trim(t3lib_div::_GP('add_user_email'));
		    			$add_user_title = trim(t3lib_div::_GP('add_user_title'));
Jerome Mariette's avatar
Jerome Mariette committed
597
598
599
600
601
	    				$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);
602
		    			$message = str_replace("###PROJECT_LINK###", $project_url, $message);
Jerome Mariette's avatar
Jerome Mariette committed
603
604
605
		    			$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
606
		    			
Jerome Mariette's avatar
Jerome Mariette committed
607
		    		}
Jerome Mariette's avatar
Jerome Mariette committed
608
    				print '0';
Jerome Mariette's avatar
Jerome Mariette committed
609
    				
Jerome Mariette's avatar
Jerome Mariette committed
610
611
612
613
    			} else {
    				print '1';	// already access to the project
    			}
    		}
Jerome Mariette's avatar
Jerome Mariette committed
614

Penom Nom's avatar
Penom Nom committed
615
616
617
618
619
620
621
622
623
624
625
    	}
    	
    	else if ( $type == 'add_to_ng6_admin'){
    		$userid = trim(t3lib_div::_GP('userid'));
    		tx_nG6_db::add_to_ng6_admin($userid);
    	}
    	else if ( $type == 'delete_from_ng6_admin'){
    		$userids = trim(t3lib_div::_GP('userids'));
    		$userids = explode(',', $userids);
    		tx_nG6_db::remove_from_ng6_admin($userids);
    	}
Penom Nom's avatar
Penom Nom committed
626
627
628
629
630
631
632
    	else if($type == 'update_user'){
    		$email = trim(t3lib_div::_GP('email'));
    		$first_name = trim(t3lib_div::_GP('first_name'));
    		$last_name = trim(t3lib_div::_GP('last_name'));
    		$group_name	= trim(t3lib_div::_GP('title'));
    		$location	= trim(t3lib_div::_GP('location'));
    		$organism	= trim(t3lib_div::_GP('organism'));
633
    		$user_id = trim(t3lib_div::_GP('id'));
Penom Nom's avatar
Penom Nom committed
634
    		$password = trim(t3lib_div::_GP('password'));
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
    		$cruser_id = trim(t3lib_div::_GP('creator'));
    		$send_an_email = filter_var(trim(t3lib_div::_GP('send_an_email')), FILTER_VALIDATE_BOOLEAN);
    		$from_email = trim(t3lib_div::_GP('from_email'));
    		
    		$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'];
    			$mail_title = "[NG6]Your user informations have been updated.";
    			$mail_content = "Dear " . $first_name . " " . $last_name . ",\n\nSome of your personnal informations have been updated : \n\n";
    			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" ;
    					}
    				}
    				$mail_content .= "\nThe NG6 team";
    				mail($email, $mail_title, $mail_content, "From: <".$from_email.">");
    			}
    		}
    		
    		print $nb_updated;
Penom Nom's avatar
Penom Nom committed
671
    	}
Penom Nom's avatar
Penom Nom committed
672
673
674
675
    	else if ($type == 'get_user_group'){
    		$id = trim(t3lib_div::_GP('id'));
    		print json_encode(tx_nG6_db::get_group_informations(tx_nG6_db::get_user_usergroup($id)));
    	}
Penom Nom's avatar
Penom Nom committed
676
    	elseif($type == 'runs_table') {
Jerome Mariette's avatar
Jerome Mariette committed
677
678
679
680
681
682
683
684
685
686
687
688
    		$smarty = new Smarty();
    		$smarty->setTemplateDir(t3lib_extMgm::extPath('nG6').'/pi1');
    		$smarty->setCompileDir(t3lib_extMgm::extPath('nG6').'/res/smarty/templates_c');
    		$smarty->setCacheDir(t3lib_extMgm::extPath('nG6').'/res/smarty/cache');
    		$smarty->setConfigDir(t3lib_extMgm::extPath('nG6').'/res/smarty/configs');
    		$smarty->security = true;
    		$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
    		$project_id = intVal(trim(t3lib_div::_GP('project_id')));
    		$user_id = intVal(trim(t3lib_div::_GP('user_id')));
    		$login_user = intVal(trim(t3lib_div::_GP('login_user')));
    		$page_id = intVal(trim(t3lib_div::_GP('page_id')));
    		$project_runs = tx_nG6_db::get_project_runs($project_id);
689
    		$is_project_admin = tx_nG6_db::is_administrator($user_id, 'project', $project_id);
Jerome Mariette's avatar
Jerome Mariette committed
690
691
692
693
694
695
696
697
698
    		$is_at_least_admin_of_1_run = false;
    		foreach($project_runs as $run_id => $run_values) {
    			$is_admin = tx_nG6_db::is_administrator($user_id, 'run', $run_values['id']);
    			$project_runs[$run_id]['is_admin'] = $is_admin;
    			if ($is_admin) { $is_at_least_admin_of_1_run = true; }
    			$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;
    		}
    		$smarty->assign('runs', $project_runs);
699
    		$smarty->assign('is_project_admin', $is_project_admin);
Jerome Mariette's avatar
Jerome Mariette committed
700
701
702
    		$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');
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
    		
    	} elseif($type == 'projects_table') {
    		$smarty = new Smarty();
    		$smarty->setTemplateDir(t3lib_extMgm::extPath('nG6').'/pi1');
    		$smarty->setCompileDir(t3lib_extMgm::extPath('nG6').'/res/smarty/templates_c');
    		$smarty->setCacheDir(t3lib_extMgm::extPath('nG6').'/res/smarty/cache');
    		$smarty->setConfigDir(t3lib_extMgm::extPath('nG6').'/res/smarty/configs');
    		$smarty->security = true;
    		$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
    		$user_id = trim(t3lib_div::_GP('user_id'));
    		$login_user = intVal(trim(t3lib_div::_GP('login_user')));
    		$page_id = intVal(trim(t3lib_div::_GP('page_id')));
    		$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.name');
    		$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']);
    			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>';
    			$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
729
    		$smarty->assign('is_ng6_admin', tx_nG6_db::is_ng6_administrator($user_id) ? true : false);
730
    		print $smarty->fetch('project_table.tpl');
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
    		
    	} elseif($type == 'analyses_table') {    		
    		$smarty = new Smarty();
    		$smarty->setTemplateDir(t3lib_extMgm::extPath('nG6').'/pi1');
    		$smarty->setCompileDir(t3lib_extMgm::extPath('nG6').'/res/smarty/templates_c');
    		$smarty->setCacheDir(t3lib_extMgm::extPath('nG6').'/res/smarty/cache');
    		$smarty->setConfigDir(t3lib_extMgm::extPath('nG6').'/res/smarty/configs');
    		$smarty->security = true;
    		$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
    		$user_id = trim(t3lib_div::_GP('user_id'));
    		$login_user = intVal(trim(t3lib_div::_GP('login_user')));
    		$page_id = intVal(trim(t3lib_div::_GP('page_id')));
    		$project_id = intVal(trim(t3lib_div::_GP('project_id')));
    		$run_id = intVal(trim(t3lib_div::_GP('run_id')));
    		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
766
767
768
    	} elseif($type == 'install') {
    		$res = tx_nG6_db::select_user_by_username("admin_install");
    		if ($res != null){
Jerome Mariette's avatar
Jerome Mariette committed
769
    			$res2 = tx_nG6_db::finalize_installation($res["uid"],
Celine Noirot's avatar
Celine Noirot committed
770
771
772
773
    					trim(t3lib_div::_GP('username')),
    					trim(t3lib_div::_GP('first_name')),
    					trim(t3lib_div::_GP('last_name')),
    					trim(t3lib_div::_GP('email')),
774
    					tx_nG6_utils::hash_password(trim(t3lib_div::_GP('password'))),
Celine Noirot's avatar
Celine Noirot committed
775
    					trim(t3lib_div::_GP('pid')),
776
    					"Demo project",
Penom Nom's avatar
Penom Nom committed
777
778
779
780
781
    					"This project presents demonstration workflows",
    					trim(t3lib_div::_GP('title')),
    					trim(t3lib_div::_GP('organism')),
    					trim(t3lib_div::_GP('location'))
    					
Celine Noirot's avatar
Celine Noirot committed
782
    			);
Jerome Mariette's avatar
Jerome Mariette committed
783
784
785
786
787
788
    			// if there is a result, then log the user
    			if ($res2) {
    				$GLOBALS['TSFE'] = t3lib_div::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], t3lib_div::_GP('id'), '');
    				$GLOBALS['TSFE']->initFEuser();
    				$GLOBALS['TSFE']->fe_user->createUserSession(array('uid' =>$res["uid"]));
    			}
Celine Noirot's avatar
Celine Noirot committed
789
    		}
Celine Noirot's avatar
Celine Noirot committed
790
    		print $res;
Jerome Mariette's avatar
Jerome Mariette committed
791
    	} elseif($type == 'project_data_repartition') {
792
793
794
    		$role = trim(t3lib_div::_GP('role'));    		
    		$by = trim(t3lib_div::_GP('by'));
    		print json_encode(tx_nG6_db::select_projects_repartition($role, $by));
795
796
797
798
799
    	} elseif($type == 'project_distribution') {
    		$values = split(",", trim(t3lib_div::_GP('values')));
    		$by = trim(t3lib_div::_GP('by'));
    		$role = trim(t3lib_div::_GP('role'));
    		print json_encode(tx_nG6_db::select_projects_distribution($values, $by, $role));
Penom Nom's avatar
Penom Nom committed
800
801
802
803
    	} elseif($type == 'project_evolution') {
    		$values = split(",", trim(t3lib_div::_GP('values')));
    		$by = trim(t3lib_div::_GP('by'));
    		$role = trim(t3lib_div::_GP('role'));
804
805
806
807
808
    	    $cumulate = false;
    		if(trim(t3lib_div::_GP('cumulate')) == '1'){
    			$cumulate = true;
    		}
    		print json_encode(tx_nG6_db::select_projects_evolution($values, $by, $role, $cumulate));
809
    		
Jerome Mariette's avatar
Jerome Mariette committed
810
811
812
813
    	} elseif($type == 'data_distribution'){
    		$values = split(",", trim(t3lib_div::_GP('values')));
    		$by = trim(t3lib_div::_GP('by'));
    		$role = trim(t3lib_div::_GP('role'));
Jerome Mariette's avatar
Jerome Mariette committed
814
815
816
817
    		$get_analyzes = false;
    		if(trim(t3lib_div::_GP('get_analyzes')) == '1'){
    			$get_analyzes = true;
    		}
Jerome Mariette's avatar
Jerome Mariette committed
818
    		$octet = true;
Jerome Mariette's avatar
all ok    
Jerome Mariette committed
819
    		if(trim(t3lib_div::_GP('bases')) == '1'){
Jerome Mariette's avatar
Jerome Mariette committed
820
    			$octet = false;
Jerome Mariette's avatar
Jerome Mariette committed
821
    		}
Jerome Mariette's avatar
Jerome Mariette committed
822
    		print json_encode(tx_nG6_db::select_storage_distribution($values, $by, $role, $get_analyzes, $octet));
823
    		
824
825
826
827
828
829
830
831
832
		} elseif($type == 'data_evolution'){
    		$values = split(",", trim(t3lib_div::_GP('values')));
    		$by = trim(t3lib_div::_GP('by'));
    		$role = trim(t3lib_div::_GP('role'));
    		$get_analyzes = false;
    		if(trim(t3lib_div::_GP('get_analyzes')) == '1'){
    			$get_analyzes = true;
    		}
    		$octet = true;
Jerome Mariette's avatar
all ok    
Jerome Mariette committed
833
    		if(trim(t3lib_div::_GP('bases')) == '1'){
834
835
836
837
838
839
840
    			$octet = false;
    		}
    		$cumulate = false;
    		if(trim(t3lib_div::_GP('cumulate')) == '1'){
    			$cumulate = true;
    		}
    		print json_encode(tx_nG6_db::select_storage_evolution($values, $by, $role, $get_analyzes, $octet, $cumulate));
841
    		
842
    	} elseif ($type == 'purge_managment_mail') {
843
844
845
846
                $user_id = trim(t3lib_div::_GP('user_id'));
    		$all_projects = trim(t3lib_div::_GP('project')); 
                
                print json_encode(tx_nG6_pi6::send_purge_demand_mail($user_id,$all_projects));
847
848
849
850
    		
    	}  elseif ($type == 'refresh_purge_list') {
			$max_retention_date = trim(t3lib_div::_GP('max_retention_date'));
    		$filter_size = trim(t3lib_div::_GP('filter_size'));
851
    		$without_laboratories_id = trim(t3lib_div::_GP('without_lab'));
852
853
    		$create_users = trim(t3lib_div::_GP('create_users'));
    		//Change date format
854
855
    		print json_encode(tx_nG6_db::filter_list_retention_data_info($filter_size,$max_retention_date,$create_users, $without_laboratories_id));
		
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
        } elseif ($type == 'delete_data') {
        //Delete data link to the list of purge demand
                $purge_ids = trim(t3lib_div::_GP('purge_demand'));    
                #TODO
                
                print json_encode(tx_nG6_db::set_purge_demand_processed(explode(',',$purge_ids),"delete",""));
        }
        elseif ($type == 'extend_rentention_date') {
        //Extend the retention date for the
                $purge_ids = trim(t3lib_div::_GP('purge_demand'));    		
                $value =  trim(t3lib_div::_GP('date_value'));
                //Change date format
                $date = explode('/', $value);
                $timestamp = mktime (0, 0, 1, $date[1], $date[0], $date[2]);
                error_log("extend_rentention_date : ".$purge_ids."\n",3,"/save/ng6-test/src/nG6/ui/nG6/pi6/test.log");
                print json_encode(tx_nG6_db::set_purge_demand_processed(explode(',',$purge_ids),"extend",$timestamp));
                
        }		
Penom Nom's avatar
Penom Nom committed
874
875
876
877
878
879
880
881
882
883
884
885
    }

}

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
$SOBE = t3lib_div::makeInstance('tx_nG6_eid');
$SOBE->main();

886
?>