class.tx_nG6_pi1.php 33.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
<?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');
31
32
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_db.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_utils.php');
Jerome Mariette's avatar
Jerome Mariette committed
33
34

class tx_nG6_pi1 extends tslib_pibase {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
35
	
Jerome Mariette's avatar
Jerome Mariette committed
36
37
38
39
40
41
42
43
44
45
46
47
	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
48
		
Jerome Mariette's avatar
Jerome Mariette committed
49
50
51
		if (strstr($this->cObj->currentRecord,'tt_content'))	{
			$conf['pidList'] = $this->cObj->data['pages'];
		}
52
53
54
		$this->conf=$conf;		// Setting the TypoScript passed to this function in $this->conf		
		$this->internal['results_at_a_time'] = $conf["results_at_a_time"];
		
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
55
56
57
		$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
58
59

		if (tx_nG6_db::user_is_authorized($GLOBALS['TSFE']->fe_user->user['usergroup'], $this->piVars['project_id'], $this->piVars['run_id'])) {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
60
			switch((string)$this->conf['view'])	{
Jerome Mariette's avatar
Jerome Mariette committed
61
62
				case 'project':
					if ($this->piVars['analyze_id']) {
Jerome Mariette's avatar
Jerome Mariette committed
63
						return $this->pi_wrapInBaseClass($this->pi_analyze_view('analyze'));
Jerome Mariette's avatar
Jerome Mariette committed
64
					} elseif ($this->piVars['project_id'] && $this->piVars['run_id']) {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
65
						return $this->pi_wrapInBaseClass($this->pi_run_view());
66
67
					}elseif ($this->piVars['project_id'] && $this->piVars['summary']) {
						return $this->pi_wrapInBaseClass($this->pi_project_summary());
Jerome Mariette's avatar
Jerome Mariette committed
68
					} else {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
69
						return $this->pi_wrapInBaseClass($this->pi_project_view());
Jerome Mariette's avatar
Jerome Mariette committed
70
71
72
73
					}
					break;
				case 'run':
					if ($this->piVars['analyze_id']) {
Jerome Mariette's avatar
Jerome Mariette committed
74
						return $this->pi_wrapInBaseClass($this->pi_analyze_view('analyze'));
Jerome Mariette's avatar
Jerome Mariette committed
75
					} else {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
76
						return $this->pi_wrapInBaseClass($this->pi_run_view());
Jerome Mariette's avatar
Jerome Mariette committed
77
78
79
					}
				break;
				default:
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
80
					return $this->pi_wrapInBaseClass($this->pi_project_view());
Jerome Mariette's avatar
Jerome Mariette committed
81
82
83
84
85
86
				break;
			}
		} else {
			return $this->pi_wrapInBaseClass($this->getFieldHeader('not_authorized'));
		}
	}
