class.tx_nG6_db.php 23.7 KB
Newer Older
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
30
31
32
33
34
35
36
37
38
39
40
<?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(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_utils.php');

/**
 * Class_nG6_db' for the 'nG6' extension.
 * This class is in charge of all communication with the database
 *
 * @author	PF bioinformatique de Toulouse <>
 */
class tx_nG6_db {

	/*
	 * Project functions
	 *------------------------------------------------------------*/

	/**
	 * Select all project for the current user
41
	 *
42
43
44
	 * @param	string	$user_group	the user group
	 * @return	table with all projects
	 */
Jerome Mariette's avatar
Jerome Mariette committed
45
	function select_all_user_projects($user_group, $orderby='', $limit='') {
46

47
		$projects = array();
48

49
		// If the user is not logged on display demonstration project
50
		$where = 'tx_nG6_project.hidden=0 AND ';
51
		if (!$GLOBALS['TSFE']->loginUser) {
52
			$where .= 'fe_group=0';
53
		} else {
54
			$where .= 'fe_group IN ('.tx_nG6_db::get_user_groups($user_group).')';
55
		}
56

57
		$orderby='tx_nG6_project.name ASC';
58
		//First, get the analyzis project-scale
59
		$queryParts = array(
60
61
62
63
64
65
66
67
			'SELECT' => 'tx_nG6_project.uid AS project_id, '.
						'tx_nG6_project.name AS project_name, '.
						'tx_nG6_project.description AS project_description, '.
						'tx_nG6_project.fe_group AS project_fe_group, '.
						'tx_nG6_project.hidden AS project_hidden',
			'FROM' => 'tx_nG6_project',
			'WHERE' => $where,
			'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
68
69
			'ORDERBY' => $orderby,
			'LIMIT' => $limit
70
71
72
73
74
		);
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($user_group));
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$project_id = $row['project_id'];
75

76
77
78
79
80
81
82
83
84
85
86
			// Is the user allowed to see this project
			$user_allowed = false;
			if ($row['project_hidden'] == 0) {
				$user_allowed = true;
			} else {
			    foreach(tx_nG6_db::get_super_groups_of($row['project_fe_group']) AS $valeur) {
					if (in_array($valeur, $user_groups)) {
						$user_allowed = true;
					}
			    }
			}
87
88

			if (!isset ($projects['project_'.$project_id]) and $user_allowed) {
89
				$projects['project_'.$project_id] = array(
90
					'id'			=> $project_id,
91
					'name'			=> $row['project_name'],
Jerome Mariette's avatar
Jerome Mariette committed
92
					'hidden'		=> $row['project_hidden'],
93
94
					'description'	=> $row['project_description']);
			}
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
		}
		return $projects;
	}

	/**
	 * Select a run from the database
	 *
	 * @param	string	$project_id	the project id to return
	 * @return	hash table with all project information
	 */
	function select_project($project_id) {
		$queryParts = array(
			'SELECT' => '*',
			'FROM' => 'tx_nG6_project',
			'WHERE' => 'tx_nG6_project.uid = '.$project_id,
			'GROUPBY' => '',
			'ORDERBY' => '',
			'LIMIT' => ''
		);
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		return $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
	}

	/**
	 * Select all runs linked to the specified project
	 *
	 * @param	string	$user_group	the user group
	 * @param	string	$project_id	the project id
	 * @return	hash table with all runs information
	 */
