class.tx_nG6_pi1.php 28.1 KB
Newer Older
Jerome Mariette's avatar
Jerome Mariette 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
30
31
32
<?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!
***************************************************************/
/**
 * Plugin 'nG6' for the 'nG6' extension.
 *
 * @author	PF bioinformatique de Toulouse <>
 */

require_once(PATH_tslib.'class.tslib_pibase.php');

class tx_nG6_pi1 extends tslib_pibase {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
33
	
Jerome Mariette's avatar
Jerome Mariette committed
34
35
36
37
38
39
40
41
42
43
44
45
	var $prefixId = 'tx_nG6_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.tx_nG6_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey = 'nG6';	// The extension key.
	
	/**
	 * Main method of your PlugIn
	 *
	 * @param	string		$content: The content of the PlugIn
	 * @param	array		$conf: The PlugIn Configuration
	 * @return	The content that should be displayed on the website
	 */
	function main($content,$conf)	{
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
46
		
Jerome Mariette's avatar
Jerome Mariette committed
47
48
49
		if (strstr($this->cObj->currentRecord,'tt_content'))	{
			$conf['pidList'] = $this->cObj->data['pages'];
		}
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
50
51
52
53
54
		$this->conf=$conf;		// Setting the TypoScript passed to this function in $this->conf
		$this->pi_setPiVarDefaults();
		$this->pi_USER_INT_obj=1;	// Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
		$this->pi_loadLL();		// Loading the LOCAL_LANG values

Jerome Mariette's avatar
Jerome Mariette committed
55
		if ($this->userIsAuthorized()) {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
56
			switch((string)$this->conf['view'])	{
Jerome Mariette's avatar
Jerome Mariette committed
57
58
				case 'project':
					if ($this->piVars['analyze_id']) {
Jerome Mariette's avatar
Jerome Mariette committed
59
						return $this->pi_wrapInBaseClass($this->pi_analyze_view('analyze'));
Jerome Mariette's avatar
Jerome Mariette committed
60
					} elseif ($this->piVars['project_id'] && $this->piVars['run_id']) {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
61
						return $this->pi_wrapInBaseClass($this->pi_run_view());
Jerome Mariette's avatar
Jerome Mariette committed
62
					} else {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
63
						return $this->pi_wrapInBaseClass($this->pi_project_view());
Jerome Mariette's avatar
Jerome Mariette committed
64
65
66
67
					}
					break;
				case 'run':
					if ($this->piVars['analyze_id']) {
Jerome Mariette's avatar
Jerome Mariette committed
68
						return $this->pi_wrapInBaseClass($this->pi_analyze_view('analyze'));
Jerome Mariette's avatar
Jerome Mariette committed
69
					} else {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
70
						return $this->pi_wrapInBaseClass($this->pi_run_view());
Jerome Mariette's avatar
Jerome Mariette committed
71
72
73
					}
				break;
				default:
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
74
					return $this->pi_wrapInBaseClass($this->pi_project_view());
Jerome Mariette's avatar
Jerome Mariette committed
75
76
77
78
79
80
81
82
83
84
85
86
				break;
			}
		} else {
			return $this->pi_wrapInBaseClass($this->getFieldHeader('not_authorized'));
		}
	}
		
	/**
	 * Shows a list of database entries
	 *
	 * @return	HTML list of table entries
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
87
88
89
	function pi_project_view()	{

		if ($this->piVars['project_id'])	{ // If a single element should be displayed
Jerome Mariette's avatar
Jerome Mariette committed
90
91
92
93
94
95
96
97
98
99
			$queryParts = array(
				'SELECT' => '*',
				'FROM' => 'tx_nG6_project',
				'WHERE' => 'tx_nG6_project.uid = '.$this->piVars['project_id'],
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
100
			return $this->pi_project_single_view();
Jerome Mariette's avatar
Jerome Mariette committed
101
		} else {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
102
103
			// If the user is not logged on display demonstration project
			if (!$GLOBALS['TSFE']->loginUser) { 
Jerome Mariette's avatar
Jerome Mariette committed
104
				$where = 'fe_group=0';
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
105
			} else {
Jerome Mariette's avatar
Jerome Mariette committed
106
				$where = 'fe_group IN ('.$this->getCurrentUserGroups().')';	
Jerome Mariette's avatar
Jerome Mariette committed
107
			}
Jerome Mariette's avatar
Jerome Mariette committed
108
109
110
111
112
113
114
115
116
			$queryParts = array(
				'SELECT' => '*',
				'FROM' => 'tx_nG6_project',
				'WHERE' => $where,
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
117
118
			// If there is at least one result
			if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
Jerome Mariette's avatar
Jerome Mariette committed
119
				return $this->pi_project_list_view($res);
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
120
			} else { // If no results
Jerome Mariette's avatar
Jerome Mariette committed
121
				return $this->getFieldHeader('no_raw');
122
			}
Jerome Mariette's avatar
Jerome Mariette committed
123
124
125
126
127
		}
	}

	/**
	 * Creates a list from a database query
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
128
	 * 
Jerome Mariette's avatar
Jerome Mariette committed
129
130
131
132
	 * @param	ressource	$res: A database result ressource
	 * @return	A HTML list if result items
	 */
	function pi_project_list_view($res)	{
133
		$nb_project = 0;
Jerome Mariette's avatar
Jerome Mariette committed
134
135
136
137
138
		$content = '<table'.$this->pi_classParam('listrow').'>
						<tr>
							<th>'.$this->getFieldHeader('project_name').'</th>
							<th>'.$this->getFieldHeader('description').'</th>
						</tr>';
139
140
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
		while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
			if ($this->internal['currentRow']['hidden'] == 0) { // If it's not a hidden project
				$content .= '<tr>
					<td>'.$this->getFieldContent('name', array('project_id'=>$this->internal['currentRow']['uid'])).'</td>
					<td>'.$this->getFieldContent('description').'</td>
					</tr>';
				$nb_project++;
			} else {
				$user_groups = t3lib_div::intExplode(',',$this->getCurrentUserGroups());
				$user_allowed = false;
			    foreach($this->getSuperGroupsOf($this->internal['currentRow']['fe_group']) AS $valeur) {
					if (in_array($valeur, $user_groups)) {
						$user_allowed = true;
						$nb_project++;
					}
			    }
			    if ($user_allowed) {
					$content .= '<tr>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('name', array('project_id'=>$this->internal['currentRow']['uid'])).'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('description').'</td>
						</tr>';
			    }
			}
		}
		if ($nb_project > 0) {
			return $content .= '</table>';
		} else {
			return $this->getFieldHeader('no_raw');
Jerome Mariette's avatar
Jerome Mariette committed
167
168
169
170
171
		}
	}

	/**
	 * Display a single item from the database
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
172
	 * 
Jerome Mariette's avatar
Jerome Mariette committed
173
174
	 * @return	HTML of a single database entry
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
175
	function pi_project_single_view()	{
Jerome Mariette's avatar
Jerome Mariette committed
176
177
178
		$content = '<div'.$this->pi_classParam('singleView').'>
			         <h2>Projet '.$this->internal['currentRow']['name'].' :</h2>
				     <p><strong>'.$this->getFieldContent('description').'</strong></p>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
179
180
		             </div>'.$this->pi_getEditPanel().$this->pi_run_view($content, $this->conf, $this->internal['currentRow']['uid']);
		$content .= $this->pi_analyze_view('project');
Jerome Mariette's avatar
Jerome Mariette committed
181
182
		return $content;
	}
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
183

Jerome Mariette's avatar
Jerome Mariette committed
184
185
186
187
188
	/**
	 * Shows a list of database entries
	 *
	 * @return	HTML list of table entries
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
189
190
191
192
    function pi_run_view() {
		if ($this->piVars['run_id'])    {       // If a single element should be displayed:
			$queryParts = array(
				'SELECT' => 'tx_nG6_run.uid AS run_id, tx_nG6_run.name AS name, tx_nG6_project.name AS project_name,' .
Jerome Mariette's avatar
Jerome Mariette committed
193
							'tx_nG6_run.date AS date, tx_nG6_run.species AS run_species, tx_nG6_run.data_nature AS run_data_nature,' .
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
194
195
							'tx_nG6_run.type AS run_type, tx_nG6_run.nb_sequences AS run_nb_sequences, tx_nG6_run.full_seq_size AS run_full_seq_size,' .
							'tx_nG6_run.description AS run_description, tx_nG6_run.sequencer AS run_sequencer,' .
196
197
							'tx_nG6_run.directory AS run_directory, tx_nG6_run.hidden AS run_hidden, tx_nG6_project.name AS project_name,' .
							'tx_nG6_project.fe_group AS project_fe_group',
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
198
199
200
201
202
203
204
205
206
207
208
209
				'FROM' => 'tx_nG6_run INNER JOIN (tx_nG6_project_run INNER JOIN tx_nG6_project ON tx_nG6_project_run.project_id=tx_nG6_project.uid)' .
						  'ON tx_nG6_run.uid=tx_nG6_project_run.run_id',
                'WHERE' => 'tx_nG6_run.uid='.$this->piVars['run_id'],
                'GROUPBY' => '',
                'ORDERBY' => '',
                'LIMIT' => ''
            );
            $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
            $this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
			return $this->pi_run_single_view();
		} else {           
			// First off, build the rigth sql request
Jerome Mariette's avatar
Jerome Mariette committed
210
			if ($this->piVars['project_id']) {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
211
212
				$where = 'tx_nG6_project_run.project_id='.$this->piVars['project_id'];

Jerome Mariette's avatar
Jerome Mariette committed
213
214
			} else {
				if (!$GLOBALS['TSFE']->loginUser) { // If the user is not logged on
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
215
216
217
218
219
220
221
222
					$where = 'project_id IN ('.$GLOBALS['TYPO3_DB']->SELECTquery('uid', 'tx_nG6_project', 'fe_group=0').')';
                } else {
                	$where = 'project_id IN ('.$GLOBALS['TYPO3_DB']->SELECTquery('uid', 'tx_nG6_project', 'fe_group IN('.$this->getCurrentUserGroups().')').')';
                }
            }
            // Then execute it
			$queryParts = array(
				'SELECT' => 'tx_nG6_run.uid AS run_id, tx_nG6_run.name AS name, tx_nG6_project.name AS project_name,' .
Jerome Mariette's avatar
Jerome Mariette committed
223
							'tx_nG6_run.date AS date, tx_nG6_run.species AS run_species, tx_nG6_run.data_nature AS run_data_nature,' .
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
224
							'tx_nG6_run.type AS run_type, tx_nG6_run.nb_sequences AS run_nb_sequences, tx_nG6_run.full_seq_size AS run_full_seq_size,' .
225
226
							'tx_nG6_run.description AS run_description, tx_nG6_run.sequencer AS run_sequencer, tx_nG6_run.hidden AS run_hidden,' .
							'tx_nG6_project.name AS project_name, tx_nG6_project.fe_group AS project_fe_group',
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
227
228
229
230
				'FROM' => 'tx_nG6_run INNER JOIN (tx_nG6_project_run INNER JOIN tx_nG6_project ON tx_nG6_project_run.project_id=tx_nG6_project.uid)' .
						  'ON tx_nG6_run.uid=tx_nG6_project_run.run_id',
                'WHERE' => $where,
                'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
231
                'ORDERBY' => 'tx_nG6_run.date DESC',
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
232
233
234
235
236
237
238
239
240
241
242
243
                'LIMIT' => ''
            );
            $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
            
            if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) { // There is some results to display
            	return $this->pi_run_list_view($res);
            } else { // no results
                return $this->getFieldHeader('no_raw');
            }
       }
    }

Jerome Mariette's avatar
Jerome Mariette committed
244
245
246
247
248
249
250
	/**
	 * Creates a list from a database query
	 *
	 * @param	ressource	$res: A database result ressource
	 * @return	A HTML list if result items
	 */
	function pi_run_list_view($res)	{
251
		$nb_run = 0;
Jerome Mariette's avatar
Jerome Mariette committed
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
		if ($this->piVars['project_id']) {
			$content = '<br /> <h3> '.$this->getFieldHeader('runs_done').'</h3> <br />';
		}
		$content .= '<table'.$this->pi_classParam('listrow').'>
						<tr>
							<th>'.$this->getFieldHeader('run_name').'</td>
							<th>'.$this->getFieldHeader('project_name').'</td>
							<th>'.$this->getFieldHeader('date').'</td>
							<th>'.$this->getFieldHeader('species').'</td>
							<th>'.$this->getFieldHeader('data_nature').'</td>
							<th>'.$this->getFieldHeader('type').'</td>
							<th>'.$this->getFieldHeader('nb_sequences').'</td>
							<th>'.$this->getFieldHeader('full_seq_size').'</td>
							<th>'.$this->getFieldHeader('description').'</td>
							<th>'.$this->getFieldHeader('sequencer').'</td>
						</tr>';
		while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
269
270
271
272
			if ($this->internal['currentRow']['run_hidden'] == 0) { // If it's not a hidden run
				$content .= '<tr>
					<td>'.$this->getFieldContent('name', array('run_id'=>$this->internal['currentRow']['run_id'], 'project_id'=>$this->piVars['project_id'])).'</td>
					<td>'.$this->getFieldContent('project_name').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
273
					<td>'.$this->getFieldContent('date').'</td>
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
					<td>'.$this->getFieldContent('run_species').'</td>
					<td>'.$this->getFieldContent('run_data_nature').'</td>
					<td>'.$this->getFieldContent('run_type').'</td>
					<td>'.$this->getFieldContent('run_nb_sequences').'</td>
					<td>'.$this->getFieldContent('run_full_seq_size').'</td>
					<td>'.$this->getFieldContent('run_description').'</td>
					<td>'.$this->getFieldContent('run_sequencer').'</td>
					</tr>';
				$nb_run++;
			} else {
				$user_groups = t3lib_div::intExplode(',',$this->getCurrentUserGroups());
				$user_allowed = false;
			    foreach($this->getSuperGroupsOf($this->internal['currentRow']['project_fe_group']) AS $valeur) {
					if (in_array($valeur, $user_groups)) {
						$user_allowed = true;
						$nb_run++;
					}
			    }
			    if ($user_allowed) {
					$content .= '<tr>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('name', array('run_id'=>$this->internal['currentRow']['run_id'], 'project_id'=>$this->piVars['project_id'])).'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('project_name').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
296
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('date').'</td>
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_species').'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_data_nature').'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_type').'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_nb_sequences').'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_full_seq_size').'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_description').'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_sequencer').'</td>
						</tr>';
			    }
			}
		}
		if ($nb_run > 0) {
			return $content .= '</table>';
		} else {
			return '';
Jerome Mariette's avatar
Jerome Mariette committed
312
313
314
315
316
		}
	}

	/**
	 * Display a single item from the database
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
317
318
	 * 
	 * @param	ressource	$res: A database result ressource
Jerome Mariette's avatar
Jerome Mariette committed
319
320
	 * @return	HTML of a single database entry
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
321
	function pi_run_single_view() {
Jerome Mariette's avatar
Jerome Mariette committed
322
		$content = '<div'.$this->pi_classParam('singleView').'><h2>Run '.$this->internal['currentRow']['name'].' :</h2>';
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
323
		$content .= '<p><strong>'.$this->getFieldContent('run_description').'</strong></p> </div>
Jerome Mariette's avatar
Jerome Mariette committed
324
325
326
				<table'.$this->pi_classParam('listrow').'>
					<tr>
						<th align="left">'.$this->getFieldHeader('project_name').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
327
						<td align="left">'.$this->getFieldContent('project_name').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
328
329
330
					</tr>	
					<tr>
						<th align="left">'.$this->getFieldHeader('date').' :</th>
Jerome Mariette's avatar
Jerome Mariette committed
331
						<td align="left">'.$this->getFieldContent('date').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
332
333
334
					</tr>					
					<tr>
						<th align="left">'.$this->getFieldHeader('species').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
335
						<td align="left">'.$this->getFieldContent('run_species').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
336
337
338
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('type').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
339
						<td align="left">'.$this->getFieldContent('run_type').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
340
341
342
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('data_nature').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
343
						<td align="left">'.$this->getFieldContent('run_data_nature').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
344
345
346
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('nb_sequences').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
347
						<td align="left">'.$this->getFieldContent('run_nb_sequences').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
348
349
350
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('full_seq_size').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
351
						<td align="left">'.$this->getFieldContent('run_full_seq_size').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
352
353
354
					</tr>						
					<tr>
						<th align="left">'.$this->getFieldHeader('sequencer').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
355
						<td align="left">'.$this->getFieldContent('run_sequencer').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
356
357
358
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('downloads').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
359
						<td align="left">'.$this->get_downloads_list().'</td>
Jerome Mariette's avatar
Jerome Mariette committed
360
361
					</tr>
				</table>';
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
362
		$content .= $this->pi_analyze_view('run');
Jerome Mariette's avatar
Jerome Mariette committed
363
364
365
366
367
368
369
370
371
		return $content.$this->pi_getEditPanel();
	}
	
	/**
	 * Shows a list of database entries
	 *
	 * @param	string		$type: What kind of analyze is it : run or project
	 * 	 * @return	HTML list of table entries
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
372
	function pi_analyze_view($type)	{
Jerome Mariette's avatar
Jerome Mariette committed
373
374
375
376
377
378
379
380
381
382
383
		if ($type == 'analyze')	{	// If a single element should be displayed:
			$queryParts = array(
				'SELECT' => '*',
				'FROM' => 'tx_nG6_analyze',
				'WHERE' => 'tx_nG6_analyze.uid = '.$this->piVars['analyze_id'],
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
384
			return $this->pi_analyze_single_view();
Jerome Mariette's avatar
Jerome Mariette committed
385
386
387
388
		} else {
			if ($type == 'run') {
				// Selects Analyzis done on this run
				$queryParts = array(
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
389
					'SELECT' => 'tx_nG6_analyze.uid AS uid, tx_nG6_analyze.name AS name, tx_nG6_analyze.description AS description,' .
390
391
392
393
394
395
396
								'tx_nG6_analyze.software AS software, tx_nG6_analyze.version AS version, tx_nG6_analyze.hidden AS hidden,' .
								'tx_nG6_project.fe_group AS project_fe_group',
					'FROM' => 'tx_nG6_analyze INNER JOIN (tx_nG6_run_analyze INNER JOIN ( tx_nG6_run INNER JOIN ( tx_nG6_project_run INNER JOIN tx_nG6_project ' .
							  'ON tx_nG6_project_run.project_id=tx_nG6_project.uid ) ' .
							  'ON tx_nG6_run.uid=tx_nG6_project_run.run_id ) ' .
							  'ON tx_nG6_run.uid=tx_nG6_run_analyze.run_id ) ' .
							  'ON tx_nG6_analyze.uid=tx_nG6_run_analyze.analyze_id ',
Jerome Mariette's avatar
Jerome Mariette committed
397
398
					'WHERE' => 'tx_nG6_run_analyze.run_id = '.$this->piVars['run_id'],
					'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
399
					'ORDERBY' => 'tx_nG6_analyze.name',
Jerome Mariette's avatar
Jerome Mariette committed
400
401
402
403
404
					'LIMIT' => ''
				);
			} elseif ($type == 'project') {
				// Selects Analyzis done on this project
				$queryParts = array(
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
405
					'SELECT' => 'tx_nG6_analyze.uid AS uid, tx_nG6_analyze.name AS name, tx_nG6_analyze.description AS description,' .
406
407
408
409
								'tx_nG6_analyze.software AS software, tx_nG6_analyze.version AS version, tx_nG6_analyze.hidden AS hidden,' .
								'tx_nG6_project.fe_group AS project_fe_group',
					'FROM' => 'tx_nG6_analyze INNER JOIN ( tx_nG6_project_analyze INNER JOIN tx_nG6_project ON tx_nG6_project.uid=tx_nG6_project_analyze.project_id ) ' .
							  'ON tx_nG6_analyze.uid=tx_nG6_project_analyze.analyze_id',
Jerome Mariette's avatar
Jerome Mariette committed
410
411
					'WHERE' => 'tx_nG6_project_analyze.project_id = '.$this->piVars['project_id'],
					'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
412
					'ORDERBY' => 'tx_nG6_analyze.name',
Jerome Mariette's avatar
Jerome Mariette committed
413
414
					'LIMIT' => ''
				);
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
415
			}	
Jerome Mariette's avatar
Jerome Mariette committed
416
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
417
			$content='';
Jerome Mariette's avatar
Jerome Mariette committed
418
			if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
419
				$content.=$this->pi_analyze_list_view($res);
Jerome Mariette's avatar
Jerome Mariette committed
420
			}
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
421
			return $content;
Jerome Mariette's avatar
Jerome Mariette committed
422
423
424
425
426
427
428
429
430
431
		}
	}

	/**
	 * Creates a list from a database query
	 *
	 * @param	ressource	$res: A database result ressource
	 * @return	A HTML list if result items
	 */
	function pi_analyze_list_view($res)	{
432
		$nb_analyse = 0;
Jerome Mariette's avatar
Jerome Mariette committed
433
434
435
436
437
438
439
440
441
		$content.='<br /> <h3> '.$this->getFieldHeader('analyzes_done').'</h3> <br />
				<table'.$this->pi_classParam('listrow').'>
					<tr>
						<th>'.$this->getFieldHeader('name').'</td>
						<th>'.$this->getFieldHeader('description').'</td>
						<th>'.$this->getFieldHeader('software').'</td>
						<th>'.$this->getFieldHeader('version').'</td>
					</tr>';
		while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
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
			if ($this->internal['currentRow']['hidden'] == 0) { // If it's not a hidden project
				$content .= '<tr>
					<td>'.$this->getFieldContent('name', array('analyze_id'=>$this->internal['currentRow']['uid'], 'run_id'=>$this->piVars['run_id'], 'project_id'=>$this->piVars['project_id'])).'</td>
					<td>'.$this->getFieldContent('description').'</td>
					<td>'.$this->getFieldContent('software').'</td>
					<td>'.$this->getFieldContent('version').'</td>
					</tr>';
				$nb_analyse++;
			} else {
				$user_groups = t3lib_div::intExplode(',',$this->getCurrentUserGroups());
				$user_allowed = false;
			    foreach($this->getSuperGroupsOf($this->internal['currentRow']['project_fe_group']) AS $valeur) {
					if (in_array($valeur, $user_groups)) {
						$user_allowed = true;
						$nb_analyse++;
					}
			    }
			    if ($user_allowed) {
					$content .= '<tr>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('name', array('analyze_id'=>$this->internal['currentRow']['uid'], 'run_id'=>$this->piVars['run_id'], 'project_id'=>$this->piVars['project_id'])).'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('description').'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('software').'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('version').'</td>
						</tr>';
			    }
			}
Jerome Mariette's avatar
Jerome Mariette committed
468
		}