87
	
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
	/**
	 * Shows the summary and statistics for a project
	 *
	 * @return	HTML list of table entries
	 */
	function pi_project_summary()	{

			$queryParts = array(
				'SELECT' => 'tx_nG6_run.uid AS run_id, tx_nG6_run.name AS name, tx_nG6_project.name AS project_name,' .
							'tx_nG6_run.date AS date, tx_nG6_run.species AS run_species, tx_nG6_run.data_nature AS run_data_nature,' .
							'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,' .
							'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',
				'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_project.uid = '.$this->piVars['project_id'],
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$content = "Le projet ".$this->piVars['project_id']." contient " . $GLOBALS['TYPO3_DB']->sql_num_rows($res) . " runs.";
			return $content;
	}
113
	
Jerome Mariette's avatar
Jerome Mariette committed
114
115
116
117
118
	/**
	 * Shows a list of database entries
	 *
	 * @return	HTML list of table entries
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
119
120
121
	function pi_project_view()	{

		if ($this->piVars['project_id'])	{ // If a single element should be displayed
122
123

			$this->internal['currentRow'] = tx_nG6_db::select_project($this->piVars['project_id']);
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
124
			return $this->pi_project_single_view();
125

Jerome Mariette's avatar
Jerome Mariette committed
126
		} else {
127
128
129
130
131
132
133
134
135
136
		
			if (isset($this->piVars['project_page']))	//project position 
			{
				$current_page = intval($this->internal['results_at_a_time']) * (intval($this->piVars['project_page']) -1);
				$limit = "$current_page".",". $this->internal['results_at_a_time'] ;
			}
			else
				$limit = '0,'.$this->internal['results_at_a_time'] ; 		
		
		
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
137
138
			// If the user is not logged on display demonstration project
			if (!$GLOBALS['TSFE']->loginUser) { 
Jerome Mariette's avatar
Jerome Mariette committed
139
				$where = 'fe_group=0';
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
140
			} else {
141
				$where = 'fe_group IN ('.tx_nG6_db::get_user_groups($GLOBALS['TSFE']->fe_user->user['usergroup']).')';	
Jerome Mariette's avatar
Jerome Mariette committed
142
			}
Jerome Mariette's avatar
Jerome Mariette committed
143
144
145
146
147
			$queryParts = array(
				'SELECT' => '*',
				'FROM' => 'tx_nG6_project',
				'WHERE' => $where,
				'GROUPBY' => '',
Gerald Salin's avatar
Gerald Salin committed
148
				'ORDERBY' => 'tx_nG6_project.name',
149
				'LIMIT' => $limit
Jerome Mariette's avatar
Jerome Mariette committed
150
151
			);
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
152
153
			// If there is at least one result
			if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
154
				//request total in DB
Jerome Mariette's avatar
Jerome Mariette committed
155
156
157
158
159
				$queryPartsc = array(
					'SELECT' => $queryParts['SELECT'],
					'FROM' => $queryParts['FROM'],
					'WHERE' => $queryParts['WHERE'],
					'GROUPBY' => '',
Gerald Salin's avatar
Gerald Salin committed
160
					'ORDERBY' => $queryParts['ORDERBY'],
Jerome Mariette's avatar
Jerome Mariette committed
161
162
163
164
165
166
167
168
					'LIMIT' => ''
				);
				$resc = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryPartsc);
	         	$total_count = $GLOBALS['TYPO3_DB']->sql_num_rows($resc);
		         //generate HTML   
	         	$project_list= $this->pi_project_list_view($res);
	         	$nav_links = 	$this->pi_navigation_link_view('project_page', $this->piVars['project_page'], $total_count);
         		return $project_list ."\n". $nav_links;			
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
169
			} else { // If no results
Jerome Mariette's avatar
Jerome Mariette committed
170
				return $this->getFieldHeader('no_raw');
171
			}
Jerome Mariette's avatar
Jerome Mariette committed
172
173
174
175
176
		}
	}

	/**
	 * Creates a list from a database query
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
177
	 * 
Jerome Mariette's avatar
Jerome Mariette committed
178
179
180
181
	 * @param	ressource	$res: A database result ressource
	 * @return	A HTML list if result items
	 */
	function pi_project_list_view($res)	{
182
		$nb_project = 0;
Jerome Mariette's avatar
Jerome Mariette committed
183
184
185
186
187
		$content = '<table'.$this->pi_classParam('listrow').'>
						<tr>
							<th>'.$this->getFieldHeader('project_name').'</th>
							<th>'.$this->getFieldHeader('description').'</th>
						</tr>';
188
189
190
191
192
193
194
195
		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 {
196
				$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($GLOBALS['TSFE']->fe_user->user['usergroup']));
197
				$user_allowed = false;
198
			    foreach(tx_nG6_db::get_super_groups_of($this->internal['currentRow']['fe_group']) AS $valeur) {
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
					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
216
217
218
219
220
		}
	}

	/**
	 * Display a single item from the database
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
221
	 * 
Jerome Mariette's avatar
Jerome Mariette committed
222
223
	 * @return	HTML of a single database entry
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
224
	function pi_project_single_view()	{
Jerome Mariette's avatar
Jerome Mariette committed
225
226
227
		$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
228
229
		             </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
230
231
		return $content;
	}
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
232

Jerome Mariette's avatar
Jerome Mariette committed
233
234
235
236
237
	/**
	 * Shows a list of database entries
	 *
	 * @return	HTML list of table entries
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
238
239
    function pi_run_view() {
		if ($this->piVars['run_id'])    {       // If a single element should be displayed:
240
		
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
241
242
			$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
243
							'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
244
245
							'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,' .
246
247
							'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
248
249
250
251
252
253
				'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' => ''
254
255
256
257
            );             
         
         $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
258
			return $this->pi_run_single_view();
259
260
261
262
263
264
265
266
267
268
		} else {        
		
			if (isset($this->piVars['run_page']))	//run position 
			{
				$current_page = intval($this->internal['results_at_a_time']) * (intval($this->piVars['run_page']) -1);
				$limit = "$current_page".",". $this->internal['results_at_a_time'] ;
			}
			else
				$limit = '0,'.$this->internal['results_at_a_time'] ; 
		   
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
269
			// First off, build the rigth sql request
Jerome Mariette's avatar
Jerome Mariette committed
270
			if ($this->piVars['project_id']) {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
271
272
				$where = 'tx_nG6_project_run.project_id='.$this->piVars['project_id'];

Jerome Mariette's avatar
Jerome Mariette committed
273
274
			} else {
				if (!$GLOBALS['TSFE']->loginUser) { // If the user is not logged on
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
275
					$where = 'project_id IN ('.$GLOBALS['TYPO3_DB']->SELECTquery('uid', 'tx_nG6_project', 'fe_group=0').')';
276
            } else {
277
            	$where = 'project_id IN ('.$GLOBALS['TYPO3_DB']->SELECTquery('uid', 'tx_nG6_project', 'fe_group IN('.tx_nG6_db::get_user_groups($GLOBALS['TSFE']->fe_user->user['usergroup']).')').')';
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
278
            }
279
280
         }
         // Then execute it
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
281
282
			$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
283
							'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
284
							'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,' .
285
286
							'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
287
288
289
290
				'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' => '',
Celine Noirot's avatar
Celine Noirot committed
291
                'ORDERBY' => 'tx_nG6_run.date DESC, tx_nG6_run.name ASC',
292
                'LIMIT' => $limit
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
293
            );
294
295
296
         $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);			
         
         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) { // There is some results to display
Jerome Mariette's avatar
Jerome Mariette committed
297
298
299
300
301
302
303
304
305
306
307
			//request total in DB
			$queryPartsc = array(
				'SELECT' => $queryParts['SELECT'],
				'FROM' => $queryParts['FROM'],
				'WHERE' => $queryParts['WHERE'],
                'GROUPBY' => '',
                'ORDERBY' => '',
                'LIMIT' => ''
            );
			$resc = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryPartsc);
         	$total_count = $GLOBALS['TYPO3_DB']->sql_num_rows($resc);
308
309
	         //generate HTML   
         	$run_list= $this->pi_run_list_view($res);
Jerome Mariette's avatar
Jerome Mariette committed
310
311
         	$nav_links = 	$this->pi_navigation_link_view('run_page', $this->piVars['run_page'], $total_count);
     		return $run_list ."\n". $nav_links;
312
313
314
         } else { // no results
             return $this->getFieldHeader('no_raw');
         }
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
315
316
317
       }
    }

Jerome Mariette's avatar
Jerome Mariette committed
318
319
320
321
322
323
	/**
	 * Creates a list from a database query
	 *
	 * @param	ressource	$res: A database result ressource
	 * @return	A HTML list if result items
	 */
324
	function pi_run_list_view($res)	{		
325
		$nb_run = 0;
Jerome Mariette's avatar
Jerome Mariette committed
326
327
328
329
330
		if ($this->piVars['project_id']) {
			$content = '<br /> <h3> '.$this->getFieldHeader('runs_done').'</h3> <br />';
		}
		$content .= '<table'.$this->pi_classParam('listrow').'>
						<tr>
Jerome Mariette's avatar
w3C ok    
Jerome Mariette committed
331
332
333
334
335
336
337
338
339
340
							<th>'.$this->getFieldHeader('run_name').'</th>
							<th>'.$this->getFieldHeader('project_name').'</th>
							<th>'.$this->getFieldHeader('date').'</th>
							<th>'.$this->getFieldHeader('species').'</th>
							<th>'.$this->getFieldHeader('data_nature').'</th>
							<th>'.$this->getFieldHeader('type').'</th>
							<th>'.$this->getFieldHeader('nb_sequences').'</th>
							<th>'.$this->getFieldHeader('full_seq_size').'</th>
							<th>'.$this->getFieldHeader('description').'</th>
							<th>'.$this->getFieldHeader('sequencer').'</th>
Jerome Mariette's avatar
Jerome Mariette committed
341
342
						</tr>';
		while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
343
344
345
346
			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
347
					<td>'.$this->getFieldContent('date').'</td>
348
349
350
					<td>'.$this->getFieldContent('run_species').'</td>
					<td>'.$this->getFieldContent('run_data_nature').'</td>
					<td>'.$this->getFieldContent('run_type').'</td>
351
352
					<td>'.number_format($this->getFieldContent('run_nb_sequences'), 0, ',', ' ').'</td>
					<td>'.number_format($this->getFieldContent('run_full_seq_size'), 0, ',', ' ').'</td>
353
354
355
356
357
					<td>'.$this->getFieldContent('run_description').'</td>
					<td>'.$this->getFieldContent('run_sequencer').'</td>
					</tr>';
				$nb_run++;
			} else {
358
				$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($GLOBALS['TSFE']->fe_user->user['usergroup']));
359
				$user_allowed = false;
360
			   foreach(tx_nG6_db::get_super_groups_of($this->internal['currentRow']['project_fe_group']) AS $valeur) {
361
362
363
364
					if (in_array($valeur, $user_groups)) {
						$user_allowed = true;
						$nb_run++;
					}
365
366
			   }
			   if ($user_allowed) {
367
368
369
					$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
370
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('date').'</td>
371
372
373
						<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>
374
375
						<td '.$this->pi_classParam('hidden').' >'.number_format($this->getFieldContent('run_nb_sequences'), 0, ',', ' ').'</td>
						<td '.$this->pi_classParam('hidden').' >'.number_format($this->getFieldContent('run_full_seq_size'), 0, ',', ' ').'</td>
376
377
378
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_description').'</td>
						<td '.$this->pi_classParam('hidden').' >'.$this->getFieldContent('run_sequencer').'</td>
						</tr>';
379
			   }
380
381
382
			}
		}
		if ($nb_run > 0) {
383
384
			$content .= "\n".'</table>' ; 		
			return $content;
385
386
		} else {
			return '';
Jerome Mariette's avatar
Jerome Mariette committed
387
388
389
390
391
		}
	}

	/**
	 * Display a single item from the database
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
392
393
	 * 
	 * @param	ressource	$res: A database result ressource
Jerome Mariette's avatar
Jerome Mariette committed
394
395
	 * @return	HTML of a single database entry
	 */
396
	function pi_run_single_view() {		
Jerome Mariette's avatar
Jerome Mariette committed
397
		$content = '<div'.$this->pi_classParam('singleView').'><h2>Run '.$this->internal['currentRow']['name'].' :</h2>';
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
398
		$content .= '<p><strong>'.$this->getFieldContent('run_description').'</strong></p> </div>
Jerome Mariette's avatar
Jerome Mariette committed
399
400
401
				<table'.$this->pi_classParam('listrow').'>
					<tr>
						<th align="left">'.$this->getFieldHeader('project_name').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
402
						<td align="left">'.$this->getFieldContent('project_name').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
403
404
405
					</tr>	
					<tr>
						<th align="left">'.$this->getFieldHeader('date').' :</th>
Jerome Mariette's avatar
Jerome Mariette committed
406
						<td align="left">'.$this->getFieldContent('date').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
407
408
409
					</tr>					
					<tr>
						<th align="left">'.$this->getFieldHeader('species').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
410
						<td align="left">'.$this->getFieldContent('run_species').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
411
412
413
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('type').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
414
						<td align="left">'.$this->getFieldContent('run_type').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
415
416
417
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('data_nature').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
418
						<td align="left">'.$this->getFieldContent('run_data_nature').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
419
420
421
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('nb_sequences').' :</th>
422
						<td align="left">'.number_format($this->getFieldContent('run_nb_sequences'), 0, ',', ' ').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
423
424
425
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('full_seq_size').' :</th>
426
						<td align="left">'.number_format($this->getFieldContent('run_full_seq_size'), 0, ',', ' ').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
427
428
429
					</tr>						
					<tr>
						<th align="left">'.$this->getFieldHeader('sequencer').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
430
						<td align="left">'.$this->getFieldContent('run_sequencer').'</td>
Jerome Mariette's avatar
Jerome Mariette committed
431
432
433
					</tr>
					<tr>
						<th align="left">'.$this->getFieldHeader('downloads').' :</th>
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
434
						<td align="left">'.$this->get_downloads_list().'</td>
Jerome Mariette's avatar
Jerome Mariette committed
435
436
					</tr>
				</table>';
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
437
		$content .= $this->pi_analyze_view('run');
438
		
Jerome Mariette's avatar
Jerome Mariette committed
439
440
441
442
443
444
445
446
447
		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
448
	function pi_analyze_view($type)	{
449
		
Jerome Mariette's avatar
Jerome Mariette committed
450
451
452
453
454
455
456
457
458
459
460
		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
461
			return $this->pi_analyze_single_view();
Jerome Mariette's avatar
Jerome Mariette committed
462
		} else {
463
464
465
466
467
468
469
470
471
472
		
			if (isset($this->piVars['analyze_page']))	//run position 
			{
				$current_page = intval($this->internal['results_at_a_time']) * (intval($this->piVars['analyze_page']) -1);
				$limit = "$current_page".",". $this->internal['results_at_a_time'] ;
			}
			else
				$limit = '0,'.$this->internal['results_at_a_time'] ; 	
				
		
Jerome Mariette's avatar
Jerome Mariette committed
473
474
475
			if ($type == 'run') {
				// Selects Analyzis done on this run
				$queryParts = array(
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
476
					'SELECT' => 'tx_nG6_analyze.uid AS uid, tx_nG6_analyze.name AS name, tx_nG6_analyze.description AS description,' .
477
478
479
480
481
482
483
								'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
484
485
					'WHERE' => 'tx_nG6_run_analyze.run_id = '.$this->piVars['run_id'],
					'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
486
					'ORDERBY' => 'tx_nG6_analyze.name',
487
					'LIMIT' => $limit
Jerome Mariette's avatar
Jerome Mariette committed
488
489
490
491
				);
			} elseif ($type == 'project') {
				// Selects Analyzis done on this project
				$queryParts = array(
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
492
					'SELECT' => 'tx_nG6_analyze.uid AS uid, tx_nG6_analyze.name AS name, tx_nG6_analyze.description AS description,' .
493
494
495
496
								'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
497
498
					'WHERE' => 'tx_nG6_project_analyze.project_id = '.$this->piVars['project_id'],
					'GROUPBY' => '',
Jerome Mariette's avatar
Jerome Mariette committed
499
					'ORDERBY' => 'tx_nG6_analyze.name',
500
					'LIMIT' => $limit
Jerome Mariette's avatar
Jerome Mariette committed
501
				);
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
502
			}	
503
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);		
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
504
			$content='';
505
			if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {	
Jerome Mariette's avatar
Jerome Mariette committed
506
507
508
509
510
511
512
513
514
515
516
517
				//request total in DB
				$queryPartsc = array(
					'SELECT' => $queryParts['SELECT'],
					'FROM' => $queryParts['FROM'],
					'WHERE' => $queryParts['WHERE'],
	                'GROUPBY' => '',
	                'ORDERBY' => '',
	                'LIMIT' => ''
	            );
				$resc = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryPartsc);
	         	$total_count = $GLOBALS['TYPO3_DB']->sql_num_rows($resc);
		         //generate HTML   
518
519
520
				$analyze_list=$this->pi_analyze_list_view($res , $total_count);
				$nav_links = $this->pi_navigation_link_view('analyze_page', $this->piVars['analyze_page'], $total_count);
				$content.= $analyze_list ."\n".$nav_links;
Jerome Mariette's avatar
Jerome Mariette committed
521
			}
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
522
			return $content;