Jerome Mariette's avatar
Jerome Mariette committed
126
    function get_project_runs($user_group, $project_id, $orderby='', $limit='') {
127
		// First select all runs from the database
128
		$queryParts = Array(
129
130
131
132
			'SELECT' => 'tx_nG6_run.uid AS run_id,'.
					 	'tx_nG6_run.directory AS run_directory,'.
					 	'tx_nG6_run.species AS run_species,'.
						'tx_nG6_run.description AS run_description, '.
Jerome Mariette's avatar
Jerome Mariette committed
133
134
135
						'tx_nG6_run.data_nature AS run_data_nature, '.
						'tx_nG6_run.sequencer AS run_sequencer, '.
						'tx_nG6_run.type AS run_type, '.
136
						'tx_nG6_run.name AS run_name, '.
Jerome Mariette's avatar
Jerome Mariette committed
137
138
139
						'tx_nG6_project.uid AS project_id, '.
						'tx_nG6_run.nb_sequences AS run_nb_sequences, '.
						'tx_nG6_run.full_seq_size AS run_full_seq_size, '.
140
141
						'tx_nG6_run.date AS run_date, '.
						'tx_nG6_run.hidden AS run_hidden, '.
Jerome Mariette's avatar
Jerome Mariette committed
142
						'tx_nG6_project.name AS project_name, '.
143
144
145
						'tx_nG6_project.fe_group AS project_fe_group',
			'FROM' => 'tx_nG6_project INNER JOIN ( tx_nG6_project_run INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid '.
					  ' ) ON tx_nG6_project.uid=tx_nG6_project_run.project_id',
146
			'WHERE' => 'tx_nG6_run.hidden=0 AND tx_nG6_project.uid='.$project_id,
147
			'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
148
149
			'ORDERBY' => $orderby,
			'LIMIT' 	=> $limit
150
		);
151
152
153
154
155
156
		// Then create the result hash table
		$results = array();
		$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($user_group));
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$run_id = $row['run_id'];
157

158
159
160
161
162
163
164
165
166
167
168
			// Is the user allowed to see this run
			$user_allowed = false;
			if ($row['run_hidden'] == 0) {
				$user_allowed = true;
			} else {
			    foreach(tx_nG6_db::get_super_groups_of($row['project_fe_group']) AS $valeur) {
					if (in_array($valeur, $user_groups)) {
						$user_allowed = true;
					}
			    }
			}
169
170
171

			if (!isset($results['run_'.$run_id]) and $user_allowed) {
				$results['run_'.$run_id] = array(
Jerome Mariette's avatar
Jerome Mariette committed
172
					'id'			=> $run_id,
173
					'directory'		=> $row['run_directory'],
174
					'name' 			=> $row['run_name'],
Jerome Mariette's avatar
Jerome Mariette committed
175
176
177
					'project_name' 	=> $row['project_name'],
					'fe_group' 		=> $row['project_fe_group'],
					'hidden'		=> $row['run_hidden'],
178
					'species' 		=> $row['run_species'],
Jerome Mariette's avatar
Jerome Mariette committed
179
180
181
					'nb_sequences' 	=> $row['run_nb_sequences'],
					'full_seq_size' => $row['run_full_seq_size'],
					'project_id' 	=> $row['project_id'],
182
					'date'			=> $row['run_date'],
Jerome Mariette's avatar
Jerome Mariette committed
183
184
185
					'data_nature'	=> $row['run_data_nature'],
					'sequencer'		=> $row['run_sequencer'],
					'type'			=> $row['run_type'],
186
					'description' 	=> $row['run_description']
187
				);
188
			}
189
190
191
192
193
194
195
196
197
198
199
		}
		return $results;
    }

	/**
	 * Select all analysis linked to the specified project
	 *
	 * @param	string	$user_group	the user group
	 * @param	string	$project_id	the project id
	 * @return	hash table with all analysis information
	 */
Jerome Mariette's avatar
Jerome Mariette committed
200
    function get_project_analysis($user_group, $project_id, $orderby, $limit) {
201
		// First select all analysis from the database
202
203
204
		$queryParts = array(
			'SELECT' => 'tx_nG6_analyze.uid AS analyze_id,'.
						'tx_nG6_analyze.directory AS analyze_directory,'.
205
206
						'tx_nG6_analyze.name AS analyze_name, '.
						'tx_nG6_analyze.date AS analyze_date, '.
Jerome Mariette's avatar
Jerome Mariette committed
207
208
						'tx_nG6_analyze.software AS analyze_software, '.
						'tx_nG6_analyze.version AS analyze_version, '.
209
210
211
212
213
214
215
						'tx_nG6_analyze.description AS analyze_description, '.
						'tx_nG6_analyze.hidden AS analyze_hidden, '.
						'tx_nG6_project.fe_group AS project_fe_group',
			'FROM' => 'tx_nG6_project INNER JOIN (tx_nG6_project_analyze INNER JOIN tx_nG6_analyze ON ' .
					  'tx_nG6_analyze.uid=tx_nG6_project_analyze.analyze_id) ON tx_nG6_project.uid = tx_nG6_project_analyze.project_id ',
			'WHERE' => 'tx_nG6_project_analyze.project_id='.$project_id,
			'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
216
217
			'ORDERBY' => $orderby,
			'LIMIT' => $limit
218
219
220
221
222
223
224
		);
		// Then create the result hash table
		$results = array();
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($user_group));
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$analyze_id = $row['analyze_id'];
225

