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 { ...@@ -131,79 +131,110 @@ class tx_nG6_eid {
} else if ($type == 'hide') { } else if ($type == 'hide') {
$ids = trim(t3lib_div::_GP('ids')); $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); $tab_ids = explode(";",$ids);
// hide $hide_level = trim(t3lib_div::_GP('hide_level'));
$to_hide = '1';
foreach($tab_ids as $p_id => $p_value) { if ($hide_level == 'project') {
// Execute query foreach($tab_ids as $id => $value) {
tx_nG6_db::change_hide_status($p_value, $to_hide, $hide_level); tx_nG6_db::hide_project($value, $user_group);
// Hide subgroups (project -> runs -> analyzes) }
$this->change_child_hide_status($user_group, $p_value, $to_hide, $hide_level); } 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} // If asked to unhide a {project/run}
} else if ($type == 'unhide') { } else if ($type == 'unhide') {
$ids = trim(t3lib_div::_GP('ids')); $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); $tab_ids = explode(";",$ids);
$unhide_level = trim(t3lib_div::_GP('unhide_level'));
// unhide
$to_hide = '0'; if ($unhide_level == 'project') {
foreach($tab_ids as $id => $value) {
foreach($tab_ids as $p_id => $p_value) { tx_nG6_db::unhide_project($value, $user_group);
// Execute query }
tx_nG6_db::change_hide_status($p_value, $to_hide, $hide_level); } else if ($unhide_level == 'run') {
// Unhide subgroups (project -> runs -> analyzes) foreach($tab_ids as $id => $value) {
$this->change_child_hide_status($user_group, $p_value, $to_hide, $hide_level); 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'));
/** $res = 0;
* Hide/unhide inherits rights from a run/project // check login and password
* if (isset($user_login) && isset($user_pwd) && $user_login != 'undefined' && $user_pwd != 'undefined') {
* @param string $user_group the user group $res = 0;
* @param string $pr_id {project/run} id $connection = ssh2_connect('127.0.0.1', 22);
* @param string $hide_status hide status {'1' (hide)/ '0' (unhide)} if (!$connection) { $res = 3; }
* @param string $pr_choice point of view choice {'project'/'run'} if (!ssh2_auth_password($connection, $user_login, $user_pwd)) { $res=2;}
*/ } else {
function change_child_hide_status($user_group, $pr_id, $hide_status, $pr_choice) { $res = 3;
}
if ($pr_choice == 'project') {
// First, All project runs if ($res == 0) {
$project_runs = tx_nG6_db::get_project_runs($user_group, $pr_id); if ($delete_level == 'project') {
foreach($project_runs as $run_id => $run_values) { foreach($tab_ids as $id => $value) {
tx_nG6_db::change_hide_status($run_values['id'], $hide_status, 'run'); $res = tx_nG6_db::delete_project($user_group, $value, $user_login, $user_pwd, $data_folder);
if ($res != 0) { break; }
// All run analyzes }
$run_analysis = tx_nG6_db::get_run_analysis($user_group, $run_values['id']); } else if ($delete_level == 'run') {
foreach($run_analysis as $analyse_id => $analyze_values) { foreach($tab_ids as $id => $value) {
tx_nG6_db::change_hide_status($analyze_values['id'], $hide_status, 'analyze'); $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 // If asked to publish a project
$project_analysis = tx_nG6_db::get_project_analysis($user_group, $pr_id); } else if ($type == 'publish') {
foreach($project_analysis as $analyse_id => $analyze_values) {
tx_nG6_db::change_hide_status($analyze_values['id'], $hide_status, 'analyze'); $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 * Creates an archiving script to archive data from ids
......
...@@ -20,7 +20,7 @@ $TCA["tx_nG6_project"] = Array ( ...@@ -20,7 +20,7 @@ $TCA["tx_nG6_project"] = Array (
"iconfile" => t3lib_extMgm::extRelPath($_EXTKEY)."icon_tx_nG6_project.gif", "iconfile" => t3lib_extMgm::extRelPath($_EXTKEY)."icon_tx_nG6_project.gif",
), ),
"feInterface" => Array ( "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 ( ...@@ -9,6 +9,7 @@ CREATE TABLE tx_nG6_project (
cruser_id int(11) DEFAULT '0' NOT NULL, cruser_id int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL, deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden 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, fe_group int(11) DEFAULT '0' NOT NULL,
name varchar(255) DEFAULT '' NOT NULL, name varchar(255) DEFAULT '' NOT NULL,
description varchar(255) DEFAULT '' NOT NULL, description varchar(255) DEFAULT '' NOT NULL,
......
...@@ -47,7 +47,7 @@ class tx_nG6_db { ...@@ -47,7 +47,7 @@ class tx_nG6_db {
$projects = array(); $projects = array();
// If the user is not logged on display demonstration project // If the user is not logged on display demonstration project
if (!$GLOBALS['TSFE']->loginUser) { if (!$GLOBALS['TSFE']->loginUser) {
$where = 'fe_group=0'; $where = 'public=0';
} else { } else {
$where = 'fe_group IN ('.tx_nG6_db::get_user_groups($user_group).')'; $where = 'fe_group IN ('.tx_nG6_db::get_user_groups($user_group).')';
} }
...@@ -57,6 +57,7 @@ class tx_nG6_db { ...@@ -57,6 +57,7 @@ class tx_nG6_db {
'tx_nG6_project.name AS project_name, '. 'tx_nG6_project.name AS project_name, '.
'tx_nG6_project.description AS project_description, '. 'tx_nG6_project.description AS project_description, '.
'tx_nG6_project.fe_group AS project_fe_group, '. 'tx_nG6_project.fe_group AS project_fe_group, '.
'tx_nG6_project.public AS project_public, '.
'tx_nG6_project.hidden AS project_hidden', 'tx_nG6_project.hidden AS project_hidden',
'FROM' => 'tx_nG6_project', 'FROM' => 'tx_nG6_project',
'WHERE' => $where, 'WHERE' => $where,
...@@ -86,6 +87,7 @@ class tx_nG6_db { ...@@ -86,6 +87,7 @@ class tx_nG6_db {
'id' => $project_id, 'id' => $project_id,
'name' => $row['project_name'], 'name' => $row['project_name'],
'hidden' => $row['project_hidden'], 'hidden' => $row['project_hidden'],
'public' => $row['project_public'],
'group' => $row['project_fe_group'], 'group' => $row['project_fe_group'],
'description' => $row['project_description']); 'description' => $row['project_description']);
} }
...@@ -252,6 +254,120 @@ class tx_nG6_db { ...@@ -252,6 +254,120 @@ class tx_nG6_db {
return $results; 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 * Run functions
...@@ -267,7 +383,7 @@ class tx_nG6_db { ...@@ -267,7 +383,7 @@ class tx_nG6_db {
// If the user is not logged on display demonstration project // If the user is not logged on display demonstration project
if (!$GLOBALS['TSFE']->loginUser) { if (!$GLOBALS['TSFE']->loginUser) {
$where = 'fe_group=0'; $where = 'public=0';
} else { } else {
$where = 'fe_group IN ('.tx_nG6_db::get_user_groups($user_group).')'; $where = 'fe_group IN ('.tx_nG6_db::get_user_groups($user_group).')';
} }
...@@ -484,9 +600,95 @@ class tx_nG6_db { ...@@ -484,9 +600,95 @@ class tx_nG6_db {
return $results; 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 { ...@@ -610,7 +812,71 @@ class tx_nG6_db {
} }
return $result; 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 * User functions
...@@ -729,9 +995,10 @@ class tx_nG6_db { ...@@ -729,9 +995,10 @@ class tx_nG6_db {
* @return boolean * @return boolean
*/ */
function user_is_authorized ($user_group, $project_id, $run_id) { function user_is_authorized ($user_group, $project_id, $run_id) {
$authorized = false;
if ($project_id) { if ($project_id) {
$queryParts = array( $queryParts = array(
'SELECT' => 'fe_group', 'SELECT' => 'fe_group,public',
'FROM' => 'tx_nG6_project', 'FROM' => 'tx_nG6_project',
'WHERE' => 'uid='.$project_id, 'WHERE' => 'uid='.$project_id,
'GROUPBY' => '', 'GROUPBY' => '',
...@@ -740,7 +1007,11 @@ class tx_nG6_db { ...@@ -740,7 +1007,11 @@ class tx_nG6_db {
); );
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $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) { } elseif ($run_id) {
$queryParts = array( $queryParts = array(
'SELECT' => 'project_id', 'SELECT' => 'project_id',
...@@ -753,7 +1024,7 @@ class tx_nG6_db { ...@@ -753,7 +1024,7 @@ class tx_nG6_db {
$res1 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); $res1 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res1); $val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res1);
$queryParts = array( $queryParts = array(
'SELECT' => 'fe_group', 'SELECT' => 'fe_group,public',
'FROM' => 'tx_nG6_project', 'FROM' => 'tx_nG6_project',
'WHERE' => 'uid='.$val['project_id'], 'WHERE' => 'uid='.$val['project_id'],
'GROUPBY' => '', 'GROUPBY' => '',
...@@ -762,15 +1033,15 @@ class tx_nG6_db { ...@@ -762,15 +1033,15 @@ class tx_nG6_db {