Jerome Mariette's avatar
Jerome Mariette committed
523
524
525
526
527
528
529
530
531
532
		}
	}

	/**
	 * 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)	{
533
		$nb_analyse = 0;
Jerome Mariette's avatar
Jerome Mariette committed
534
535
536
		$content.='<br /> <h3> '.$this->getFieldHeader('analyzes_done').'</h3> <br />
				<table'.$this->pi_classParam('listrow').'>
					<tr>
Jerome Mariette's avatar
w3C ok    
Jerome Mariette committed
537
538
539
540
						<th>'.$this->getFieldHeader('name').'</th>
						<th>'.$this->getFieldHeader('description').'</th>
						<th>'.$this->getFieldHeader('software').'</th>
						<th>'.$this->getFieldHeader('version').'</th>
Jerome Mariette's avatar
Jerome Mariette committed
541
542
					</tr>';
		while($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
543
544
545
546
547
548
549
550
551
			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 {
552
				$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($GLOBALS['TSFE']->fe_user->user['usergroup']));
553
				$user_allowed = false;
554
			    foreach(tx_nG6_db::get_super_groups_of($this->internal['currentRow']['project_fe_group']) AS $valeur) {
555
556
557
558
559
560
561
562
563
564
565
566
567
568
					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
569
		}
570
571
572
		if ($nb_analyse > 0) {			
			$content .= "\n".'</table>' ;						
			return $content ;
573
574
575
		} else {
			return '';
		}		
Jerome Mariette's avatar
Jerome Mariette committed
576
577
	}

Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
578

Jerome Mariette's avatar
Jerome Mariette committed
579
580
581
582
583
	/**
	 * Display a single item from the database
	 *
	 * @return	HTML of a single database entry
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
584
	function pi_analyze_single_view() {
585

586
		// add the jquery libs
587
588
589
590
591
592
593
594
		$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] = '
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.ui.core.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.ui.dialog.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.ui.draggable.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.ui.resizable.min.js"></script> 
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.bgiframe.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.url.packed.js"></script>
595
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/tx_nG6_pi1.js"></script>
596
597
598
599
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.core.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.theme.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.dialog.css"/>';

600
601
		$content = '<div id="img_dialog" title=""></div>';
		$content .= '<input type="hidden" id="analyse_name" value="'.$this->internal['currentRow']['name'].'" />';
602
603

		$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
604
		if (file_exists($this->conf['data'].$this->internal['currentRow']['directory'].'/analyse.xml' )) {
Jerome Mariette's avatar
Jerome Mariette committed
605
606
607
608
609
610
611
612
613
614
615
616
617
			$xml = new DomDocument;
			$xml->load($this->conf['data'].$this->internal['currentRow']['directory'].'/analyse.xml');
			
			// Find out the analyse class
            $class = $xml->documentElement;
            $class_value = "";
			foreach ($class->childNodes AS $item) {
                if ($item->nodeName == "class") { $class_value = $item->nodeValue; } 
			}
			// If no class value : xml incorrect
			if ($class_value == "") { 
				$content .= $this->getFieldHeader('uncorrect_xml');
			} else {
Jerome Mariette's avatar
Jerome Mariette committed
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
				
	            $xslt = new XSLTProcessor();
	            $xsl = new DOMDocument();
	            if (file_exists(PATH_typo3conf.ext.'/'.$this->extKey.'/res/xsl/'.$this->LLkey.'.'.$class_value.'.xsl')) {
	                    $xsl->load( 'typo3conf/ext/'.$this->extKey.'/res/xsl/'.$this->LLkey.'.'.$class_value.'.xsl', LIBXML_NOCDATA);
	                    $xslt->importStylesheet( $xsl );
	                    $content .= $xslt->transformToXML( $xml );
	            } else if (file_exists(PATH_typo3conf.ext.'/'.$this->extKey.'/res/xsl/default.'.$class_value.'.xsl')) {
	                    $xsl->load( 'typo3conf/ext/'.$this->extKey.'/res/xsl/default.'.$class_value.'.xsl', LIBXML_NOCDATA);
	                    $xslt->importStylesheet( $xsl );
	                    $content .= $xslt->transformToXML( $xml );
	            } else {
	                    $content .= $this->getFieldHeader('no_xsl_found');
	            }
			}
		} else if (file_exists($this->conf['data'].$this->internal['currentRow']['directory'].'/index.html' )) {
			$fp = fopen((string)$this->conf['data'].$this->internal['currentRow']['directory'].'/index.html',"r"); //lecture du fichier
			while (!feof($fp)) { //on parcourt toutes les lignes
				$content .= fgets($fp, 4096); // lecture du contenu de la ligne
Jerome Mariette's avatar
Jerome Mariette committed
637
638
			}
		} else {
Jerome Mariette's avatar
Jerome Mariette committed
639
			$content .= $this->getFieldHeader('not_synchro');
Jerome Mariette's avatar
Jerome Mariette committed
640
641
642
643
644
645
646
647
648
649
650
651
652
		}
		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
653
				return $this->pi_list_linkSingle($this->internal['currentRow'][$fN],$this->internal['currentRow']['uid'],1, $mergeArr);	
Jerome Mariette's avatar
Jerome Mariette committed
654
655
			break;
			case 'name':
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
656
				return $this->pi_list_linkSingle($this->internal['currentRow'][$fN],$this->internal['currentRow']['uid'],1, $mergeArr);	
Jerome Mariette's avatar
Jerome Mariette committed
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
			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;
	}
722

Jerome Mariette's avatar
Jerome Mariette committed
723
724
725
726
727
	/**
	 * Display a list of downloadable file
	 *
	 * @return	HTML of a list of downlabale links
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
728
729
	function get_downloads_list() {
		$directory = (string)$this->conf['data'].$this->internal['currentRow']['run_directory'];
Jerome Mariette's avatar
Jerome Mariette committed
730
731
732
733
734
		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)) {
735
				if(!is_dir($directory.'/'.$entry)&& $entry != '.' && $entry != '..' && !tx_nG6_utils::ends_with($entry, ".cfg")) {
Jerome Mariette's avatar
Jerome Mariette committed
736
					$link = 'fileadmin/'.$this->internal['currentRow']['run_directory'].'/'.$entry;
Jerome Mariette's avatar
Jerome Mariette committed
737
738
739
740
741
742
743
744
745
746
747
748
					$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');
		}
	}
	
749
750
751
752
753
754
755
756
757
758
759
760
761
762
	/**
	 * Display links for navigation in run lists or analyse lists. Called only if $end>1
	 *
	 * @param	$name		name of the variable set in GET: run_page or analyze_page
	 * @param	$start	current page number
	 * @param	$maxline	current total number of rows
	 *
	 * @return	HTML navigation links
	 */
	function pi_navigation_link_view($name, $start, $total_count) 
	{  
		$start = intval($start);		
		
		//max page number
Jerome Mariette's avatar
Jerome Mariette committed
763
		$end = $total_count/$this->internal['results_at_a_time'] ;
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
		$end = ceil($end) ;
		//repair URL mistakes caused by the nasty user  		
		if ($start > $end)
			$start = $end;
		if (($start < 1) or (! $start))
			$start = 1; 
					
		$start=(string)$start ; $end=(string)$end ;
		//create navigation links
		
		$go_back = $this->pi_linkTP_keepPIvars ('<<', array ($name => 1))	.' '.		$this->pi_linkTP_keepPIvars ('<', array ($name => $start-1));
		$go_ahead= $this->pi_linkTP_keepPIvars ('>', array ($name => $start+1)).' '.$this->pi_linkTP_keepPIvars ('>>', array ($name => $end)); 
		$current_pos = 'page '.$start. '/'.$end;
		
		if( $end == '1' )	{			//do nothing
			return '' ;
		}		
		elseif($start == '1')	{		//don't display << nor <
			$go_back = '';
		}
		elseif($start == $end)	{	//don't display > nor >>
			$go_ahead = '';		
		}
		else 		{	//display both
		}		
		$content = '<div align="right">'.$go_back .' '. $current_pos .' '. $go_ahead .'</div>' ;
		return $content;
	}	
792
793
	
	
Jerome Mariette's avatar
Jerome Mariette committed
794
795
796
797
798
799
800
801
802
803
		
}



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']);
}

?>