226
227
228
229
230
231
232
233
234
235
236
			// Is the user allowed to see this analyse
			$user_allowed = false;
			if ($row['analyze_hidden'] == 0) {
				$user_allowed = true;
			} else {
			    foreach(tx_nG6_db::get_super_groups_of($row['project_fe_group']) AS $valeur) {
					if (in_array($valeur, $user_groups)) {
						$user_allowed = true;
					}
			    }
			}
237
238
239
240

			if (!isset ($results['analyse_'.$analyze_id]) and $user_allowed) {
				$results['analyse_'.$analyze_id] = array(
					'directory'		=> $row['analyze_directory'],
241
					'name' 			=> $row['analyze_name'],
Jerome Mariette's avatar
Jerome Mariette committed
242
243
244
245
					'id' 			=> $row['analyze_id'],
					'hidden' 		=> $row['analyze_hidden'],
					'software' 		=> $row['analyze_software'],
					'version' 		=> $row['analyze_version'],
246
					'date'			=> $row['analyze_date'],
247
					'description' 	=> $row['analyze_description']
248
				);
249
			}
250
251
252
253
254
255
256
257
258
		}
		return $results;
    }


	/*
	 * Run functions
	 *------------------------------------------------------------*/

Jerome Mariette's avatar
Jerome Mariette committed
259
260
	/**
	 * Select all run for the specified user
261
	 *
Jerome Mariette's avatar
Jerome Mariette committed
262
263
264
265
266
267
	 * @param	string	$user_group	the user group
	 * @return	table with all projects
	 */
	function select_all_user_runs($user_group, $orderby='', $limit='') {

		// If the user is not logged on display demonstration project
268
		if (!$GLOBALS['TSFE']->loginUser) {
Jerome Mariette's avatar
Jerome Mariette committed
269
270
			$where = 'fe_group=0';
		} else {
271
			$where = 'fe_group IN ('.tx_nG6_db::get_user_groups($user_group).')';
Jerome Mariette's avatar
Jerome Mariette committed
272
273
		}
     	// Execute the request
274
		$queryParts = Array(
Jerome Mariette's avatar
Jerome Mariette committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
			'SELECT' => 'tx_nG6_run.uid AS run_id,'.
					 	'tx_nG6_run.directory AS run_directory,'.
					 	'tx_nG6_run.species AS run_species,'.
						'tx_nG6_run.description AS run_description, '.
						'tx_nG6_run.data_nature AS run_data_nature, '.
						'tx_nG6_run.sequencer AS run_sequencer, '.
						'tx_nG6_run.type AS run_type, '.
						'tx_nG6_run.name AS run_name, '.
						'tx_nG6_run.nb_sequences AS run_nb_sequences, '.
						'tx_nG6_run.full_seq_size AS run_full_seq_size, '.
						'tx_nG6_run.date AS run_date, '.
						'tx_nG6_run.hidden AS run_hidden, '.
						'tx_nG6_project.uid AS project_id, '.
						'tx_nG6_project.name AS project_name, '.
						'tx_nG6_project.fe_group AS project_fe_group',
			'FROM' => 'tx_nG6_project INNER JOIN ( tx_nG6_project_run INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid '.
					  ' ) ON tx_nG6_project.uid=tx_nG6_project_run.project_id',
			'WHERE' => $where,
			'GROUPBY' => '',
			'ORDERBY' => $orderby,
			'LIMIT' 	=> $limit
296
		);
Jerome Mariette's avatar
Jerome Mariette committed
297
298
299
300
301
302
		// Then create the result hash table
		$results = array();
		$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($user_group));
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$run_id = $row['run_id'];
303

