* 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(\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');
class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
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) {
//error_log("tx_nG6_pi1 \n", 3, "/work/tmp/mes-erreurs.log");
if (strstr($this->cObj->currentRecord,'tt_content')) {
$conf['pidList'] = $this->cObj->data['pages'];
}
// Setting the TypoScript passed to this function in $this->conf
$this->conf=$conf;
$this->pi_setPiVarDefaults();
// 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
$this->pi_loadLL();
// Add the ng6 plugins css
$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] = '
';
tx_nG6_db::check_db_rights_level();
// if asked to upgrade to version 1.2
if($this->piVars['upgrade']){
$content = '
Access denied - You are not authorized to access this page. You will be redirected in 3 seconds ' .
'Click
here if the redirection did not work'.
'
';
}
/**
* Return the project view
*/
function pi_project_view() {
$projects = array();
if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
$is_current_user_superadmin = tx_nG6_db::is_user_ng6_superadmin($user_id);
$single_project_display = false;
// If a single element
if ($this->piVars['project_id']) {
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']));
$single_project_display = true ;
}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 ;
}
} else {
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');
}
}
// If there is no project the user can access
if (count($projects) > 0) {
$smarty = new Smarty();
$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');
$smarty->security = true;
$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
// Add some information to the table
$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']);
//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;
}
$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']));
}
$smarty->assign('projects', $projects);
$smarty->assign('login_user', $GLOBALS['TSFE']->loginUser);
$smarty->assign('user_id', $GLOBALS['TSFE']->fe_user->user['uid']);
$smarty->assign('user_login', $GLOBALS['TSFE']->fe_user->user['username']);
$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']);
$smarty->assign('server_url', $this->conf['server_url']);
$smarty->assign('single_project_display', $single_project_display);
$smarty->assign('is_ng6_admin', tx_nG6_db::is_ng6_administrator($user_id) || tx_nG6_db::is_user_ng6_superadmin($user_id) ? true : false);
$smarty->assign('is_ng6_superadmin', tx_nG6_db::is_user_ng6_superadmin($user_id) ? true : false);
// If it's a single project, add runs and analysis information
if ($single_project_display) {
//comments on the project
$comments = tx_nG6_db::get_all_project_comments($projects[key($projects)]['id']);
$smarty->assign('comments', $comments);
// 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']);
if( $is_current_user_superadmin ){
$project_runs[$run_id]['is_admin'] = 1;
}
$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']);
if( $is_current_user_superadmin ){
$project_analysis[$analysis_id]['is_admin'] = 1;
}
$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']));
}
$smarty->assign('h_analysis', tx_nG6_utils::trace_hierarchy($project_analysis));
$smarty->assign('project_analysis', $project_analysis);
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));
}
$txNG6Utils = new tx_nG6_utils;
//$smarty->register_object('tx_nG6_utils',$txNG6Utils);
$smarty->assign_by_ref('tx_nG6_utils', $txNG6Utils);
$smarty->assign_by_ref('retention_policy', tx_nG6_utils::get_project_retention_policy($projects[key($projects)]['id']));
}
return $smarty->fetch('project_view.tpl');
} else {
return $this->redirect_view();
}
}
/**
* Return the run view
*/
function pi_run_view() {
$runs = array();
if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
$is_current_user_superadmin = tx_nG6_db::is_user_ng6_superadmin($user_id);
$single_run_display = false;
// If a single element
if ($this->piVars['run_id']) {
if (tx_nG6_db::user_is_authorized($user_id, $this->piVars['project_id'], $this->piVars['run_id']) || $is_current_user_superadmin ) {
$runs = array('run_'.$this->piVars['run_id'] => tx_nG6_db::select_run($this->piVars['run_id']));
$single_run_display = true;
}
} else {
$runs = tx_nG6_db::select_all_user_runs($user_id,"tx_nG6_run.uid DESC");
}
if (count($runs) > 0) {
$smarty = new Smarty();
$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');
$smarty->security = true;
$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
// Add some information to the table
$run_ids = "";
foreach($runs as $run_id => $run_values) {
if (tx_nG6_db::is_administrator($user_id, 'run', $run_values['id']) || $is_current_user_superadmin ) {
$runs[$run_id]['is_admin'] = true;
} else {
$runs[$run_id]['is_admin'] = false;
}
$run_ids .= $run_values['id'].",";
if ($this->piVars['project_id']) {
$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']));
} else {
$runs[$run_id]['href'] = $this->pi_list_linkSingle($run_values['name'],$run_values['id'],1, array('run_id'=>$run_values['id']));
}
}
$smarty->assign('runs', $runs);
$smarty->assign('login_user', $GLOBALS['TSFE']->loginUser);
$smarty->assign('user_login', $GLOBALS['TSFE']->fe_user->user['username']);
$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"]);
$smarty->assign('server_url', $this->conf['server_url']);
$smarty->assign('run_ids', substr($run_ids,0,-1));
$smarty->assign('single_run_display', $single_run_display);
// If it's a single run, add analysis information
if ($single_run_display) {
//comments on the run
$comments = tx_nG6_db::get_all_run_comments($runs[key($runs)]['id']);
$smarty->assign('comments', $comments);
$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']);
$smarty->assign('run_purge_date', $retention_policy['run_purge_date']);
$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']);
if($is_current_user_superadmin){
$run_analysis[$analysis_id]['is_admin'] = 1;
}
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']));
}
}
$smarty->assign('h_analysis', tx_nG6_utils::trace_hierarchy($run_analysis));
$smarty->assign('run_analysis', $run_analysis);
}
return $smarty->fetch('run_view.tpl');
} else {
return $this->redirect_view();
}
}
/**
* Return the analysis view
*/
function pi_analyze_view() {
if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
$is_current_user_superadmin = tx_nG6_db::is_user_ng6_superadmin($user_id);
$smarty = new Smarty();
$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');
$smarty->security = true;
$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
// First select the analyse
$analyse = tx_nG6_db::select_analyse($this->piVars['analyze_id']);
// is project admin
$is_project_admin = tx_nG6_db::is_project_administrator($GLOBALS['TSFE']->fe_user->user['uid'], $analyse['project_id']);
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 ) {
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 = '