* 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(PATH_tslib.'class.tslib_pibase.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_utils.php');
require_once(t3lib_extMgm::extPath('nG6').'/lib/class.tx_nG6_db.php');
require_once(t3lib_extMgm::extPath('nG6').'/res/smarty/libs/Smarty.class.php');
class tx_nG6_pi6 extends tslib_pibase {
var $prefixId = 'tx_nG6_pi6'; // Same as class name
var $scriptRelPath = 'pi6/class.tx_nG6_pi6.php'; // Path to this script relative to the extension dir.
var $extKey = 'nG6'; // The extension key.
//var $pi_checkCHash = TRUE;
/**
* 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) {
if (strstr($this->cObj->currentRecord,'tt_content')) {
$conf['pidList'] = $this->cObj->data['pages'];
$conf['recursive'] = $this->cObj->data['recursive'];
}
$this->pi_loadLL();
$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_USER_INT_obj=1;
// Add the jquery libs + the tree plugins and its css
$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] = '
';
$smarty = new Smarty();
$smarty->setTemplateDir(t3lib_extMgm::extPath('nG6').'/pi6');
$smarty->setCompileDir(t3lib_extMgm::extPath('nG6').'/res/smarty/templates_c');
$smarty->setCacheDir(t3lib_extMgm::extPath('nG6').'/res/smarty/cache');
$smarty->setConfigDir(t3lib_extMgm::extPath('nG6').'/res/smarty/configs');
$smarty->security = true;
$smarty->security_settings['MODIFIER_FUNCS'] = array('count');
$group_list = tx_nG6_db::get_group_list();
$smarty->assign('login_user', $GLOBALS['TSFE']->loginUser);
$smarty->assign('user_id', $GLOBALS['TSFE']->fe_user->user['uid']);
$smarty->assign('user_name', $GLOBALS['TSFE']->fe_user->user['username']);
$smarty->assign('group_list', $group_list);
$smarty->assign('data_folder', $this->conf["data"]);
$smarty->assign('server_url', $this->conf['server_url']);
$distribution = tx_nG6_db::select_projects_repartition('create_user', 'title');
$smarty->assign('distribution', $distribution);
$smarty->assign('ng6_admin_users', tx_nG6_db::get_ng6_admin_users() );
$smarty->assign('ng6_purge_delay',$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['delay_purge']);
$txNG6Utils = new tx_nG6_utils;
$smarty->assign_by_ref('tx_nG6_utils', $txNG6Utils);
return $smarty->fetch('administration_view.tpl');
}
function send_purge_demand_mail($user_id,$project_ids) {
$template_mail= 'Dear user,
The data storage time limit of ###nb_run### run(s) and ###nb_analyse### analyse(s) of ###PROJECT_NAME### project (###PROJET_ID###) is coming to end.
This purge alert number ###DEMAND_ID### corresponds to the files (size : ###STORAGE_SIZE###) linked to the following
* runs names: ###RUNS_LIST###
* analyses ids: ###ANALYSES_LIST###
In ###PURGE_DELAY### days, your data will be delete. Until then, you can save them by your own, or ask for extention period with number ###DEMAND_ID###.
###EMAILS###Keep us informed if you wish to extend the storage so that we do not delete the data by error, by answering to this email with following this informations :
Demand number : ###DEMAND_ID###
Extension term (min ###EXTENSION_DURATION###) :
Extension size (min ###EXTENSION_SIZE###) :
Price for ###EXTENSION_SIZE### during ###EXTENSION_DURATION### is about ###EXTENSION_PRICE###.
Yours sincerely
nG6 team';
$project_name="";
$txNG6Utils = new tx_nG6_utils;
foreach(explode(",", $project_ids) as $project_id){
#retrieve project data
$p=tx_nG6_db::select_a_project_retention_data_info($project_id);
#build email list of managers
$managers_email=Array();
$managers_name=Array();
$admin_email = Array();
$admin_name = Array();
foreach ( $p[$project_id]["users"] as $u ){
if ( $u["right_level_label"] == "manager" ){
$managers_email[]=$u["email"];
$managers_name[]=$u["user_name"];
}elseif( $u["right_level_label"] == "administrator"){
$admin_email[] = $u["email"];
$admin_name[] = $u["user_name"];
}
}
#Warn if mail is sent to several manager
$email_warn="" ;
$purge_email_to="";
if ( count($managers_email) > 1 ) {
$email_warn="This project is associated to several managers (all recieved this email), please send only one answer per purge alert number.(".join(',', $managers_email).")\n";
$purge_email_to=join(',', $managers_email);
}elseif ( count($managers_email ==0)) {
$email_warn="As this project do not have managers, administrators recieved this alert (".join(',', $admin_email).")\n";
$purge_email_to=join(',', $admin_email);
}
//Retrieve purgeable information for email
$run_info="";
$all_purgeable_runs=array_merge($p[$project_id]["state"]["stored"]["run_ids"],$p[$project_id]["state"]["extended"]["run_ids"]);
$all_purgeable_analysis=array_merge($p[$project_id]["state"]["stored"]["analysis_ids"],$p[$project_id]["state"]["extended"]["analysis_ids"]);
$nb_run_purgeable = $p[$project_id]["state"]["stored"]["nb_run"]+ $p[$project_id]["state"]["extended"]["nb_run"];
$nb_analyse_purgeable = $p[$project_id]["state"]["stored"]["nb_analyze"]+ $p[$project_id]["state"]["extended"]["nb_analyze"];
//Retrieve run name
foreach($all_purgeable_runs as $run_id ){
$run = tx_nG6_db::select_run($run_id);
$run_name = $run["name"];
$run_info .= $run["name"]." ($run_id), ";
}
#Add purge demand to get id
$purge_demand_id = tx_nG6_db::add_purge_demand($user_id,$project_id,$p[$project_id]["total_purgeable_size"],$all_purgeable_runs,$all_purgeable_analysis,$managers_name);
#Build corresponding string array
$search=array("###nb_run###","###nb_analyse###","###PROJECT_NAME###","###PROJET_ID###","###DEMAND_ID###",
"###EMAILS###","###RUNS_LIST###","###ANALYSES_LIST###","###STORAGE_SIZE###",
"###EXTENSION_DURATION###","###EXTENSION_SIZE###","###EXTENSION_PRICE###","###PURGE_DELAY###");
$replace=array($nb_run_purgeable,$nb_analyse_purgeable,$p[$project_id]["project_name"],$project_id, $purge_demand_id ,
$email_warn, $run_info , $analysis_list, tx_nG6_utils::get_octet_string_representation($p[$project_id]["total_purgeable_size"] ),
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['min_extension_duration'],$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['min_extension_size'],
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['min_extension_price'],$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['delay_purge']);
$mail=str_replace($search, $replace, $template_mail);
$to = $purge_email_to;
$subject = '[nG6 purge] No '.$purge_demand_id.' - Project '.$p[$project_id]["project_name"];
$headers[] = 'From: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['email_from'];
#$headers[] = 'Cc: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['email_from'];
$headers[] = 'Reply-To: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['email_from'];
$headers[] = 'X-Mailer: PHP/' . phpversion();
#TODO Uncomment
mail($to, $subject, $mail, implode("\r\n", $headers));
//return $headers ;
}
return implode("\r\n", $headers).$mail;
}
function set_purge_demand_processed($demand_ids,$process, $value,$user,$pwd){
$all_demands=tx_nG6_db::get_purge_demand_from_id($demand_ids);
$all_runs=array();
$all_analyses=array();
foreach($all_demands as $res){
if ($res["state"] != "deleted")
{
$all_analyses=array_merge($all_analyses,explode(',',$res["analyze_ids"]));
$all_runs=array_merge($all_runs,explode(',',$res["run_ids"]));
}
}
//extend
if ($process == "extend"){
$date=$value;
tx_nG6_db::update_field('tx_nG6_run', $all_runs,
array("retention_date","data_state", "mail_sent_date","purge_demand_id"),
array($date,"extended","","NULL"),
array("purge_demand_id"));
tx_nG6_db::update_field('tx_nG6_analyze',$all_analyses,
array("retention_date","data_state", "mail_sent_date","purge_demand_id"),
array($date,"extended","","NULL"),
array("purge_demand_id"));
tx_nG6_db::update_field('tx_nG6_purge_demand',$demand_ids,
array("processed_date","demand_state"),
array($date,"extended"));
return("Done extend");
}else{ //delete
$data_folder=$value;
$date= time();
$all_runs_purged=array();
$all_analyses_purged=array();
if ( $connexion )
{
//purged_size = storage_size !!!
tx_nG6_db::update_field('tx_nG6_run', $all_runs_purged, array("purged_size","data_state", "purged_date", "storage_size"),
array("storage_size","purged",$date, 0),
array("purged_size"));
tx_nG6_db::update_field('tx_nG6_analyze',$all_analyses_purged, array("purged_size","data_state", "purged_date", "storage_size"),
array("storage_size","purged",$date, 0),
array("purged_size"));
if (count($all_runs_purged)==count($all_runs) and count($all_analyses_purged)==count($all_analyses)){
tx_nG6_db::update_field('tx_nG6_purge_demand',$demand_ids,
array("processed_date","demand_state"),
array($date,"deleted"));
return("Done delete, res : ".$res);
}else{
return("Error: not all runs or analyses were purged , please check unix permission (see apache logs).");
}
}else{
return("Error while ssh login.");
}
}
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/pi6/class.tx_nG6_pi6.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/pi6/class.tx_nG6_pi6.php']);
}
?>