Jerome Mariette's avatar
Jerome Mariette committed
304
305
306
307
308
309
310
311
312
313
314
			// Is the user allowed to see this run
			$user_allowed = false;
			if ($row['run_hidden'] == 0) {
				$user_allowed = true;
			} else {
			    foreach(tx_nG6_db::get_super_groups_of($row['project_fe_group']) AS $valeur) {
					if (in_array($valeur, $user_groups)) {
						$user_allowed = true;
					}
			    }
			}
315
316

			if (!isset($results['run_'.$run_id]) and $user_allowed) {
Jerome Mariette's avatar
Jerome Mariette committed
317
				$results['run_'.$run_id] = array(
318
319
					'id'			=> $run_id,
					'directory'		=> $row['run_directory'],
Jerome Mariette's avatar
Jerome Mariette committed
320
321
322
323
324
325
326
327
328
329
330
331
					'name' 			=> $row['run_name'],
					'project_name' 	=> $row['project_name'],
					'fe_group' 		=> $row['project_fe_group'],
					'project_id' 	=> $row['project_id'],
					'hidden'		=> $row['run_hidden'],
					'species' 		=> $row['run_species'],
					'nb_sequences' 	=> $row['run_nb_sequences'],
					'full_seq_size' => $row['run_full_seq_size'],
					'date'			=> $row['run_date'],
					'data_nature'	=> $row['run_data_nature'],
					'sequencer'		=> $row['run_sequencer'],
					'type'			=> $row['run_type'],
332
					'description' 	=> $row['run_description']
Jerome Mariette's avatar
Jerome Mariette committed
333
				);
334
			}
Jerome Mariette's avatar
Jerome Mariette committed
335
336
337
338
339
		}
		return $results;

	}

340
341
342
343
344
345
	/**
	 * Select all information for the specified run
	 *
	 * @param	string	$run_id	the run id
	 * @return	hash table with all the run information
	 */
Jerome Mariette's avatar
Jerome Mariette committed
346
	function select_run($run_id) {
347
348


349
		// First select the run from the database
350
		$queryParts = Array(
351
352
353
354
355
			'SELECT' => 'tx_nG6_project.uid AS project_id,'.
						'tx_nG6_project.name AS project_name,'.
						'tx_nG6_run.uid AS run_id,'.
					 	'tx_nG6_run.directory AS run_directory,'.
						'tx_nG6_run.description AS run_description, '.
Jerome Mariette's avatar
Jerome Mariette committed
356
						'tx_nG6_run.species AS run_species, '.
357
						'tx_nG6_run.name AS run_name, '.
Jerome Mariette's avatar
Jerome Mariette committed
358
359
360
361
						'tx_nG6_run.data_nature AS run_data_nature, '.
						'tx_nG6_run.sequencer AS run_sequencer, '.
						'tx_nG6_run.type AS run_type, '.
						'tx_nG6_run.full_seq_size, '.
362
363
364
365
366
367
368
369
						'tx_nG6_run.nb_sequences, '.
						'tx_nG6_run.date AS run_date',
			'FROM' => 'tx_nG6_project INNER JOIN ( tx_nG6_project_run INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid '.
					  ' ) ON tx_nG6_project.uid=tx_nG6_project_run.project_id',
			'WHERE' => 'tx_nG6_run.uid='.$run_id,
			'GROUPBY' => '',
			'ORDERBY' => 'tx_nG6_run.date DESC',
			'LIMIT' 	=> ''
370
		);
371
372
373
		// Then create the result hash table
		$result = array();
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
374
375
376
377
378
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$result = array(
				'project_id'	=> $row['project_id'],
				'project_name'	=> $row['project_name'],
				'directory'		=> $row['run_directory'],
Jerome Mariette's avatar
Jerome Mariette committed
379
380
381
382
383
384
385
386
				'name' 			=> $row['run_name'],
				'type' 			=> $row['run_type'],
				'sequencer' 	=> $row['run_sequencer'],
				'data_nature' 	=> $row['run_data_nature'],
				'full_seq_size' => $row['full_seq_size'],
				'species' 		=> $row['run_species'],
				'nb_sequences' 	=> $row['nb_sequences'],
				'date'			=> $row['run_date'],
387
388
				'description' 	=> $row['run_description']
			);
389
390
391
		}
		return $result;
    }
