Commit facbcf96 authored by Celine Noirot's avatar Celine Noirot

#23 + refactor move pi6 php functions to db + move pi6 js fonction to utils.js...

#23 + refactor move pi6 php functions to db + move pi6 js fonction to utils.js + externalize email function in preparation of resend email
parent 224deb60
......@@ -857,6 +857,11 @@ class tx_nG6_eid {
//Change date format
print json_encode(tx_nG6_db::filter_list_retention_data_info($filter_size,$max_retention_date,$create_users, $without_laboratories_id,$with_laboratories_id));
} elseif ($type == 'purge_managment_resend_mail') {
$purge_ids = trim(t3lib_div::_GP('purge_demand'));
$data_folder = trim(t3lib_div::_GP('user_id'));
print json_encode(tx_nG6_pi6::resend_purge_demand_mail($user_id,$purge_demand));
} elseif ($type == 'delete_purge_data') {
//TODO recuperer user password et faire comme pour pi1
if ($user_id == ""){
......@@ -878,7 +883,7 @@ class tx_nG6_eid {
$res = 3;
}
if ($res == 0) {
$res = tx_nG6_pi6::delete_purge_demand($purge_ids,$user_login, $user_pwd, $data_folder);
$res = tx_nG6_db::delete_purge_demand($purge_ids,$user_login, $user_pwd, $data_folder);
}
print $res;
}
......@@ -894,7 +899,7 @@ class tx_nG6_eid {
//Change date format
$date = explode('/', $value);
$timestamp = mktime (0, 0, 1, $date[1], $date[0], $date[2]);
print json_encode(tx_nG6_pi6::extend_retention_date(explode(',',$purge_ids),$timestamp,$type_extend));
print json_encode(tx_nG6_db::extend_retention_date(explode(',',$purge_ids),$timestamp,$type_extend));
}
}
......
......@@ -429,7 +429,90 @@ INNER JOIN fe_groups ON fe_groups.uid = fe_users.usergroup',
return ($results);
}
function extend_retention_date($demand_ids, $date, $type_extend){
//TODO extend thanks to the type
//extend
$all_demands=tx_nG6_db::get_purge_demand_from_id( join(', ', $demand_ids));
$all_runs=array();
$all_analyses=array();
foreach($all_demands as $res){
if ($res["state"] != "deleted")
{
if ($type_extend == 'extend_all_project') {
//extend all project
$curr_project_id=$res["project_id"];
$all_project_filter = " project_id =".$curr_project_id. " AND DATEDIFF( FROM_UNIXTIME( retention_date ), FROM_UNIXTIME(" .$date. ") ) <0
AND state in ('extended','stored') ";
// get all info of a project even non obsolete run analyse (by TRUE parameter)
$res_project_analyze = tx_nG6_db::select_all_in_view("tx_nG6_view_project_analyze", $all_project_filter);
$res_project_run = tx_nG6_db::select_all_in_view("tx_nG6_view_project_run", $all_project_filter);
$res_project_run_analyze = tx_nG6_db::select_all_in_view("tx_nG6_view_project_run_analyze", $all_project_filter);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_project_analyze)) {
$all_analyses[] = $res_row["analyze_id"];
}
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_project_run_analyze)) {
$all_analyses[] = $res_row["analyze_id"];
}
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_project_run)) {
$all_runs[] = $res_row["run_id"];
}
} else {
$all_analyses=array_merge($all_analyses,explode(',',$res["analyze_ids"]));
$all_runs=array_merge($all_runs,explode(',',$res["run_ids"]));
}
}
}
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");
}
function delete_purge_demand($demand_ids,$user_login, $user_pwd, $data_folder){
$date= time();
$all_demands=tx_nG6_db::get_purge_demand_from_id($demand_ids);
$directories=array();
$res = 0 ;
foreach($all_demands as $demand){
if ($demand["state"] != "deleted"){
foreach(explode(',',$demand["analyze_ids"]) as $a_id){
$res = tx_nG6_db::purge_analysis($a_id, $user_login, $user_pwd, $data_folder);
if ($res != 0) {
break;
}
}
if ($res == 0) {
foreach(explode(',',$demand["run_ids"]) as $r_id){
$res = tx_nG6_db::purge_run($r_id, $user_login, $user_pwd, $data_folder);
if ($res != 0) {
break;
}
}
}
else {
break;
}
}
}
# finally set purge demand as purged
if ($res == 0){
tx_nG6_db::update_field('tx_nG6_purge_demand',explode(',',$demand_ids),
array("processed_date","demand_state"),
array($date,"purged"));
}
return $res;
}
/**
* Select all project for the current user
*
......
......@@ -178,6 +178,49 @@ class tx_nG6_utils {
return $value;
}
function get_purge_email($project_name, $project_id, $nb_run_purgeable,$nb_analyse_purgeable, $demand_id,
$purgeable_size, $project_size, $purge_delay, $url_price, $min_extention_duration,
$min_extention_size, $emails, $runs_list, $analyse_list) {
$template_mail= 'Mail automatique / en phase de TEST
Dear user,
The two years data storage period of your ###PROJECT_NAME### project (###nb_run### run(s) and ###nb_analyse### analyse(s)) is ended.
This purge alert No ###DEMAND_ID### corresponds to ###PURGEABLE_SIZE### purgeable data on ###PROJECT_SIZE### of whole project see list of impacted files below.
In ###PURGE_DELAY### days, your data will be deleted. Keep us informed if you wish to extend the storage period,
please have a look at our storage fees (###URL_PRICE###) and reply to this email with the following information:
----------------------------------------------
Demand number: ###DEMAND_ID###
Request for extension term: XXX (minimal unit: ###EXTENSION_DURATION###)
Request for extension size: XXX (mininal unit: ###EXTENSION_SIZE###)
Laboratory name/Institution:
----------------------------------------------
###EMAILS###We would appreciate if you could group your demands by laboratory.
Yours sincerely
nG6 team (for GeT-Genotoul and Bioinfo-Genotoul facilities)
Files impacted of:
- runs names: ###RUNS_LIST###
- analyses ids: ###ANALYSES_LIST###
';
$search=array("###nb_run###","###nb_analyse###","###PROJECT_NAME###","###PROJET_ID###","###DEMAND_ID###",
"###EMAILS###","###RUNS_LIST###","###ANALYSES_LIST###","###PURGEABLE_SIZE###", "###PROJECT_SIZE###",
"###EXTENSION_DURATION###","###EXTENSION_SIZE###","###URL_PRICE###","###PURGE_DELAY###");
$replace=array($nb_run_purgeable,$nb_analyse_purgeable,$project_name,$project_id, $demand_id ,
$emails, $runs_list, $analyse_list, $purgeable_size,$project_size,
$min_extention_duration, $min_extention_size, $url_price, $purge_delay);
$mail=str_replace($search, $replace, $template_mail);
return $mail;
}
/**
* hash password (using default encryption method)
* @param string $password
......
......@@ -433,6 +433,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<th align="left" colspan="7">
With selection :
<div class="btn-group">
<button id="btn_demand_resend_mail" type="button" class="btn btn-sm btn-default" ><i class="glyphicon glyphicon-remove"></i> Resend mail</button>
<button id="btn_demand_delete_data" type="button" class="btn btn-sm btn-default" ><i class="glyphicon glyphicon-remove"></i> Delete data</button>
<button id="btn_demand_retention" type="button" class="btn btn-sm btn-default"><i class="glyphicon glyphicon-pencil"></i> Extend retention date </button>
</div>
......
This diff is collapsed.
......@@ -383,10 +383,29 @@ $(function () {
},
error: function(returnval){
//TODO Afficher alerte en cas d'erreur de mail
return "Error mail sending"+returnval;
$('#data_table_obsolete_wait').hide();
$('#obsolete_list').show();
$("#purge_demand_error").html("<div class='tx-nG6-pi6-error'>Error mail sending.</div>");
$("#purge_demand_error").show();
}
});
});
//resend email
$("#btn_demand_resend_mail").click(function(){
var demands = getDatatableCheckedValue(purge_table["demand"], "demand");
$.ajax({
url: "index.php?eID=tx_nG6&type=purge_managment_resend_mail&purge_demand="+demands.join(',')+"&user_id="+$('input[id=user_id]').val(),
dataType: 'json',
success: function(val, status, xhr) {
refresh_project_obsolete(purge_table["obsolete"]);
refresh_purge_demand(purge_table["demand"]);
},
error: function(returnval){
//TODO Afficher alerte en cas d'erreur de mail
$("#modal-body-tmpl").html("<div class='tx-nG6-pi6-error'>Error mail sending.</div>");
}
});
})
// Delete data after selecting list of ids demand
$("#btn_demand_delete_data").click(function(){
......@@ -412,10 +431,7 @@ $(function () {
$("#ng6modal").modal();
var demands = [];
$("#modal-btn-purge").click( function() {
$(':checked[id^=chk_demand').each(function(){
demand_id=$(this).val();
demands.push(demand_id);
});
demands = getDatatableCheckedValue(purge_table["demand"], "demand");
var val_url = "index.php?eID=tx_nG6&type=delete_purge_data&purge_demand=" + demands.join(',');
val_url += "&user_login=" + $("#user_login_val").val() + "&user_pwd=" + $("#user_pwd_val").val();
val_url += "&user_id="+$("#user_id").val() +"&data_folder=" + $("#data_folder").val() ;
......@@ -475,9 +491,9 @@ $(function () {
$('input[id^=chk_'+type+']').prop('checked', chk_status);
//updateDatatableButton(purge_table[type],type);
});
});
});
function extend_date(list_ids, purge_demand_datatable, obsolete_project_datatable){
function extend_date(list_ids, purge_demand_datatable, obsolete_project_datatable){
if(list_ids == ""){
window.alert("You must select or enter purge demand. ");
return 0;
......@@ -522,8 +538,7 @@ function extend_date(list_ids, purge_demand_datatable, obsolete_project_datatabl
error: function(val) {
//TO PRINT ERROR
$("#ng6modal").modal('hide');
refresh_purge_demand(purge_demand_datatable);
refresh_project_obsolete(obsolete_project_datatable);
}
});
......@@ -579,7 +594,7 @@ function extend_date(list_ids, purge_demand_datatable, obsolete_project_datatabl
});
}
function refresh_project_obsolete(obsolete_project_datatable){
function refresh_project_obsolete(obsolete_project_datatable){
$('#data_table_obsolete_wait').show();
$('#obsolete_list').hide();
......@@ -676,7 +691,7 @@ function refresh_project_obsolete(obsolete_project_datatable){
}
});
}
}
/*
* Retrieve checked values for data managment
*/
......@@ -722,22 +737,6 @@ function set_active_tab(active_tab){
}
}
function get_octet_string_representation (size, round) {
var octets_link = new Array("bytes", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb"),
p = parseInt(Math.ceil(parseFloat(size.toString().length)/parseFloat(3) - parseFloat(1))),
pow_needed = p * 10;
pow_needed = Math.pow(2, pow_needed);
value = parseFloat(size)/parseFloat(pow_needed);
var tmp = value.toString().split(".");
if (tmp.length > 1 && round > 0) {
value = tmp[0] + "." + tmp[1].slice(0, round);
} else if (tmp.length > 1 && round == 0) {
value = tmp[0];
}
value = value + " " + octets_link[p];
return value;
}
function getDatatableCheckedValue(stat_tables){
var values = new Array(),
......@@ -755,6 +754,7 @@ function getDatatableCheckedValue(stat_tables){
return values
}
function drawProjectDistribution(stat_tables) {
var $group_by = $("input[type=radio][name=group_by]:checked"),
group_by = $group_by.val(),
......@@ -808,7 +808,7 @@ function drawProjectEvolution(stat_tables){
var $group_by = $("input[type=radio][name=group_by]:checked"),
group_by = $group_by.val(),
real_group = $group_by.attr('id').split('_')[1],
role = $("input[type=radio][name=users_to_consider]:checked").val(),
role = $("input[type=radio][name=users_to_consider]:checked").val(),
values = getDatatableCheckedValue(stat_tables),
cumulate = $("#chk_cumulate")[0].checked ? "1" : "0" ;
......@@ -839,7 +839,7 @@ function drawProjectEvolution(stat_tables){
credits: { enabled: false },
series: [{name: "number of project", data: val}]
});
}
}
});
}
......@@ -853,47 +853,47 @@ function drawDataDistribution(stat_tables){
analysis = $("#chk_includes_analyses").attr("checked") == "checked" ? "1" : "0";
$.ajax({
url: "index.php?eID=tx_nG6&type=data_distribution&by="+group_by+"&role="+role+"&get_analyzes="+analysis+"&bases="+bases+"&values="+values.join(","),
dataType: 'json',
success: function(val, status, xhr) {
// reformat the data with values to integer
for (var i=0; i <val.length; i++ ) {
val[i][1] = parseInt(val[i][1]);
}
$('#highcharts_graph').highcharts({
chart: {
width: 930
},
title: {
text: 'Data storage size gathered by ' + real_group
},
tooltip: {
formatter: function() {
return '<b>'+ get_octet_string_representation(this.point.y, 2)+'</b> ('+Highcharts.numberFormat(this.percentage, 2)+'%)' ;
url: "index.php?eID=tx_nG6&type=data_distribution&by="+group_by+"&role="+role+"&get_analyzes="+analysis+"&bases="+bases+"&values="+values.join(","),
dataType: 'json',
success: function(val, status, xhr) {
// reformat the data with values to integer
for (var i=0; i <val.length; i++ ) {
val[i][1] = parseInt(val[i][1]);
}
,shared: true
},
credits: { enabled: false },
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name + '</b>';
$('#highcharts_graph').highcharts({
chart: {
width: 930
},
title: {
text: 'Data storage size gathered by ' + real_group
},
tooltip: {
formatter: function() {
return '<b>'+ get_octet_string_representation(this.point.y, 2)+'</b> ('+Highcharts.numberFormat(this.percentage, 2)+'%)' ;
}
,shared: true
},
credits: { enabled: false },
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name + '</b>';
}
}
}
}
}
},
series: [{
type: 'pie',
data: val
}]
});
}
},
series: [{
type: 'pie',
data: val
}]
});
}
});
}
......
......@@ -62,4 +62,20 @@ function key_gen(size) {
*/
function resize(elt, ratio) {
elt.width = ratio*elt.width ;
}
\ No newline at end of file
}
function get_octet_string_representation (size, round) {
var octets_link = new Array("bytes", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb"),
p = parseInt(Math.ceil(parseFloat(size.toString().length)/parseFloat(3) - parseFloat(1))),
pow_needed = p * 10;
pow_needed = Math.pow(2, pow_needed);
value = parseFloat(size)/parseFloat(pow_needed);
var tmp = value.toString().split(".");
if (tmp.length > 1 && round > 0) {
value = tmp[0] + "." + tmp[1].slice(0, round);
} else if (tmp.length > 1 && round == 0) {
value = tmp[0];
}
value = value + " " + octets_link[p];
return value;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment