class.tx_nG6_pi1.php 26.6 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
<?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 <>
 */

30
31
32
33
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/lib/class.tx_nG6_db.php');
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/lib/class.tx_nG6_utils.php');
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/lib/class.tx_nG6_upgrade.php');
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/libs/Smarty.class.php'); 
Jerome Mariette's avatar
Jerome Mariette committed
34

35
class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
36
	
Jerome Mariette's avatar
Jerome Mariette committed
37
38
39
40
41
42
43
44
45
46
47
48
	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)	{
Gerald Salin's avatar
Gerald Salin committed
49
		//error_log("tx_nG6_pi1 \n", 3, "/work/tmp/mes-erreurs.log");
Jerome Mariette's avatar
Jerome Mariette committed
50
51
52
		if (strstr($this->cObj->currentRecord,'tt_content'))	{
			$conf['pidList'] = $this->cObj->data['pages'];
		}
Jerome Mariette's avatar
Jerome Mariette committed
53
54
		// Setting the TypoScript passed to this function in $this->conf
		$this->conf=$conf;
55
		
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
56
		$this->pi_setPiVarDefaults();
Jerome Mariette's avatar
Jerome Mariette committed
57
58
59
		// 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_USER_INT_obj=1;
		// Loading the LOCAL_LANG values
60
61
		$this->pi_loadLL();		
		
62
		// Add the ng6 plugins css
Jerome Mariette's avatar
Jerome Mariette committed
63
		$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] = '
64
65
66
67
68
69
70
71
72
73
74
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jquery.min.js"></script>
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jquery.dataTables.min.js"></script>
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/wysihtml5-0.3.0.min.js"></script>
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/bootstrap.min.js"></script>
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/bootstrap-editable.min.js"></script>			
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/bootstrap3-wysihtml5.all.min.js"></script>
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/dataTables.bootstrap.js"></script>
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/typeahead.bundle.js"></script>
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jflow.min.js"></script>
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/tx_nG6_pi1.js"></script>
			<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/tx_nG6_utils.js"></script>
75
			
76
77
78
79
80
81
82
			<link type="text/css" rel="stylesheet" media="screen" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/css/bootstrap3-wysihtml5.min.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/css/dataTables.bootstrap.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/css/bootstrap-editable.css"/>	
			<link type="text/css" rel="stylesheet" media="screen" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/css/typeaheadjs.css"/>	
			<link type="text/css" rel="stylesheet" media="screen" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/css/font-awesome.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/css/jflow.min.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/css/tx_nG6.css"/>';			
Jerome Mariette's avatar
Jerome Mariette committed
83
		
84
85
		tx_nG6_db::check_db_rights_level();

Jerome Mariette's avatar
Jerome Mariette committed
86
		// if asked to upgrade to version 1.2
87
		if($this->piVars['upgrade']){
88
			$content = '<div class="sub-content sc-top">'.tx_nG6_upgrade::upgrade($this->piVars['upgrade'], $this->conf["data"]).'</div>';
Celine Noirot's avatar
Celine Noirot committed
89
90
91
92
93
		} 
		else if(! $this->pi_is_install_finalized()) {
			$content .= $this->pi_install_view();
		}
		else {
Jerome Mariette's avatar
Jerome Mariette committed
94
95
96
97
98
99
100
101
102
103
104
			switch((string)$this->conf['view'])	{
				// If the plugin is configured to display results by run
				case 'run':
					if ($this->piVars['analyze_id']) {
						$content .= $this->pi_analyze_view();
					} else {
						$content .= $this->pi_run_view();
					}
					break;
				// If the plugin is not configured, display by project is default
				default:
105
106
107
108
109
110
111
					if ($this->piVars['analyze_id']) {
						$content .= $this->pi_analyze_view();
					} elseif ($this->piVars['project_id'] && $this->piVars['run_id']) {
						$content .= $this->pi_run_view();
					} else {
						$content .= $this->pi_project_view();
					}
Jerome Mariette's avatar
Jerome Mariette committed
112
					break;
Jerome Mariette's avatar
Jerome Mariette committed
113
114
			}
		}