392

393
394
395
396
397
398
399
	/**
	 * Select all analysis linked to the specified run
	 *
	 * @param	string	$user_group	the user group
	 * @param	string	$run_id	the run id
	 * @return	hash table with all analysis information
	 */
Jerome Mariette's avatar
Jerome Mariette committed
400
    function get_run_analysis($user_group, $run_id, $orderby='', $limit='') {
401
		// First select all analysis from the database
402
403
404
		$queryParts = array(
			'SELECT' => 'tx_nG6_analyze.uid AS analyze_id,'.
						'tx_nG6_analyze.directory AS analyze_directory,'.
405
406
						'tx_nG6_analyze.name AS analyze_name, '.
						'tx_nG6_analyze.date AS analyze_date, '.
Jerome Mariette's avatar
Jerome Mariette committed
407
408
						'tx_nG6_analyze.software AS analyze_software, '.
						'tx_nG6_analyze.version AS analyze_version, '.
409
410
411
412
413
414
415
416
						'tx_nG6_analyze.hidden AS analyze_hidden, '.
						'tx_nG6_analyze.description AS analyze_description, '.
						'tx_nG6_project.fe_group AS project_fe_group',
			'FROM' => 'tx_nG6_project INNER JOIN ( tx_nG6_project_run INNER JOIN ( tx_nG6_run INNER JOIN ( tx_nG6_run_analyze INNER JOIN '.
					  'tx_nG6_analyze ON tx_nG6_analyze.uid = tx_nG6_run_analyze.analyze_id) ON tx_nG6_run_analyze.run_id = tx_nG6_run.uid '.
					  ') ON tx_nG6_run.uid = tx_nG6_project_run.run_id) ON tx_nG6_project_run.project_id = tx_nG6_project.uid ',
			'WHERE' => 'tx_nG6_run_analyze.run_id='.$run_id,
			'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
417
418
			'ORDERBY' => $orderby,
			'LIMIT' => $limit
419
420
421
422
423
424
425
		);
		// Then create the result hash table
		$results = array();
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($user_group));
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$analyze_id = $row['analyze_id'];
426

427
428
429
430
431
432
433
434
435
436
437
			// Is the user allowed to see this analyse
			$user_allowed = false;
			if ($row['analyze_hidden'] == 0) {
				$user_allowed = true;
			} else {
			    foreach(tx_nG6_db::get_super_groups_of($row['project_fe_group']) AS $valeur) {
					if (in_array($valeur, $user_groups)) {
						$user_allowed = true;
					}
			    }
			}
438
439
440
441

			if (!isset ($results['analyse_'.$analyze_id]) and $user_allowed) {
				$results['analyse_'.$analyze_id] = array(
					'directory'		=> $row['analyze_directory'],
Jerome Mariette's avatar
Jerome Mariette committed
442
443
444
445
446
447
					'name' 			=> $row['analyze_name'],
					'id' 			=> $row['analyze_id'],
					'hidden' 		=> $row['analyze_hidden'],
					'software' 		=> $row['analyze_software'],
					'version' 		=> $row['analyze_version'],
					'date'			=> $row['analyze_date'],
448
					'description' 	=> $row['analyze_description']
449
				);
450
			}
451
452
453
454
455
456
457
458
		}
		return $results;
    }


	/*
	 * Run functions
	 *------------------------------------------------------------*/
459

460
461
462
463
464
465
	/**
	 * Select all information on an analyse
	 *
	 * @param	string	$analyse_id	the analyse id
	 * @return	hash table with all analyse information
	 */
