Commit df8c8c2c authored by Jerome Mariette's avatar Jerome Mariette
Browse files

modify download + add download using symbolic links

parent 2555a1a5
This diff is collapsed.
No preview for this file type
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009 PF bioinformatique de Toulouse <>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_utils.php');
/**
* Class_nG6_db' for the 'nG6' extension.
* This class is in charge of all communication with the database
*
* @author PF bioinformatique de Toulouse <>
*/
class tx_nG6_db {
/*
* Project functions
*------------------------------------------------------------*/
/**
* Select all project for the current user
*
* @param string $user_group the user group
* @return table with all projects
*/
function select_all_user_projects($user_group) {
$projects = array();
// If the user is not logged on display demonstration project
if (!$GLOBALS['TSFE']->loginUser) {
$where = 'fe_group=0';
} else {
$where = 'fe_group IN ('.tx_nG6_db::get_user_groups($user_group).')';
}
//First, get the analyzis project-scale
$queryParts = array(
'SELECT' => 'tx_nG6_project.uid AS project_id, '.
'tx_nG6_project.name AS project_name, '.
'tx_nG6_project.description AS project_description, '.
'tx_nG6_project.fe_group AS project_fe_group, '.
'tx_nG6_project.hidden AS project_hidden',
'FROM' => 'tx_nG6_project',
'WHERE' => $where,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($user_group));
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$project_id = $row['project_id'];
// Is the user allowed to see this project
$user_allowed = false;
if ($row['project_hidden'] == 0) {
$user_allowed = true;
} else {
foreach(tx_nG6_db::get_super_groups_of($row['project_fe_group']) AS $valeur) {
if (in_array($valeur, $user_groups)) {
$user_allowed = true;
}
}
}
if (!isset ($projects['project_'.$project_id]) and $user_allowed) {
$projects['project_'.$project_id] = array(
'id' => $project_id,
'name' => $row['project_name'],
'description' => $row['project_description']);
}
}
return $projects;
}
/**
* Select a run from the database
*
* @param string $project_id the project id to return
* @return hash table with all project information
*/
function select_project($project_id) {
$queryParts = array(
'SELECT' => '*',
'FROM' => 'tx_nG6_project',
'WHERE' => 'tx_nG6_project.uid = '.$project_id,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
return $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
}
/**
* Select all runs linked to the specified project
*
* @param string $user_group the user group
* @param string $project_id the project id
* @return hash table with all runs information
*/
function get_project_runs($user_group, $project_id) {
// First select all runs from the database
$queryParts = Array(
'SELECT' => 'tx_nG6_run.uid AS run_id,'.
'tx_nG6_run.directory AS run_directory,'.
'tx_nG6_run.species AS run_species,'.
'tx_nG6_run.description AS run_description, '.
'tx_nG6_run.name AS run_name, '.
'tx_nG6_run.nb_sequences, '.
'tx_nG6_run.date AS run_date, '.
'tx_nG6_run.hidden AS run_hidden, '.
'tx_nG6_project.fe_group AS project_fe_group',
'FROM' => 'tx_nG6_project INNER JOIN ( tx_nG6_project_run INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid '.
' ) ON tx_nG6_project.uid=tx_nG6_project_run.project_id',
'WHERE' => 'tx_nG6_project.uid='.$project_id,
'GROUPBY' => '',
'ORDERBY' => 'tx_nG6_run.date DESC',
'LIMIT' => ''
);
// Then create the result hash table
$results = array();
$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($user_group));
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$run_id = $row['run_id'];
// Is the user allowed to see this run
$user_allowed = false;
if ($row['run_hidden'] == 0) {
$user_allowed = true;
} else {
foreach(tx_nG6_db::get_super_groups_of($row['project_fe_group']) AS $valeur) {
if (in_array($valeur, $user_groups)) {
$user_allowed = true;
}
}
}
if (!isset($results['run_'.$run_id]) and $user_allowed) {
$results['run_'.$run_id] = array(
'directory' => $row['run_directory'],
'name' => $row['run_name'],
'species' => $row['run_species'],
'nb_sequences' => $row['nb_sequences'],
'date' => $row['run_date'],
'description' => $row['run_description']
);
}
}
return $results;
}
/**
* Select all analysis linked to the specified project
*
* @param string $user_group the user group
* @param string $project_id the project id
* @return hash table with all analysis information
*/
function get_project_analysis($user_group, $project_id) {
// First select all analysis from the database
$queryParts = array(
'SELECT' => 'tx_nG6_analyze.uid AS analyze_id,'.
'tx_nG6_analyze.directory AS analyze_directory,'.
'tx_nG6_analyze.name AS analyze_name, '.
'tx_nG6_analyze.date AS analyze_date, '.
'tx_nG6_analyze.description AS analyze_description, '.
'tx_nG6_analyze.hidden AS analyze_hidden, '.
'tx_nG6_project.fe_group AS project_fe_group',
'FROM' => 'tx_nG6_project INNER JOIN (tx_nG6_project_analyze INNER JOIN tx_nG6_analyze ON ' .
'tx_nG6_analyze.uid=tx_nG6_project_analyze.analyze_id) ON tx_nG6_project.uid = tx_nG6_project_analyze.project_id ',
'WHERE' => 'tx_nG6_project_analyze.project_id='.$project_id,
'GROUPBY' => '',
'ORDERBY' => 'tx_nG6_analyze.name',
'LIMIT' => ''
);
// Then create the result hash table
$results = array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($user_group));
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$analyze_id = $row['analyze_id'];
// Is the user allowed to see this analyse
$user_allowed = false;
if ($row['analyze_hidden'] == 0) {
$user_allowed = true;
} else {
foreach(tx_nG6_db::get_super_groups_of($row['project_fe_group']) AS $valeur) {
if (in_array($valeur, $user_groups)) {
$user_allowed = true;
}
}
}
if (!isset ($results['analyse_'.$analyze_id]) and $user_allowed) {
$results['analyse_'.$analyze_id] = array(
'directory' => $row['analyze_directory'],
'name' => $row['analyze_name'],
'date' => $row['analyze_date'],
'description' => $row['analyse_description']
);
}
}
return $results;
}
/*
* Run functions
*------------------------------------------------------------*/
/**
* Select all information for the specified run
*
* @param string $run_id the run id
* @return hash table with all the run information
*/
function get_run($run_id) {
// First select the run from the database
$queryParts = Array(
'SELECT' => 'tx_nG6_project.uid AS project_id,'.
'tx_nG6_project.name AS project_name,'.
'tx_nG6_run.uid AS run_id,'.
'tx_nG6_run.directory AS run_directory,'.
'tx_nG6_run.description AS run_description, '.
'tx_nG6_run.name AS run_name, '.
'tx_nG6_run.nb_sequences, '.
'tx_nG6_run.date AS run_date',
'FROM' => 'tx_nG6_project INNER JOIN ( tx_nG6_project_run INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid '.
' ) ON tx_nG6_project.uid=tx_nG6_project_run.project_id',
'WHERE' => 'tx_nG6_run.uid='.$run_id,
'GROUPBY' => '',
'ORDERBY' => 'tx_nG6_run.date DESC',
'LIMIT' => ''
);
// Then create the result hash table
$result = array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$run_id = $row['run_id'];
if (!isset ($results['run_'.$run_id])) {
$result = array(
'project_id' => $row['project_id'],
'project_name' => $row['project_name'],
'directory' => $row['run_directory'],
'name' => $row['run_name'],
'nb_sequences' => $row['nb_sequences'],
'date' => $row['run_date'],
'description' => $row['run_description']
);
}
}
return $result;
}
/**
* Select all analysis linked to the specified run
*
* @param string $user_group the user group
* @param string $run_id the run id
* @return hash table with all analysis information
*/
function get_run_analysis($user_group, $run_id) {
// First select all analysis from the database
$queryParts = array(
'SELECT' => 'tx_nG6_analyze.uid AS analyze_id,'.
'tx_nG6_analyze.directory AS analyze_directory,'.
'tx_nG6_analyze.name AS analyze_name, '.
'tx_nG6_analyze.date AS analyze_date, '.
'tx_nG6_analyze.hidden AS analyze_hidden, '.
'tx_nG6_analyze.description AS analyze_description, '.
'tx_nG6_project.fe_group AS project_fe_group',
'FROM' => 'tx_nG6_project INNER JOIN ( tx_nG6_project_run INNER JOIN ( tx_nG6_run INNER JOIN ( tx_nG6_run_analyze INNER JOIN '.
'tx_nG6_analyze ON tx_nG6_analyze.uid = tx_nG6_run_analyze.analyze_id) ON tx_nG6_run_analyze.run_id = tx_nG6_run.uid '.
') ON tx_nG6_run.uid = tx_nG6_project_run.run_id) ON tx_nG6_project_run.project_id = tx_nG6_project.uid ',
'WHERE' => 'tx_nG6_run_analyze.run_id='.$run_id,
'GROUPBY' => '',
'ORDERBY' => 'tx_nG6_analyze.name',
'LIMIT' => ''
);
// Then create the result hash table
$results = array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$user_groups = t3lib_div::intExplode(',',tx_nG6_db::get_user_groups($user_group));
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$analyze_id = $row['analyze_id'];
// Is the user allowed to see this analyse
$user_allowed = false;
if ($row['analyze_hidden'] == 0) {
$user_allowed = true;
} else {
foreach(tx_nG6_db::get_super_groups_of($row['project_fe_group']) AS $valeur) {
if (in_array($valeur, $user_groups)) {
$user_allowed = true;
}
}
}
if (!isset ($results['analyse_'.$analyze_id]) and $user_allowed) {
$results['analyse_'.$analyze_id] = array(
'directory' => $row['analyze_directory'],
'name' => $row['analyze_name'],
'date' => $row['analyze_date'],
'description' => $row['analyse_description']
);
}
}
return $results;
}
/*
* Run functions
*------------------------------------------------------------*/
/**
* Select all information on an analyse
*
* @param string $analyse_id the analyse id
* @return hash table with all analyse information
*/
function get_analyse($analyse_id) {
// First select all analyse information
$queryParts = array(
'SELECT' => 'tx_nG6_project.uid AS project_id,'.
'tx_nG6_project.name AS project_name,'.
'tx_nG6_analyze.uid AS analyze_id,'.
'tx_nG6_analyze.directory AS analyze_directory,'.
'tx_nG6_analyze.name AS analyze_name, '.
'tx_nG6_analyze.date AS analyze_date, '.
'tx_nG6_analyze.description AS analyze_description ',
'FROM' => 'tx_nG6_project INNER JOIN (tx_nG6_project_analyze INNER JOIN tx_nG6_analyze ON ' .
'tx_nG6_analyze.uid=tx_nG6_project_analyze.analyze_id) ON tx_nG6_project.uid = tx_nG6_project_analyze.project_id ',
'WHERE' => 'tx_nG6_analyze.uid='.$analyse_id,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
// If it's a project analyse, add project information
if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
$result = array();
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$result = array(
'project_name' => $row['project_name'],
'project_id' => $row['project_id'],
'run_name' => 'None',
'run_id' => 'None',
'directory' => $row['analyze_directory'],
'name' => $row['analyze_name'],
'date' => $row['analyze_date'],
'description' => $row['analyze_description']
);
}
return $result;
} else { // If it's a run analyse, add run information
$queryParts = array(
'SELECT' => 'tx_nG6_project.name AS project_name,'.
'tx_nG6_project.uid AS project_id,'.
'tx_nG6_run.uid AS run_id,'.
'tx_nG6_run.name AS run_name,'.
'tx_nG6_analyze.uid AS analyze_id,'.
'tx_nG6_analyze.directory AS analyze_directory,'.
'tx_nG6_analyze.name AS analyze_name, '.
'tx_nG6_analyze.date AS analyze_date, '.
'tx_nG6_analyze.description AS analyze_description',
'FROM' => 'tx_nG6_project INNER JOIN ( tx_nG6_project_run INNER JOIN ( tx_nG6_run INNER JOIN ( tx_nG6_run_analyze INNER JOIN '.
'tx_nG6_analyze ON tx_nG6_analyze.uid = tx_nG6_run_analyze.analyze_id) ON tx_nG6_run_analyze.run_id = tx_nG6_run.uid '.
') ON tx_nG6_run.uid = tx_nG6_project_run.run_id) ON tx_nG6_project_run.project_id = tx_nG6_project.uid ',
'WHERE' => 'tx_nG6_analyze.uid='.$analyse_id,
'GROUPBY' => '',
'ORDERBY' => 'tx_nG6_analyze.name',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$result = array();
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$result = array(
'project_name' => $row['project_name'],
'project_id' => $row['project_id'],
'run_name' => $row['run_name'],
'run_id' => $row['run_id'],
'directory' => $row['analyze_directory'],
'name' => $row['analyze_name'],
'date' => $row['analyze_date'],
'description' => $row['analyze_description']
);
}
return $result;
}
}
/*
* User functions
*------------------------------------------------------------*/
/**
* Return the supergroups list of the specified group
*
* @param string $group the group
* @return array
*/
function get_super_groups_of ($group) {
// First get the super group of the given group
$queryParts = array(
'SELECT' => 'uid, subgroup',
'FROM' => 'fe_groups',
'WHERE' => '',
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$reslist = array();
$i = 0;
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
if (in_array($group, t3lib_div::intExplode(',',$row['subgroup']))) {
$reslist[$i] = $row['uid'];
$i++;
}
}
return $reslist;
}
/**
* Returns a string with user groups separated by comas
*
* @param string $user_group the user group
* @return string list of user groups splited by a coma
*/
function get_user_groups($user_group) {
$tab_groups = array();
tx_nG6_db::get_sub_groups($user_group, '', $tab_groups);
$groups = '';
foreach($tab_groups as $valeur) { $groups .= $valeur.','; }
return substr($groups, 0, -1);
}
/**
* Fetches subgroups of groups. Function is called recursively for each subgroup.
* Function was previously copied from t3lib_userAuthGroup->fetchGroups and has been slightly modified.
*
* @param string $grList commalist of fe_groups uid numbers
* @param string $idList list of already processed fe_groups-uids so the function will not fall into a eternal recursion.
* @return array
*/
function get_sub_groups($grList, $idList='', &$groups) {
// Fetching records of the groups in $grList (which are not blocked by lockedToDomain either):
$lockToDomain_SQL = ' AND (lockToDomain=\'\' OR lockToDomain IS NULL)';
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,subgroup', 'fe_groups', 'deleted=0 AND hidden=0 AND uid IN ('.$grList.')'.$lockToDomain_SQL);
$groupRows = array(); // Internal group record storage
// The groups array is filled
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
if(!in_array($row['uid'], $groups)) { $groups[] = $row['uid']; }
$groupRows[$row['uid']] = $row;
}
// Traversing records in the correct order
$include_staticArr = t3lib_div::intExplode(',', $grList);
foreach($include_staticArr as $uid) { // traversing list
// Get row:
$row=$groupRows[$uid];
if (is_array($row) && !t3lib_div::inList($idList,$uid)) { // Must be an array and $uid should not be in the idList, because then it is somewhere previously in the grouplist
// Include sub groups
if (trim($row['subgroup'])) {
$theList = implode(',',t3lib_div::intExplode(',',$row['subgroup'])); // Make integer list
tx_nG6_db::get_sub_groups($theList, $idList.','.$uid, $groups); // Call recursively, pass along list of already processed groups so they are not recursed again.
}
}
}
}
/**
* Return if the user is authorized or not to access the specified project and run
*
* @param string $user_group the user group
* @param string $project_id the project id
* @param string $project_id the run id
* @return boolean
*/
function user_is_authorized ($user_group, $project_id, $run_id) {
if ($project_id) {
$queryParts = array(
'SELECT' => 'fe_group',
'FROM' => 'tx_nG6_project',
'WHERE' => 'uid='.$project_id,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$authorized_group = $val['fe_group'];
} elseif ($run_id) {
$queryParts = array(
'SELECT' => 'project_id',
'FROM' => 'tx_nG6_project_run',
'WHERE' => 'run_id='.$run_id,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res1 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res1);
$queryParts = array(
'SELECT' => 'fe_group',
'FROM' => 'tx_nG6_project',
'WHERE' => 'uid='.$val['project_id'],
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res2 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
$authorized_group = $val['fe_group'];
} else {
return true;
}
if (!$GLOBALS['TSFE']->loginUser) { // If the user is not logged on
return $authorized_group == 0;
} else {
return in_array($authorized_group, preg_split("/,/", tx_nG6_db::get_user_groups($user_group)));
}
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_db.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_db.php']);
}
?>
<?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!
***************************************************************/
/**
* An easy way to keep in track of external processes.
* Ever wanted to execute a process in php, but you still wanted to have somewhat controll of the process ? Well.. This is a way of doing it.
* @compability: Linux only. (Windows does not work).
*
* @author: Peec
*/
class Process{
private $pid;
private $command;
public function __construct($cl=false){
if ($cl != false){
$this->command = $cl;
$this->runCom();
}
}
private function runCom(){
$command = 'nohup '.$this->command.' > /dev/null 2>&1 & echo $!';
exec($command ,$op);
$this->pid = (int)$op[0];
}
public function setPid($pid){
$this->pid = $pid;
}
public function getPid(){