Jerome Mariette's avatar
Jerome Mariette committed
115
		return $this->pi_wrapInBaseClass($content);
Penom Nom's avatar
Penom Nom committed
116
		
Jerome Mariette's avatar
Jerome Mariette committed
117
	}
Jerome Mariette's avatar
Jerome Mariette committed
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
	/**
	 * return a redirection view
	 * @return string
	 */
	function redirect_view(){
		$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')	=== FALSE ? 'http' : 'https';
		$host     = $_SERVER['HTTP_HOST'];
		$script   = $_SERVER['SCRIPT_NAME'];
		$currentUrl = $protocol . '://' . $host . $script ;
		return '<div class="sub-content"><br/><div class="alert alert-warning"><b>Access denied</b> - You are not authorized to access this page. You will be redirected in 3 seconds ' .
				'Click <a href="' . $currentUrl . '">here</a> if the redirection did not work'.
				'<meta http-equiv="refresh" content="3; URL=' . $currentUrl . '"></div></div>';
	}
	
	
Jerome Mariette's avatar
Jerome Mariette committed
134
	/**
Jerome Mariette's avatar
Jerome Mariette committed
135
	 * Return the project view
Jerome Mariette's avatar
Jerome Mariette committed
136
	 */
Jerome Mariette's avatar
Jerome Mariette committed
137
	function pi_project_view()	{		
Jerome Mariette's avatar
Jerome Mariette committed
138
		$projects = array();
Jerome Mariette's avatar
Jerome Mariette committed
139
140
		if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
		else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
141
142
		$is_current_user_superadmin = tx_nG6_db::is_user_ng6_superadmin($user_id);
		
Jerome Mariette's avatar
Jerome Mariette committed
143
		
144
		$single_project_display = false;
Jerome Mariette's avatar
Jerome Mariette committed
145
146
		// If a single element
		if ($this->piVars['project_id']) {
Jerome Mariette's avatar
Jerome Mariette committed
147
148
			if (tx_nG6_db::user_is_authorized($user_id, $this->piVars['project_id'], $this->piVars['run_id'])) {
				$projects = array('project_'.$this->piVars['project_id'] => tx_nG6_db::select_project($this->piVars['project_id']));
149
				$single_project_display = true ;
150
151
152
			}elseif( $is_current_user_superadmin ){
				$projects = array('project_'.$this->piVars['project_id'] => tx_nG6_db::select_project($this->piVars['project_id']));
				$single_project_display = true ;
Jerome Mariette's avatar
Jerome Mariette committed
153
			}
Jerome Mariette's avatar
Jerome Mariette committed
154
		} else {
155
156
157
158
159
160
161
			if( $is_current_user_superadmin ){
				$projects = tx_nG6_db::select_superadmin_projects();
			}else{
				$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.uid DESC');
				//$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.name');
			}
			
Jerome Mariette's avatar
Jerome Mariette committed
162
		}
Jerome Mariette's avatar
Jerome Mariette committed
163
164
165
166
		
		// If there is no project the user can access
		if (count($projects) > 0) {
			$smarty = new Smarty();
167
168
169
170
			$smarty->setTemplateDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/pi1');
			$smarty->setCompileDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/templates_c');
			$smarty->setCacheDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/cache');
			$smarty->setConfigDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/configs');
Jerome Mariette's avatar
Jerome Mariette committed
171
172
			$smarty->security = true;
			$smarty->security_settings['MODIFIER_FUNCS'] = array('count');		
Jerome Mariette's avatar
Jerome Mariette committed
173
			// Add some information to the table
Jerome Mariette's avatar
Jerome Mariette committed
174
175
176
177
178
179
180
181
182
			$project_ids = "";
			foreach($projects as $project_id => $project_values) {
				// project admin ?
				$projects[$project_id]['is_admin'] = tx_nG6_db::is_project_administrator($GLOBALS['TSFE']->fe_user->user['uid'], $project_values['id']);
				// project manager ?
				$projects[$project_id]['is_manager'] = tx_nG6_db::is_project_manager($GLOBALS['TSFE']->fe_user->user['uid'], $project_values['id']);
				// project member ?
				$projects[$project_id]['is_member'] = tx_nG6_db::is_project_member($GLOBALS['TSFE']->fe_user->user['uid'], $project_values['id']);
				
183
184
185
186
187
				//If the user is a superadmin, we set its rights to admin on each project
				if( $is_current_user_superadmin ){
					$projects[$project_id]['is_admin'] = true;
				}
				
Jerome Mariette's avatar
Jerome Mariette committed
188
189
				$project_ids .= $project_values['id'].",";
				$projects[$project_id]['href'] = $this->pi_list_linkSingle($project_values['name'],$project_values['id'],1, array('project_id'=>$project_values['id']));
Jerome Mariette's avatar
Jerome Mariette committed
190
			}
Jerome Mariette's avatar
Jerome Mariette committed
191
192
193
			$smarty->assign('projects', $projects);
			$smarty->assign('login_user', $GLOBALS['TSFE']->loginUser);
			$smarty->assign('user_id', $GLOBALS['TSFE']->fe_user->user['uid']);
Jerome Mariette's avatar
Jerome Mariette committed
194
			$smarty->assign('user_login', $GLOBALS['TSFE']->fe_user->user['username']);
Jerome Mariette's avatar
Jerome Mariette committed
195
196
197
198
199
			$smarty->assign('data_folder', $this->conf["data"]);
			$smarty->assign('from_email', $this->conf["FromEmail"]);
			$smarty->assign('server_name', $this->conf["server_name"]);
			$smarty->assign('project_ids', substr($project_ids,0,-1));
			$smarty->assign('pid', $this->conf['userpidList']);
Jerome Mariette's avatar
Jerome Mariette committed
200
			$smarty->assign('server_url', $this->conf['server_url']);
201
			$smarty->assign('single_project_display', $single_project_display);
202
			$smarty->assign('is_ng6_admin', tx_nG6_db::is_ng6_administrator($user_id) || tx_nG6_db::is_user_ng6_superadmin($user_id) ? true : false);
Romain Therville's avatar
Romain Therville committed
203
			$smarty->assign('is_ng6_superadmin', tx_nG6_db::is_user_ng6_superadmin($user_id) ? true : false);
204
			
Jerome Mariette's avatar
Jerome Mariette committed
205
			// If it's a single project, add runs and analysis information
206
			if ($single_project_display) {
207
208
209
210
211
				
				//comments on the project
				$comments = tx_nG6_db::get_all_project_comments($projects[key($projects)]['id']);
				$smarty->assign('comments', $comments);
				
Jerome Mariette's avatar
Jerome Mariette committed
212
213
214
215
216
217
218
219
				// Get all users on project
				$project_users = tx_nG6_db::get_all_users_on_project($projects[key($projects)]['id']);
				$smarty->assign('project_users', $project_users);
	
				// Add some information to the table
				$project_runs = tx_nG6_db::get_project_runs($projects[key($projects)]['id']);
				foreach($project_runs as $run_id => $run_values) {
					$project_runs[$run_id]['is_admin'] = tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'run', $run_values['id']);
220
221
222
223
224
					
					if( $is_current_user_superadmin ){
						$project_runs[$run_id]['is_admin'] = 1;
					}
					
Jerome Mariette's avatar
Jerome Mariette committed
225
226
227
228
229
230
231
232
					$project_runs[$run_id]['href'] = $this->pi_list_linkSingle($run_values['name'],$run_values['id'],1, array('run_id'=>$run_values['id'], 'project_id'=>$run_values['project_id']));
				}
				$smarty->assign('project_runs', $project_runs);
				$project_analysis = tx_nG6_db::get_project_analysis($projects[key($projects)]['id']);
				
				// Add some information to the table
				foreach($project_analysis as $analysis_id => $analysis_values) {
					$project_analysis[$analysis_id]['is_admin'] = tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'analyze', $analysis_values['id']);
233
234
235
236
237
					
					if( $is_current_user_superadmin ){
						$project_analysis[$analysis_id]['is_admin'] = 1;
					}
					
Jerome Mariette's avatar
Jerome Mariette committed
238
239
					$project_analysis[$analysis_id]['href'] = $this->pi_list_linkSingle($analysis_values['name'],$analysis_values['id'],1, array('analyze_id'=>$analysis_values['id'], 'project_id'=>$this->piVars['project_id']));
				}
240
				$smarty->assign('h_analysis', tx_nG6_utils::trace_hierarchy($project_analysis));
Jerome Mariette's avatar
Jerome Mariette committed
241
				$smarty->assign('project_analysis', $project_analysis);
Romain Therville's avatar
Romain Therville committed
242
243
244
245
246
247
248
				
				if( $projects[$project_id]['is_admin'] == 1 ){
					$smarty->assign('managment_purged_data', tx_nG6_db::select_a_project_retention_data_info($projects[key($projects)]['id'], TRUE, TRUE));
				}else{
					$smarty->assign('managment_purged_data', tx_nG6_db::select_a_project_retention_data_info($projects[key($projects)]['id'], TRUE, FALSE));
				}
				
249
250
251
				$txNG6Utils = new tx_nG6_utils;
				//$smarty->register_object('tx_nG6_utils',$txNG6Utils);
				$smarty->assign_by_ref('tx_nG6_utils', $txNG6Utils);
252
253

				$smarty->assign_by_ref('retention_policy', tx_nG6_utils::get_project_retention_policy($projects[key($projects)]['id']));
254
				
Jerome Mariette's avatar
Jerome Mariette committed
255
256
257
			}	
			return $smarty->fetch('project_view.tpl');
		} else {
258
			return $this->redirect_view();
Jerome Mariette's avatar
Jerome Mariette committed
259
		}
