Commit 7573f92a authored by Jerome Mariette's avatar Jerome Mariette
Browse files

add delete and publish functions

parent 4f7c77cf
......@@ -131,79 +131,110 @@ class tx_nG6_eid {
} else if ($type == 'hide') {
$ids = trim(t3lib_div::_GP('ids'));
$hide_level = trim(t3lib_div::_GP('hide_level')); //{project/run}
//{project/run}_id to array (1;2;3;...) -> [1;2;3;...]
// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
$tab_ids = explode(";",$ids);
// hide
$to_hide = '1';
$hide_level = trim(t3lib_div::_GP('hide_level'));
foreach($tab_ids as $p_id => $p_value) {
// Execute query
tx_nG6_db::change_hide_status($p_value, $to_hide, $hide_level);
// Hide subgroups (project -> runs -> analyzes)
$this->change_child_hide_status($user_group, $p_value, $to_hide, $hide_level);
if ($hide_level == 'project') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::hide_project($value, $user_group);
}
} else if ($hide_level == 'run') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::hide_run($value, $user_group);
}
} else if ($hide_level == 'analysis') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::hide_analysis($value, $user_group);
}
}
// If asked to unhide a {project/run}
} else if ($type == 'unhide') {
$ids = trim(t3lib_div::_GP('ids'));
$hide_level = trim(t3lib_div::_GP('hide_level')); //{project/run}
//{project/run}_id to array (1;2;3;...) -> [1;2;3;...]
// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
$tab_ids = explode(";",$ids);
// unhide
$to_hide = '0';
foreach($tab_ids as $p_id => $p_value) {
// Execute query
tx_nG6_db::change_hide_status($p_value, $to_hide, $hide_level);
// Unhide subgroups (project -> runs -> analyzes)
$this->change_child_hide_status($user_group, $p_value, $to_hide, $hide_level);
$unhide_level = trim(t3lib_div::_GP('unhide_level'));
if ($unhide_level == 'project') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::unhide_project($value, $user_group);
}
} else if ($unhide_level == 'run') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::unhide_run($value, $user_group);
}
} else if ($unhide_level == 'analysis') {
foreach($tab_ids as $id => $value) {
tx_nG6_db::unhide_analysis($value, $user_group);
}
}
}
// If asked to delete a {project/run/analyze}
} else if ($type == 'delete') {
}
$ids = trim(t3lib_div::_GP('ids'));
// {project/run}_id to array (1;2;3;...) -> [1;2;3;...]
$tab_ids = explode(";",$ids);
$delete_level = trim(t3lib_div::_GP('del_level'));
$data_folder = trim(t3lib_div::_GP('data_folder'));
$user_login = trim(t3lib_div::_GP('user_login'));
$user_pwd = trim(t3lib_div::_GP('user_pwd'));
/**
* Hide/unhide inherits rights from a run/project
*
* @param string $user_group the user group
* @param string $pr_id {project/run} id
* @param string $hide_status hide status {'1' (hide)/ '0' (unhide)}
* @param string $pr_choice point of view choice {'project'/'run'}
*/
function change_child_hide_status($user_group, $pr_id, $hide_status, $pr_choice) {
if ($pr_choice == 'project') {
$res = 0;
// check login and password
if (isset($user_login) && isset($user_pwd) && $user_login != 'undefined' && $user_pwd != 'undefined') {
$res = 0;
$connection = ssh2_connect('127.0.0.1', 22);
if (!$connection) { $res = 3; }
if (!ssh2_auth_password($connection, $user_login, $user_pwd)) { $res=2;}
} else {
$res = 3;
}
// First, All project runs
$project_runs = tx_nG6_db::get_project_runs($user_group, $pr_id);
foreach($project_runs as $run_id => $run_values) {
tx_nG6_db::change_hide_status($run_values['id'], $hide_status, 'run');
// All run analyzes
$run_analysis = tx_nG6_db::get_run_analysis($user_group, $run_values['id']);
foreach($run_analysis as $analyse_id => $analyze_values) {
tx_nG6_db::change_hide_status($analyze_values['id'], $hide_status, 'analyze');
}
if ($res == 0) {
if ($delete_level == 'project') {
foreach($tab_ids as $id => $value) {
$res = tx_nG6_db::delete_project($user_group, $value, $user_login, $user_pwd, $data_folder);
if ($res != 0) { break; }
}
} else if ($delete_level == 'run') {
foreach($tab_ids as $id => $value) {
$res = tx_nG6_db::delete_run($user_group, $value, $user_login, $user_pwd, $data_folder);
if ($res != 0) { break; }
}
} else if ($delete_level == 'analysis') {
foreach($tab_ids as $id => $value) {
$res = tx_nG6_db::delete_analysis($value, $user_login, $user_pwd, $data_folder);
if ($res != 0) { break; }
}
}
}
print $res;
// All project analysis
$project_analysis = tx_nG6_db::get_project_analysis($user_group, $pr_id);
foreach($project_analysis as $analyse_id => $analyze_values) {
tx_nG6_db::change_hide_status($analyze_values['id'], $hide_status, 'analyze');
}
// If asked to publish a project
} else if ($type == 'publish') {
$ids = trim(t3lib_div::_GP('ids'));
// project_id to array (1;2;3;...) -> [1;2;3;...]
$tab_ids = explode(";",$ids);
foreach($tab_ids as $id => $value) {
tx_nG6_db::publish_project($value, $user_group);
}
// If asked to unpublish a project
} else if ($type == 'unpublish') {
$ids = trim(t3lib_div::_GP('ids'));
// project_id to array (1;2;3;...) -> [1;2;3;...]
$tab_ids = explode(";",$ids);
foreach($tab_ids as $id => $value) {
tx_nG6_db::unpublish_project($value);
}
}
} elseif ($pr_choice == 'run') {
// All run analysis
$run_analysis = tx_nG6_db::get_run_analysis($user_group, $pr_id);
foreach($run_analysis as $analyse_id => $analyze_values) {
tx_nG6_db::change_hide_status($analyze_values['id'], $hide_status, 'analyze');
}
}
}
}
/**
* Creates an archiving script to archive data from ids
......
......@@ -20,7 +20,7 @@ $TCA["tx_nG6_project"] = Array (
"iconfile" => t3lib_extMgm::extRelPath($_EXTKEY)."icon_tx_nG6_project.gif",
),
"feInterface" => Array (
"fe_admin_fieldList" => "hidden, fe_group, name, description",
"fe_admin_fieldList" => "hidden, public, fe_group, name, description",
)
);
......
......@@ -9,6 +9,7 @@ CREATE TABLE tx_nG6_project (
cruser_id int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
public tinyint(4) DEFAULT '1' NOT NULL,
fe_group int(11) DEFAULT '0' NOT NULL,
name varchar(255) DEFAULT '' NOT NULL,
description varchar(255) DEFAULT '' NOT NULL,
......
......@@ -47,7 +47,7 @@ class tx_nG6_db {
$projects = array();
// If the user is not logged on display demonstration project
if (!$GLOBALS['TSFE']->loginUser) {
$where = 'fe_group=0';
$where = 'public=0';
} else {
$where = 'fe_group IN ('.tx_nG6_db::get_user_groups($user_group).')';
}
......@@ -57,6 +57,7 @@ class tx_nG6_db {
'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.public AS project_public, '.
'tx_nG6_project.hidden AS project_hidden',
'FROM' => 'tx_nG6_project',
'WHERE' => $where,
......@@ -86,6 +87,7 @@ class tx_nG6_db {
'id' => $project_id,
'name' => $row['project_name'],
'hidden' => $row['project_hidden'],
'public' => $row['project_public'],
'group' => $row['project_fe_group'],
'description' => $row['project_description']);
}
......@@ -252,6 +254,120 @@ class tx_nG6_db {
return $results;
}
/**
* Hide a project and sublevels (runs & analyzes) datas from database project
*
* @param string $p_id the project id to hide
* @param string $user_group the group of the current user
*/
function hide_project($p_id, $user_group) {
// First change all project runs
$project_runs = tx_nG6_db::get_project_runs($user_group, $p_id);
foreach($project_runs as $run_id => $run_values) {
tx_nG6_db::hide_run($run_values['id'], $user_group);
}
// Then all project analysis
$project_analysis = tx_nG6_db::get_project_analysis($user_group, $p_id);
foreach($project_analysis as $analysis_id => $analysis_values) {
tx_nG6_db::hide_analysis($analysis_values['id']);
}
// Finaly change the project itself
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_project', 'uid='.$p_id, array('hidden' => '1'));
}
/**
* Unhide a project and sublevels (runs & analyzes) datas
*
* @param string $p_id the project id to hide
* @param string $user_group the group of the current user
*/
function unhide_project($p_id, $user_group) {
// First change all project runs
$project_runs = tx_nG6_db::get_project_runs($user_group, $p_id);
foreach($project_runs as $run_id => $run_values) {
tx_nG6_db::unhide_run($run_values['id'], $user_group);
}
// Then all project analysis
$project_analysis = tx_nG6_db::get_project_analysis($user_group, $p_id);
foreach($project_analysis as $analysis_id => $analysis_values) {
tx_nG6_db::unhide_analysis($analysis_values['id']);
}
// Finaly change the project itself
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_project', 'uid='.$p_id, array('hidden' => '0'));
}
/**
* Publish the project
*
* @param string $p_id the project id to publish
*/
function publish_project($p_id, $user_group) {
// First unhide the project
tx_nG6_db::unhide_project($p_id, $user_group);
// The set the project as visible
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_project', 'uid='.$p_id, array('public' => '0'));
}
/**
* Unpublish the project
*
* @param string $p_id the project id to publish
*/
function unpublish_project($p_id) {
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_project', 'uid='.$p_id, array('public' => '1'));
}
/**
* Delete a project and sublevels (runs & analyzes) datas from database project
*
* @param string $user_group the user group
* @param string $p_id the project id
* @param string $user_login the user login
* @param string $user_pwd the user password
* @param string $data_folder the data folder
*/
function delete_project($user_group, $p_id, $user_login, $user_pwd, $data_folder) {
$res = 0;
// All runs
$project_runs = tx_nG6_db::get_project_runs($user_group, $p_id);
foreach($project_runs as $run_id => $run_values) {
if ($run_values['id'] != 'undefined' && $run_values['id'] != '') {
//delete the run sublevels
$res = tx_nG6_db::delete_run($user_group, $run_values['id'], $user_login, $user_pwd, $data_folder);
if ($res != 0) { break; }
}
}
// All project_analysis
if ($res == 0) {
$project_analysis = tx_nG6_db::get_project_analysis($user_group, $p_id);
foreach($project_analysis as $analyse_id => $analyze_values) {
if ($analyze_values['id'] != 'undefined' && $analyze_values['id'] != '') {
// delete table 'analyze' entries
$res = tx_nG6_db::delete_analysis($analyze_values['id'], $user_login, $user_pwd, $data_folder);
if ($res != 0) { break; }
}
}
}
// Delete DB project entry
if ($res == 0) {
$table='tx_nG6_project';
$where='tx_nG6_project.uid='.$p_id;
$res1 = $GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
if ($res1 != 1) {$res = 1;}
}
return $res;
}
/*
* Run functions
......@@ -267,7 +383,7 @@ class tx_nG6_db {
// If the user is not logged on display demonstration project
if (!$GLOBALS['TSFE']->loginUser) {
$where = 'fe_group=0';
$where = 'public=0';
} else {
$where = 'fe_group IN ('.tx_nG6_db::get_user_groups($user_group).')';
}
......@@ -484,9 +600,95 @@ class tx_nG6_db {
return $results;
}
/**
* Delete a run, sample and sublevel (analyzes) datas from database project
*
* @param string $user_group the user group
* @param string $r_id the run id
* @param string $user_login the user login
* @param string $user_pwd the user password
* @param string $data_folder the data folder
*/
function delete_run($user_group, $r_id, $user_login, $user_pwd, $data_folder) {
$res = 0;
$run_analysis = tx_nG6_db::get_run_analysis($user_group, $r_id);
foreach($run_analysis as $analyse_id => $analyze_values) {
if ($analyze_values['id'] != 'undefined' && $analyze_values['id'] != '') {
// delete table 'analyze' entries
$res = tx_nG6_db::delete_analysis($analyze_values['id'], $user_login, $user_pwd, $data_folder);
if ($res != 0) { break; }
}
}
// First select the run
$my_run = tx_nG6_db::select_run($r_id);
// delete run
if ($res == 0) {
$table='tx_nG6_project_run';
$where='run_id='.$r_id;
$GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
$table='tx_nG6_run';
$where='tx_nG6_run.uid='.$r_id;
$res1 = $GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
if ($res1 != 1) {$res = 1;}
}
// delete run samples
if ($res == 0) {
$table='tx_nG6_sample';
$where='tx_nG6_sample.run_id='.$r_id;
$GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
}
if ($res == 0) {
// Delete the run directory
$res = tx_nG6_utils::delete_directory($user_login, $user_pwd, $data_folder.$my_run['directory']);
}
return $res;
}
/**
* Hide a run and sublevels (analysis)
*
* @param string $r_id the run id to hide
* @param string $user_group the group of the current user
*/
function hide_run($r_id, $user_group) {
// First select all run analysis
$run_analysis = tx_nG6_db::get_run_analysis($user_group, $r_id);
foreach($run_analysis as $analysis_id => $analysis_values) {
tx_nG6_db::hide_analysis($analysis_values['id']);
}
// Finaly change the project itself
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_run', 'uid='.$r_id, array('hidden' => '1'));
}
/**
* Unhide a run and sublevels (analysis)
*
* @param string $r_id the run id to hide
* @param string $user_group the group of the current user
*/
function unhide_run($r_id, $user_group) {
// Then all run analysis
$run_analysis = tx_nG6_db::get_run_analysis($user_group, $r_id);
foreach($run_analysis as $analysis_id => $analysis_values) {
tx_nG6_db::unhide_analysis($analysis_values['id']);
}
// Finaly change the run itself
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_run', 'uid='.$r_id, array('hidden' => '0'));
}
/*
* Analyze functions
* Analysis functions
*------------------------------------------------------------*/
/**
......@@ -610,7 +812,71 @@ class tx_nG6_db {
}
return $result;
}
/**
* Hide an analysis
*
* @param string $a_id the analysis id to hide
*/
function hide_analysis($a_id) {
// Change the analysis itself
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_analyze', 'uid='.$a_id, array('hidden' => '1'));
}
/**
* Unhide an analysis
*
* @param string $a_id the analysis id to hide
* @param string $user_group the group of the current user
*/
function unhide_analysis($a_id) {
// Change the analysis itself
$GLOBALS['TYPO3_DB']-> exec_UPDATEquery ('tx_nG6_analyze', 'uid='.$a_id, array('hidden' => '0'));
}
/**
* Delete an analyze and results from database project
*
* @param string $a_id the analyze id
* @param string $user_login the user login
* @param string $user_pwd the user password
* @param string $data_folder the data folder
* @return 0=>everything ok, 1=>user right problem, 2=>wrong authentification, 3=>connection error
*/
function delete_analysis($a_id, $user_login, $user_pwd, $data_folder) {
$res = 0;
// First select the analyse
$my_analysis = tx_nG6_db::select_analyse($a_id);
// Delete the analysis results from the database
$table='tx_nG6_result';
$where='tx_nG6_result.analyze_id='.$a_id;
$GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
// Intermediate tables
$table='tx_nG6_project_analyze';
$where='analyze_id='.$a_id;
$GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
$table='tx_nG6_run_analyze';
$where='analyze_id='.$a_id;
$GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
// Finaly the analysis itself
$table='tx_nG6_analyze';
$where='tx_nG6_analyze.uid='.$a_id;
$res1 = $GLOBALS['TYPO3_DB']-> exec_DELETEquery ($table, $where);
if ($res1 != 1) { $res = 1; }
if ($res == 0) {
// Delete the analyse directory
$res = tx_nG6_utils::delete_directory($user_login, $user_pwd, $data_folder.$my_analysis['directory']);
}
return $res;
}
/*
* User functions
......@@ -729,9 +995,10 @@ class tx_nG6_db {
* @return boolean
*/
function user_is_authorized ($user_group, $project_id, $run_id) {
$authorized = false;
if ($project_id) {
$queryParts = array(
'SELECT' => 'fe_group',
'SELECT' => 'fe_group,public',
'FROM' => 'tx_nG6_project',
'WHERE' => 'uid='.$project_id,
'GROUPBY' => '',
......@@ -740,7 +1007,11 @@ class tx_nG6_db {
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$authorized_group = $val['fe_group'];
if ($GLOBALS['TSFE']->loginUser) {
$authorized = in_array($val['fe_group'], preg_split("/,/", tx_nG6_db::get_user_groups($user_group)));
} else {
$authorized = ($val['public'] == 0);
}
} elseif ($run_id) {
$queryParts = array(
'SELECT' => 'project_id',
......@@ -753,7 +1024,7 @@ class tx_nG6_db {
$res1 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res1);
$queryParts = array(
'SELECT' => 'fe_group',
'SELECT' => 'fe_group,public',
'FROM' => 'tx_nG6_project',
'WHERE' => 'uid='.$val['project_id'],
'GROUPBY' => '',
......@@ -762,15 +1033,15 @@ class tx_nG6_db {
);
$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;
if ($GLOBALS['TSFE']->loginUser) {
$authorized = in_array($val['fe_group'], preg_split("/,/", tx_nG6_db::get_user_groups($user_group)));
} else {
$authorized = ($val['public'] == 0);
}
} else {
return in_array($authorized_group, preg_split("/,/", tx_nG6_db::get_user_groups($user_group)));
$authorized = true;
}
return $authorized;
}
/**
......@@ -829,35 +1100,59 @@ class tx_nG6_db {
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$queryParts = array(
'SELECT' => 'project_id',
'FROM' => 'tx_nG6_project_run',
'WHERE' => 'run_id='.$val['run_id'],
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res2 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
$queryParts = array(
'SELECT' => 'fe_group',
'FROM' => 'tx_nG6_project',
'WHERE' => 'uid='.$val['project_id'],
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res3 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res3);
$authorized_group = $val['fe_group'];
if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$queryParts = array(
'SELECT' => 'project_id',
'FROM' => 'tx_nG6_project_run',
'WHERE' => 'run_id='.$val['run_id'],
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res2 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
$queryParts = array(
'SELECT' => 'fe_group',
'FROM'