class.tx_nG6_pi6.php 15.7 KB
Newer Older
Jerome Mariette's avatar
Jerome Mariette committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?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!
***************************************************************/
/**
 * 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;
40

Jerome Mariette's avatar
Jerome Mariette committed
41
42
43
44
45
46
47
48
49
50
51
52
53
	/**
	 * 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'];
		}
54

Jerome Mariette's avatar
Jerome Mariette committed
55
56
57
58
		$this->pi_loadLL();
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_USER_INT_obj=1;
59
                
Jerome Mariette's avatar
Jerome Mariette committed
60
61
		// Add the jquery libs + the tree plugins and its css
		$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] = '
Penom Nom's avatar
Penom Nom committed
62
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.min.js"></script>
63
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/highstock.js"></script>
Jerome Mariette's avatar
Jerome Mariette committed
64
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.highcharts.exporting.js"></script>
Jerome Mariette's avatar
Jerome Mariette committed
65
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.dataTables.min.js"></script>
Penom Nom's avatar
Penom Nom committed
66
67
68
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/bootstrap.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/dataTables.bootstrap.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/typeahead.bundle.js"></script>
Penom Nom's avatar
Penom Nom committed
69
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jflow.min.js"></script>
Penom Nom's avatar
Penom Nom committed
70
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/tx_nG6_utils.js"></script>
Penom Nom's avatar
Penom Nom committed
71
72
73
74
75
76
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/tx_nG6_pi6.js"></script>
					
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/bootstrap-theme.min.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/dataTables.bootstrap.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/typeaheadjs.css"/>	
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/font-awesome.css"/>
Penom Nom's avatar
Penom Nom committed
77
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jflow.min.css"/>
Jerome Mariette's avatar
Jerome Mariette committed
78
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/tx_nG6.css"/>';
Jerome Mariette's avatar
Jerome Mariette committed
79
80
81
82
83
84
85
86
87

		$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');

Jerome Mariette's avatar
Jerome Mariette committed
88
89
90
		$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']);
91
                $smarty->assign('user_name', $GLOBALS['TSFE']->fe_user->user['username']);
Jerome Mariette's avatar
Jerome Mariette committed
92
93
		$smarty->assign('group_list', $group_list);
		$smarty->assign('data_folder', $this->conf["data"]);
94
		$smarty->assign('server_url', $this->conf['server_url']);
95
                $smarty->assign('server_name', $this->conf["server_name"]);
96
                
97
98
		$distribution = tx_nG6_db::select_projects_repartition('create_user', 'title');
		$smarty->assign('distribution', $distribution);
Penom Nom's avatar
Penom Nom committed
99
		$smarty->assign('ng6_admin_users', tx_nG6_db::get_ng6_admin_users() );
100
               
101
		$smarty->assign('ng6_purge_delay',$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['delay_purge']);
Celine Noirot's avatar
Celine Noirot committed
102
103
		$txNG6Utils = new tx_nG6_utils;
		$smarty->assign_by_ref('tx_nG6_utils', $txNG6Utils);
Jerome Mariette's avatar
Jerome Mariette committed
104
105
		return $smarty->fetch('administration_view.tpl');
	}
106
107
        
        function send_purge_demand_mail($user_id,$project_ids)	{
108
                 $template_mail=  'Mail automatique / en phase de TEST
Celine Noirot's avatar
Celine Noirot committed
109
Dear user,
110

Celine Noirot's avatar
Celine Noirot committed
111
The two years data storage time limit of your ###PROJECT_NAME### project (###nb_run### run(s) and ###nb_analyse### analyse(s)) is coming to end. 
112

Celine Noirot's avatar
Celine Noirot committed
113
This purge alert No ###DEMAND_ID### corresponds to ###STORAGE_SIZE### (see below files impacted).
114

Celine Noirot's avatar
Celine Noirot committed
115
116
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 prices (http://bioinfo.genotoul.fr/index.php/resources-2/pricing/) and reply to this email with the following information:
----------------------------------------------
117
118
119
120
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: 
Celine Noirot's avatar
Celine Noirot committed
121
----------------------------------------------
122

123
###EMAILS###It would be appreciable if you could group your demand by laboratory.
Celine Noirot's avatar
Celine Noirot committed
124

125
Yours sincerely
Celine Noirot's avatar
Celine Noirot committed
126
nG6 team (for GeT-Genotoul and Bioinfo-Genotoul facilities)
127

Celine Noirot's avatar
Celine Noirot committed
128
129
130
Files impacted of:
- runs names: 	###RUNS_LIST###
- analyses ids:	###ANALYSES_LIST###
131
';
Celine Noirot's avatar
Celine Noirot committed
132
133
134
                $project_name="";
                $txNG6Utils = new tx_nG6_utils;
                foreach(explode(",", $project_ids) as $project_id){
135
                        #retrieve project data
Celine Noirot's avatar
Celine Noirot committed
136
137
                        $p=tx_nG6_db::select_a_project_retention_data_info($project_id);
                
138
                        #build email list of managers
139
140
                        $users_names=array();
								$users_emails = array();
Celine Noirot's avatar
Celine Noirot committed
141
                        foreach ( $p[$project_id]["users"] as  $u ){
142
143
144
145
146
147
                        	if (!isset ($users_names[$u["right_level_label"]]) ){
                        		$users_names[$u["right_level_label"]]=Array();
                        		$users_emails[$u["right_level_label"]]=Array();
                        	}
                           $users_names[$u["right_level_label"]][] = $u["user_name"];
                           $users_emails[$u["right_level_label"]][] = $u["email"];
148
149
                        }      
                        #Warn if mail is sent to several manager
150
                        
151
152
                        $email_warn="" ;
                        $purge_email_to="";
153
154
155
156
157
158
159
160
161
162
163
164
165
166
                        $purge_name_to=Array();
                        if ( count( $users_emails['manager']) >= 1 ) {
                        		if ( count( $users_emails['manager']) > 1 ) {
                                	$email_warn="Be aware that this project is associated to several managers (all recieved this email), please send only one answer per purge alert number.\n";
                                }
                                $purge_email_to=join(',', $users_emails['manager']);
                                $purge_name_to=$users_names['manager'];
                        } elseif ( count($users_emails['manager']) == 0) {
                      	  $purge_email_to=join(', ', array_merge($users_emails['administrator'],$users_emails['member']));
                      	  $purge_name_to=array_merge($users_names['administrator'],$users_names['member']);
								  $email_warn="As this project do not have managers, administrators and members recieved this alert.\n";
								  $email_warn.=  " - Administrator(s): ".join(', ',$users_emails['administrator']). "\n";
								  $email_warn.=  " - Members(s): ".join(', ',$users_emails['member']). "\n";                             
								}
Celine Noirot's avatar
Celine Noirot committed
167
                        //Retrieve purgeable information for email
168
                        $run_info=Array();
Celine Noirot's avatar
Celine Noirot committed
169
                        
170
                        //ici bug car on prend l'ensemble des runs/analyses du projets 
Celine Noirot's avatar
Celine Noirot committed
171
172
173
174
175
176
177
                        $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);
178
                                $run_name = $run["name"];    
179
                                $run_info[]= $run["name"]." ($run_id)";
180
181
182
                        }
                        
                        #Add purge demand to get id
183
                        $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,$purge_name_to);
184
185
186
187
                        
                        #Build corresponding string array                        
                        $search=array("###nb_run###","###nb_analyse###","###PROJECT_NAME###","###PROJET_ID###","###DEMAND_ID###",
                                                "###EMAILS###","###RUNS_LIST###","###ANALYSES_LIST###","###STORAGE_SIZE###", 
188
                                                "###EXTENSION_DURATION###","###EXTENSION_SIZE###","###EXTENSION_URL_PRICES###","###PURGE_DELAY###");
Celine Noirot's avatar
Celine Noirot committed
189
                        $replace=array($nb_run_purgeable,$nb_analyse_purgeable,$p[$project_id]["project_name"],$project_id, $purge_demand_id ,
190
                                                $email_warn, join(', ', $run_info), join(', ', $all_purgeable_analysis), tx_nG6_utils::get_octet_string_representation($p[$project_id]["total_purgeable_size"] ),
191
                                                $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['min_extension_duration'],$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['min_extension_size'],
192
                                                $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['extension_url_price'],$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['delay_purge']);
193
194
195
                        
                        $mail=str_replace($search, $replace, $template_mail);
                        
196
                        $to      =   $purge_email_to;
Celine Noirot's avatar
Celine Noirot committed
197
                        $subject = '[nG6 purge] No '.$purge_demand_id.' - Project '.$p[$project_id]["project_name"];
198
                        $headers[] = 'From: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['email_from'];
199
                        $headers[] = 'X-Mailer: PHP/' . phpversion();
200
                        #TODO Uncomment
Celine Noirot's avatar
Celine Noirot committed
201
                        $to      =   "celine.noirot@inra.fr";
202
                        mail($to, $subject, $mail, implode("\r\n", $headers));
203
			}	
204
                return implode("\r\n", $headers).$mail;
205
        }
Celine Noirot's avatar
Celine Noirot committed
206
 
Celine Noirot's avatar
Celine Noirot committed
207
208
        function extend_rentention_date($demand_ids, $date){
                //extend
Celine Noirot's avatar
Celine Noirot committed
209
210
211
212
213
214
215
216
217
218
                $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"]));
                        }
                }
Celine Noirot's avatar
Celine Noirot committed
219
220
221
222
223
224
225
226
227
228
229
230
231
232
                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");
                
        }
233
         function delete_purge_demand($demand_ids,$user_login, $user_pwd, $data_folder){
Celine Noirot's avatar
Celine Noirot committed
234
                $date= time();
235
                $all_demands=tx_nG6_db::get_purge_demand_from_id($demand_ids);
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
                $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;
                                }
257
258
                        }
                }
259
260
261
                # finally set purge demand as purged
                if ($res == 0){
                        tx_nG6_db::update_field('tx_nG6_purge_demand',explode(',',$demand_ids),
262
                        array("processed_date","demand_state"),
263
264
265
                        array($date,"purged"));
                }
                return $res;
Celine Noirot's avatar
Celine Noirot committed
266
267
        }
             
Jerome Mariette's avatar
Jerome Mariette committed
268
269
270
271
272
273
}

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']);
}

274
?>