Jerome Mariette's avatar
Jerome Mariette committed
260
	}
261
	
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
262

Jerome Mariette's avatar
Jerome Mariette committed
263
	/**
Jerome Mariette's avatar
Jerome Mariette committed
264
	 * Return the run view
Jerome Mariette's avatar
Jerome Mariette committed
265
	 */
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
266
    function pi_run_view() {
267

Jerome Mariette's avatar
Jerome Mariette committed
268
		$runs = array();
Jerome Mariette's avatar
Jerome Mariette committed
269
270
		if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
		else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
271
		$is_current_user_superadmin = tx_nG6_db::is_user_ng6_superadmin($user_id);
Jerome Mariette's avatar
Jerome Mariette committed
272
		
273
		$single_run_display = false;
Jerome Mariette's avatar
Jerome Mariette committed
274
275
		// If a single element
		if ($this->piVars['run_id']) {
276
			if (tx_nG6_db::user_is_authorized($user_id, $this->piVars['project_id'], $this->piVars['run_id']) || $is_current_user_superadmin ) {
Jerome Mariette's avatar
Jerome Mariette committed
277
				$runs = array('run_'.$this->piVars['run_id'] => tx_nG6_db::select_run($this->piVars['run_id']));
278
				$single_run_display = true;
Jerome Mariette's avatar
Jerome Mariette committed
279
			}
Jerome Mariette's avatar
Jerome Mariette committed
280
		} else {
281
			$runs = tx_nG6_db::select_all_user_runs($user_id,"tx_nG6_run.uid DESC");
Jerome Mariette's avatar
Jerome Mariette committed
282
		}
283
		
Jerome Mariette's avatar
Jerome Mariette committed
284
285
		if (count($runs) > 0) {
			$smarty = new Smarty();
286
287
288
289
			$smarty->setTemplateDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/pi1');
			$smarty->setCompileDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/templates_c');
			$smarty->setCacheDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/cache');
			$smarty->setConfigDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/configs');
Jerome Mariette's avatar
Jerome Mariette committed
290
291
292
			$smarty->security = true;
			$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
	
Jerome Mariette's avatar
Jerome Mariette committed
293
			// Add some information to the table
Jerome Mariette's avatar
Jerome Mariette committed
294
295
			$run_ids = "";
			foreach($runs as $run_id => $run_values) {
296
				if (tx_nG6_db::is_administrator($user_id, 'run', $run_values['id']) || $is_current_user_superadmin ) {
Jerome Mariette's avatar
Jerome Mariette committed
297
298
299
300
301
					$runs[$run_id]['is_admin'] = true;
				} else {
					$runs[$run_id]['is_admin'] = false;
				}
				$run_ids .= $run_values['id'].",";
Jerome Mariette's avatar
Jerome Mariette committed
302
				if ($this->piVars['project_id']) {
Jerome Mariette's avatar
Jerome Mariette committed
303
					$runs[$run_id]['href'] = $this->pi_list_linkSingle($run_values['name'],$run_values['id'],1, array('run_id'=>$run_values['id'], 'project_id'=>$run_values['project_id']));	
Jerome Mariette's avatar
Jerome Mariette committed
304
				} else {
Jerome Mariette's avatar
Jerome Mariette committed
305
					$runs[$run_id]['href'] = $this->pi_list_linkSingle($run_values['name'],$run_values['id'],1, array('run_id'=>$run_values['id']));
Jerome Mariette's avatar
Jerome Mariette committed
306
307
				}
			}
Jerome Mariette's avatar
Jerome Mariette committed
308
309
			$smarty->assign('runs', $runs);
			$smarty->assign('login_user', $GLOBALS['TSFE']->loginUser);
Jerome Mariette's avatar
Jerome Mariette committed
310
			$smarty->assign('user_login', $GLOBALS['TSFE']->fe_user->user['username']);
Jerome Mariette's avatar
Jerome Mariette committed
311
312
313
			$smarty->assign('user_id', $GLOBALS['TSFE']->fe_user->user['uid']);
			$smarty->assign('data_folder', $this->conf["data"]);
			$smarty->assign('server_name', $this->conf["server_name"]);
Jerome Mariette's avatar
Jerome Mariette committed
314
			$smarty->assign('server_url', $this->conf['server_url']);
Jerome Mariette's avatar
Jerome Mariette committed
315
			$smarty->assign('run_ids', substr($run_ids,0,-1));
316
			$smarty->assign('single_run_display', $single_run_display);
Jerome Mariette's avatar
Jerome Mariette committed
317
318
			
			// If it's a single run, add analysis information
319
			if ($single_run_display) {
320
321
322
323
324
				
				//comments on the run
				$comments = tx_nG6_db::get_all_run_comments($runs[key($runs)]['id']);
				$smarty->assign('comments', $comments);
				
325
326
327
328
				$retention_policy = tx_nG6_db::select_run_retention_status($runs[key($runs)]['id']);
				$smarty->assign('run_data_state', $retention_policy['run_data_state']);
				$smarty->assign('run_retention_date', $retention_policy['run_retention_date']);
				
Jerome Mariette's avatar
Jerome Mariette committed
329
330
331
332
				$run_analysis = tx_nG6_db::get_run_analysis($runs[key($runs)]['id']);
				// Add some information to the table
				foreach($run_analysis as $analysis_id => $analysis_values) {
					$run_analysis[$analysis_id]['is_admin'] = tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'analyze', $analysis_values['id']);
333
334
335
					if($is_current_user_superadmin){
						$run_analysis[$analysis_id]['is_admin'] = 1;
					}
Jerome Mariette's avatar
Jerome Mariette committed
336
337
338
339
340
341
					if ($this->piVars['project_id']) {
						$run_analysis[$analysis_id]['href'] = $this->pi_list_linkSingle($analysis_values['name'],$analysis_values['id'],1, array('analyze_id'=>$analysis_values['id'], 'project_id'=>$this->piVars['project_id'], 'run_id'=>$this->piVars['run_id']));
					} else {
						$run_analysis[$analysis_id]['href'] = $this->pi_list_linkSingle($analysis_values['name'],$analysis_values['id'],1, array('analyze_id'=>$analysis_values['id'], 'run_id'=>$this->piVars['run_id']));
					}
				}
342
				$smarty->assign('h_analysis', tx_nG6_utils::trace_hierarchy($run_analysis));
Jerome Mariette's avatar
Jerome Mariette committed
343
344
345
346
				$smarty->assign('run_analysis', $run_analysis);
			}		
			return $smarty->fetch('run_view.tpl');
		} else {
347
			return $this->redirect_view();
Jerome Mariette's avatar
Jerome Mariette committed
348
		}