Jerome Mariette's avatar
Jerome Mariette committed
466
467
    function select_analyse($analyse_id) {

468
		// First select all analyse information
469
470
471
472
473
		$queryParts = array(
			'SELECT' => 'tx_nG6_project.uid AS project_id,'.
						'tx_nG6_project.name AS project_name,'.
						'tx_nG6_analyze.uid AS analyze_id,'.
						'tx_nG6_analyze.directory AS analyze_directory,'.
474
475
476
477
478
479
480
481
482
483
						'tx_nG6_analyze.name AS analyze_name, '.
						'tx_nG6_analyze.date AS analyze_date, '.
						'tx_nG6_analyze.description AS analyze_description ',
			'FROM' => 'tx_nG6_project INNER JOIN (tx_nG6_project_analyze INNER JOIN tx_nG6_analyze ON ' .
					  'tx_nG6_analyze.uid=tx_nG6_project_analyze.analyze_id) ON tx_nG6_project.uid = tx_nG6_project_analyze.project_id ',
			'WHERE' => 'tx_nG6_analyze.uid='.$analyse_id,
			'GROUPBY' => '',
			'ORDERBY' => '',
			'LIMIT' => ''
		);
484

485
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
486

487
488
489
		// If it's a project analyse, add project information
		if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
			$result = array();
490
491
492
			while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
				$result = array(
					'project_name'				=> $row['project_name'],
493
					'project_id'				=> $row['project_id'],
494
495
496
					'run_name'					=> 'None',
					'run_id'					=> 'None',
					'directory'					=> $row['analyze_directory'],
497
498
					'name' 						=> $row['analyze_name'],
					'date'						=> $row['analyze_date'],
499
500
					'description' 				=> $row['analyze_description']
				);
501
502
503
			}
			return $result;
		} else { // If it's a run analyse, add run information
504
			$queryParts = array(
505
506
				'SELECT' => 'tx_nG6_project.name AS project_name,'.
							'tx_nG6_project.uid AS project_id,'.
507
							'tx_nG6_run.uid AS run_id,'.
508
							'tx_nG6_run.name AS run_name,'.
509
510
							'tx_nG6_analyze.uid AS analyze_id,'.
							'tx_nG6_analyze.directory AS analyze_directory,'.
511
512
513
514
515
516
517
518
519
520
521
522
523
							'tx_nG6_analyze.name AS analyze_name, '.
							'tx_nG6_analyze.date AS analyze_date, '.
							'tx_nG6_analyze.description AS analyze_description',
				'FROM' => 'tx_nG6_project INNER JOIN ( tx_nG6_project_run INNER JOIN ( tx_nG6_run INNER JOIN ( tx_nG6_run_analyze INNER JOIN '.
						  'tx_nG6_analyze ON tx_nG6_analyze.uid = tx_nG6_run_analyze.analyze_id) ON tx_nG6_run_analyze.run_id = tx_nG6_run.uid '.
						  ') ON tx_nG6_run.uid = tx_nG6_project_run.run_id) ON tx_nG6_project_run.project_id = tx_nG6_project.uid ',
				'WHERE' => 'tx_nG6_analyze.uid='.$analyse_id,
				'GROUPBY' => '',
				'ORDERBY' => 'tx_nG6_analyze.name',
				'LIMIT' => ''
			);
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$result = array();
524
525
526
			while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
				$result = array(
					'project_name'				=> $row['project_name'],
527
					'project_id'				=> $row['project_id'],
528
529
530
					'run_name'					=> $row['run_name'],
					'run_id'					=> $row['run_id'],
					'directory'					=> $row['analyze_directory'],
531
532
					'name' 						=> $row['analyze_name'],
					'date'						=> $row['analyze_date'],
533
534
					'description' 				=> $row['analyze_description']
				);
535
536
537
538
			}
			return $result;
		}
    }
539

540
541
542
543
544
545
546

	/*
	 * User functions
	 *------------------------------------------------------------*/

    /**
    * Return the supergroups list of the specified group
547
    *
548
549
    * @param string	$group	the group
    * @return array
550
    */
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
	function get_super_groups_of ($group) {
		// First get the super group of the given group
		$queryParts = array(
			'SELECT' => 'uid, subgroup',
			'FROM' => 'fe_groups',
			'WHERE' => '',
			'GROUPBY' => '',
			'ORDERBY' => '',
			'LIMIT' => ''
		);
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		$reslist = array();
		$i = 0;
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
			if (in_array($group, t3lib_div::intExplode(',',$row['subgroup']))) {
				$reslist[$i] = $row['uid'];
				$i++;
			}
		}
		return $reslist;
	}