469
470
471
472
473
		if ($nb_analyse > 0) {
			return $content .= '</table>';
		} else {
			return '';
		}		
Jerome Mariette's avatar
Jerome Mariette committed
474
475
	}

Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
476

Jerome Mariette's avatar
Jerome Mariette committed
477
478
479
480
481
	/**
	 * Display a single item from the database
	 *
	 * @return	HTML of a single database entry
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
482
	function pi_analyze_single_view() {
Jerome Mariette's avatar
Jerome Mariette committed
483
		$content = '<div'.$this->pi_classParam('singleView').'><h2>Analyse '.$this->internal['currentRow']['name'].' : <span>'.$this->getFieldContent('description').'</span></h2></div>';
Jerome Mariette's avatar
Jerome Mariette committed
484
		if (file_exists($this->conf['data'].$this->internal['currentRow']['directory'].'/index.html' )) {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
485
			$fp = fopen((string)$this->conf['data'].$this->internal['currentRow']['directory'].'/index.html',"r"); //lecture du fichier
Jerome Mariette's avatar
Jerome Mariette committed
486
487
488
489
			while (!feof($fp)) { //on parcourt toutes les lignes
				$content .= fgets($fp, 4096); // lecture du contenu de la ligne
			}
		}
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
490
		else {
Jerome Mariette's avatar
Jerome Mariette committed
491
			$content .= $this->getFieldHeader('not_synchro');
Jerome Mariette's avatar
Jerome Mariette committed
492
493
494
495
496
497
498
499
500
501
502
503
504
		}
		return $content;
	}
	
	/**
	 * Returns the content of a given field
	 *
	 * @param	string		$fN: name of table field
	 * @return	Value of the field
	 */
	function getFieldContent($fN, $mergeArr=array())	{
		switch($fN) {
			case 'uid':
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
505
				return $this->pi_list_linkSingle($this->internal['currentRow'][$fN],$this->internal['currentRow']['uid'],1, $mergeArr);	
Jerome Mariette's avatar
Jerome Mariette committed
506
507
			break;
			case 'name':
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
508
				return $this->pi_list_linkSingle($this->internal['currentRow'][$fN],$this->internal['currentRow']['uid'],1, $mergeArr);	
Jerome Mariette's avatar
Jerome Mariette committed
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
			break;
			case 'date':
					// %A %e. %B %Y
				return strftime('%d-%m-%y',$this->internal['currentRow']['date']);
			break;			
			default:
				return $this->internal['currentRow'][$fN];
			break;
		}
	}
	/**
	 * Returns the label for a fieldname from local language array
	 *
	 * @param	[type]		$fN: ...
	 * @return	[type]		...
	 */
	function getFieldHeader($fN)	{
		switch($fN) {
			
			default:
				return $this->pi_getLL('listFieldHeader_'.$fN,'['.$fN.']');
			break;
		}
	}
	
	/**
	 * Returns a sorting link for a column header
	 *
	 * @param	string		$fN: Fieldname
	 * @return	The fieldlabel wrapped in link that contains sorting vars
	 */
	function getFieldHeader_sortLink($fN)	{
		return $this->pi_linkTP_keepPIvars($this->getFieldHeader($fN),array('sort'=>$fN.':'.($this->internal['descFlag']?0:1)));
	}
	
	/**
	 * Overloading of the tslib_pibase->pi_list_linkSingle function so piVars[showUid] is not set.
	 * Uses pi_linkTP for the linking
	 *
	 * @param	string		The content string to wrap in <a> tags
	 * @param	integer		UID of the record for which to display details (basically this will become the value of [showUid]
	 * @param	boolean		See pi_linkTP_keepPIvars
	 * @param	array		Array of values to override in the current piVars. Same as $overrulePIvars in pi_linkTP_keepPIvars
	 * @param	boolean		If true, only the URL is returned, not a full link
	 * @param	integer		Alternative page ID for the link. (By default this function links to the SAME page!)
	 * @return	string		The input string wrapped in <a> tags
	 * @see pi_linkTP(), pi_linkTP_keepPIvars()
	 */
	function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0)	{
		if ($this->prefixId)	{
			if ($cache)	{
				$overrulePIvars=(array)$mergeArr;
				$str = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
			} else {
				$overrulePIvars=(array)$mergeArr;
				$str = $this->pi_linkTP_keepPIvars($str,$overrulePIvars,$cache,0,$altPageId);
			}

				// If urlOnly flag, return only URL as it has recently be generated.
			if ($urlOnly)	{
				$str = $this->cObj->lastTypoLinkUrl;
			}
		}
		return $str;
	}
	
	/**
	 * Display a list of downloadable file
	 *
	 * @return	HTML of a list of downlabale links
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
580
581
	function get_downloads_list() {
		$directory = (string)$this->conf['data'].$this->internal['currentRow']['run_directory'];
Jerome Mariette's avatar
Jerome Mariette committed
582
583
584
585
586
587
		try {
			if (!is_dir($directory)) { throw new Exception('Error when attempting to open the data folder !'); }
			$my_directory = opendir($directory) or die('Error when attempting to open the data folder !');
			$download = '<p '.$this->pi_classParam('downloads').'><ul>';
			while($entry = @readdir($my_directory)) {
				if(!is_dir($directory.'/'.$entry)&& $entry != '.' && $entry != '..' && !$this->endsWith($entry, ".cfg")) {
Jerome Mariette's avatar
Jerome Mariette committed
588
					$link = 'fileadmin/'.$this->internal['currentRow']['run_directory'].'/'.$entry;
Jerome Mariette's avatar
Jerome Mariette committed
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
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
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
					$download .= '<li><a href="'.$link.'" target="_blank">'.$entry.'</a></li>';
				}
			}
			$download .= '</ul>';		
			closedir($my_directory);
			return $download;
		}
		catch (Exception $e) {
			return $this->getFieldHeader('not_synchro');
		}
	}
	
	// return true if $str ends with $sub
	function endsWith( $str, $sub ) {
		return ( substr( $str, strlen( $str ) - strlen( $sub ) ) == $sub );
	}
	
	function getCurrentUserGroups() {
		$tab_groups = array();
		$this->getSubGroups($GLOBALS['TSFE']->fe_user->user['usergroup'], '', $tab_groups);
		$groups = '';
		foreach($tab_groups as $valeur) { $groups .= $valeur.','; }
		return substr($groups, 0, -1);	
	}

	/**
	 * 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		Commalist of fe_groups uid numbers
	 * @param	string		List of already processed fe_groups-uids so the function will not fall into a eternal recursion.
	 * @return	array
	 * @access private
	 */
	function getSubGroups($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 OR lockToDomain=\''.$this->authInfo['HTTP_HOST'].'\')';
		if (!$this->authInfo['showHiddenRecords'])	$hiddenP = 'AND hidden=0 ';
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,subgroup', 'fe_groups', 'deleted=0 '.$hiddenP.' 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
					$this->getSubGroups($theList, $idList.','.$uid, $groups);		// Call recursively, pass along list of already processed groups so they are not recursed again.
				}
			}
		}
	}
	
	function userIsAuthorized () {
		if ($this->piVars['project_id']) {
			$queryParts = array(
				'SELECT' => 'fe_group',
				'FROM' => 'tx_nG6_project',
				'WHERE' => 'uid='.$this->piVars['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 ($this->piVars['run_id']) {
			$queryParts = array(
				'SELECT' => 'project_id',
				'FROM' => 'tx_nG6_project_run',
				'WHERE' => 'run_id='.$this->piVars['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, split(",", $this->getCurrentUserGroups()));
		}
	}
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
	
	function getSuperGroupsOf ($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;
	}
	
	
	
Jerome Mariette's avatar
Jerome Mariette committed
724
725
726
727
728
729
730
731
732
733
		
}



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

?>