349
350
	}
	
Jerome Mariette's avatar
sql ok    
Jerome Mariette committed
351

Jerome Mariette's avatar
Jerome Mariette committed
352
	/**
Jerome Mariette's avatar
Jerome Mariette committed
353
	 * Return the analysis view
Jerome Mariette's avatar
Jerome Mariette committed
354
	 */
Jerome Mariette's avatar
Jerome Mariette committed
355
	function pi_analyze_view() {
356
357
		if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
		else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
358
		$is_current_user_superadmin = tx_nG6_db::is_user_ng6_superadmin($user_id);
359
		
Penom Nom's avatar
Penom Nom committed
360
		$smarty = new Smarty();
361
362
363
364
		$smarty->setTemplateDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/pi1/analyzes');
		$smarty->setCompileDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/templates_c');
		$smarty->setCacheDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/cache');
		$smarty->setConfigDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/configs');
Penom Nom's avatar
Penom Nom committed
365
366
367
		$smarty->security = true;
		$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
		
368
		// First select the analyse
Jerome Mariette's avatar
Jerome Mariette committed
369
		$analyse = tx_nG6_db::select_analyse($this->piVars['analyze_id']);
Jerome Mariette's avatar
Jerome Mariette committed
370
		
Penom Nom's avatar
Penom Nom committed
371
372
373
		// is project admin
		$is_project_admin = tx_nG6_db::is_project_administrator($GLOBALS['TSFE']->fe_user->user['uid'], $analyse['project_id']);
		
374
375
376
		if( $is_current_user_superadmin ){ $is_project_admin = 1; }
		
		if (tx_nG6_db::user_is_authorized($user_id, $analyse['project_id'], $this->piVars['run_id']) || $is_current_user_superadmin ) {
Penom Nom's avatar
Penom Nom committed
377
			
Penom Nom's avatar
Penom Nom committed
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
			if ($is_project_admin || $analyse['hidden'] == "0") {
				// Handle old fashion
				if (file_exists($this->conf['data'].$analyse['directory'].'/index.html' )) {
					// Add the analyse description
					$content = '<div id="img_dialog" title=""></div>';
					$content .= '<input type="hidden" id="analyse_name" value="'.$analyse['name'].'" />';
					$content .= '<div'.$this->pi_classParam('singleView').'>';
					$content .= '<h2>Analyse '.$analyse['name'].' : <span>'.$analyse['description'].'</span></h2></div>';
					$fp = fopen((string)$this->conf['data'].$analyse['directory'].'/index.html',"r");
					while (!feof($fp)) {
						$content .= fgets($fp, 4096);
					}
					return $content;
					// Else meaning using smarty
				} else {
				
					$smarty->assign('is_project_admin', $is_project_admin);
					$smarty->assign('analyse', $analyse);
					$analysis_size = tx_nG6_db::get_analysis_size($this->piVars['analyze_id']);
					$smarty->assign('analyse_size', tx_nG6_utils::get_octet_string_representation($analysis_size));
					$smarty->assign('data_folder', $this->conf["data"]);
					$smarty->assign('analyze_id', $this->piVars['analyze_id']);
					$smarty->assign('server_url', $this->conf['server_url']);
					$smarty->assign('user_login', $GLOBALS['TSFE']->fe_user->user['username']);
					$smarty->assign('user_id', $GLOBALS['TSFE']->fe_user->user['uid']);
403
404
405
406
					
					$retention_policy = tx_nG6_db::select_analysis_retention_status($this->piVars['analyze_id']);
					$smarty->assign('analysis_data_state', $retention_policy['analysis_data_state']);
					$smarty->assign('analysis_retention_date', $retention_policy['analysis_retention_date']);
Penom Nom's avatar
Penom Nom committed
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
				
					// Then select analyse results
					$results = tx_nG6_db::select_analyse_results($this->piVars['analyze_id']);
					$smarty->assign('analyse_results', $results);
				
					//comments on the analysis
					$comments = tx_nG6_db::get_all_analyze_comments($this->piVars['analyze_id']);
					$smarty->assign('comments', $comments);
				
					// Select the run file description
					if ($analyse['run_id'] != 'None') {
						$descriptions = tx_nG6_db::select_mid_descriptions($analyse['run_id']);
					} else {
						$descriptions = array();
					}
					$smarty->assign('descriptions', $descriptions);
					$smarty->assign('data_folder', $this->conf['data']);
				
					// Try to process the analyse template
					try {
						$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] .= '
428
429
430
431
432
433
434
435
436
437
438
439
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/tx_nG6_pi1_analysis.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jquery.venny.min.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jquery.highcharts.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jquery.highcharts.exporting.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jquery.highcharts.more.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jquery.highcharts.exportcsv.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jsphylosvg-min.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/raphael-min.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/unitip.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/jquery.jstree.min.js"></script>
						<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/js/d3-3.4.4.min.js"></script>
						<link type="text/css" rel="stylesheet" media="screen" href="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'res/css/unitip.css"/>';
Penom Nom's avatar
Penom Nom committed
440
						
441
						if (file_exists(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->extKey).'pi1/analyzes/'.$analyse['class'].'.js')) {
Penom Nom's avatar
Penom Nom committed
442
							$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] .= '
443
							<script type="text/javascript" src="'.\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey).'pi1/analyzes/'.$analyse['class'].'.js"></script>';
Penom Nom's avatar
Penom Nom committed
444
445
						}
						
Penom Nom's avatar
Penom Nom committed
446
447
448
449
						return $smarty->fetch($analyse['class'].'.tpl');
					} catch (Exception $e) {
						return 'No template found for class ' . $analyse['class'];
					}
450
451
				}
			}