572

573
574
	/**
	 * Returns a string with user groups separated by comas
575
	 *
576
577
578
579
580
581
582
583
     * @param	string	$user_group	the user group
	 * @return	string	list of user groups splited by a coma
	 */
	function get_user_groups($user_group) {
		$tab_groups = array();
		tx_nG6_db::get_sub_groups($user_group, '', $tab_groups);
		$groups = '';
		foreach($tab_groups as $valeur) { $groups .= $valeur.','; }
584
		return substr($groups, 0, -1);
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
	}

	/**
	 * Fetches subgroups of groups. Function is called recursively for each subgroup.
	 * Function was previously copied from t3lib_userAuthGroup->fetchGroups and has been slightly modified.
	 *
	 * @param	string	$grList	commalist of fe_groups uid numbers
	 * @param	string	$idList	list of already processed fe_groups-uids so the function will not fall into a eternal recursion.
	 * @return	array
	 */
	function get_sub_groups($grList, $idList='', &$groups)	{

		// Fetching records of the groups in $grList (which are not blocked by lockedToDomain either):
		$lockToDomain_SQL = ' AND (lockToDomain=\'\' OR lockToDomain IS NULL)';
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,subgroup', 'fe_groups', 'deleted=0 AND hidden=0 AND uid IN ('.$grList.')'.$lockToDomain_SQL);

		$groupRows = array();	// Internal group record storage
		// The groups array is filled
		while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
			if(!in_array($row['uid'], $groups))	{ $groups[] = $row['uid']; }
			$groupRows[$row['uid']] = $row;
		}

		// Traversing records in the correct order
		$include_staticArr = t3lib_div::intExplode(',', $grList);
		foreach($include_staticArr as $uid)	{	// traversing list
			// Get row:
			$row=$groupRows[$uid];
			if (is_array($row) && !t3lib_div::inList($idList,$uid))	{	// Must be an array and $uid should not be in the idList, because then it is somewhere previously in the grouplist
				// Include sub groups
				if (trim($row['subgroup']))	{
					$theList = implode(',',t3lib_div::intExplode(',',$row['subgroup']));	// Make integer list
					tx_nG6_db::get_sub_groups($theList, $idList.','.$uid, $groups);		// Call recursively, pass along list of already processed groups so they are not recursed again.
				}
			}
		}
	}
622

623
624
625
626
627
628
629
630
631
632
633
634
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
671
672
673
674
	/**
	 * Return if the user is authorized or not to access the specified project and run
	 *
	 * @param	string	$user_group	the user group
	 * @param	string	$project_id	the project id
	 * @param	string	$project_id	the run id
	 * @return	boolean
	 */
	function user_is_authorized ($user_group, $project_id, $run_id) {
		if ($project_id) {
			$queryParts = array(
				'SELECT' => 'fe_group',
				'FROM' => 'tx_nG6_project',
				'WHERE' => 'uid='.$project_id,
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
			$authorized_group = $val['fe_group'];
		} elseif ($run_id) {
			$queryParts = array(
				'SELECT' => 'project_id',
				'FROM' => 'tx_nG6_project_run',
				'WHERE' => 'run_id='.$run_id,
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res1 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res1);
			$queryParts = array(
				'SELECT' => 'fe_group',
				'FROM' => 'tx_nG6_project',
				'WHERE' => 'uid='.$val['project_id'],
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res2 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
			$authorized_group = $val['fe_group'];
		} else {
			return true;
		}
		if (!$GLOBALS['TSFE']->loginUser) { // If the user is not logged on
			return $authorized_group == 0;
		} else {
			return in_array($authorized_group, preg_split("/,/", tx_nG6_db::get_user_groups($user_group)));
		}
	}
675

676
677
678
679
680
681
682
683

}

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

?>