Jerome Mariette's avatar
Jerome Mariette committed
452
		}
Penom Nom's avatar
Penom Nom committed
453
		return $smarty->fetch('AnalaysisAccessDenied.tpl');
Jerome Mariette's avatar
Jerome Mariette committed
454
	}
Penom Nom's avatar
Penom Nom committed
455
456
	
	
Celine Noirot's avatar
Celine Noirot committed
457
458
459
460
461
	/**
	 * Return the install view
	 */
	function pi_install_view() {
		$smarty = new Smarty();
462
463
464
465
		$smarty->setTemplateDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/pi1');
		$smarty->setCompileDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/templates_c');
		$smarty->setCacheDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/cache');
		$smarty->setConfigDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/res/smarty/configs');
Celine Noirot's avatar
Celine Noirot committed
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
		$smarty->security = true;
		$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
		$smarty->assign('server_name', $this->conf["server_name"]);
		$smarty->assign('server_url', $this->conf['server_url']);
		$smarty->assign('pid', $this->conf['userpidList']);
		return $smarty->fetch('install_view.tpl');
	}
	/**
	 * Does installation need is finalized ( admin_install user exist in db )
	 *
	 * @param	integer		Alternative page ID for the link. (By default this function links to the SAME page!)
	 * @return	boolean		If true, intallation allready finalysed
	 */
	function pi_is_install_finalized()	{
		$res = tx_nG6_db::select_user_by_username("admin_install");
Jerome Mariette's avatar
Jerome Mariette committed
481
		if ($res == null) {
Celine Noirot's avatar
Celine Noirot committed
482
			return true;
Jerome Mariette's avatar
Jerome Mariette committed
483
		} else {
Celine Noirot's avatar
Celine Noirot committed
484
485
486
			return false;
		}
	}
Jerome Mariette's avatar
Jerome Mariette committed
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
	
	/**
	 * 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;
	}
518
	
Jerome Mariette's avatar
Jerome Mariette committed
519
520
521
522
523
524
}

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

Penom Nom's avatar
Penom Nom committed
525
?>