class.tx_nG6_pi6.php 12 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
91
92
		$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('group_list', $group_list);
		$smarty->assign('data_folder', $this->conf["data"]);
93
		$smarty->assign('server_url', $this->conf['server_url']);
94
                
95
96
		$distribution = tx_nG6_db::select_projects_repartition('create_user', 'title');
		$smarty->assign('distribution', $distribution);
Penom Nom's avatar
Penom Nom committed
97
		$smarty->assign('ng6_admin_users', tx_nG6_db::get_ng6_admin_users() );
98
99
100
101
102
103
               
                $this->projects_obsolete=tx_nG6_db::select_obsolete_list_retention_data_info();
		$smarty->assign('ng6_purge_projects',$this->projects_obsolete);
                $this->ng6_purge_demands=tx_nG6_db::get_purge_demand_list($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['delay_purge']);
                
                $smarty->assign('ng6_purge_demands',$this->ng6_purge_demands);
Celine Noirot's avatar
Celine Noirot committed
104
105
		$txNG6Utils = new tx_nG6_utils;
		$smarty->assign_by_ref('tx_nG6_utils', $txNG6Utils);
Jerome Mariette's avatar
Jerome Mariette committed
106
107
		return $smarty->fetch('administration_view.tpl');
	}
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
        
        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="";
                 
                foreach(explode(",", $project_ids) as $id){
                        #retrieve project data
                        $p=tx_nG6_db::select_a_project_retention_data_info($id);
                        
                        #build email list of managers
                        $managers_email=Array();
                        $managers_name=Array();
                        $admin_email = Array();
                        $admin_name = Array();
                        foreach ( $p[$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 manager (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="This project isn't associated to manager, as administrator (".join(',', $admin_email).")of this project you recieved this purge alert \n";
                                $purge_email_to=join(',', $admin_email);
                        }
                        
                        $run_info=""; 
                        $run_list =split(",", $p[$id]["state"]["stored"]["run_ids"]);
                        if(count($run_list) != 0){
                                for( $i=0;$i<count($run_list);$i++){
                                        $run = tx_nG6_db::select_run($run_list[$i]);
                                        $run_name = $run["name"];    
                                        $run_info .= "$run_name ($run_list[$i]), ";
                                }
                        }else{
                                $run = tx_nG6_db::select_run($run_list);
                                $run_name = $run["name"];    
                                $run_info .= "$run_name ($run_list[$i]), ";
                        }
                        
                        $analysis_list = $p[$id]["state"]["stored"]["analysis_ids"];
                        
                        #Add purge demand to get id
                        $add_id = tx_nG6_db::add_purge_demand($user_id,$id,$p[$id]["total_purgeable_size"],$p[$id]["state"]["stored"]["run_ids"],$analysis_list,$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($p[$id]["state"]["stored"]["nb_run"],$p[$id]["state"]["stored"]["nb_analyze"],$p[$id]["project_name"],$id,$add_id ,
                                                $email_warn, $run_info , $analysis_list, $p[$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 '.$add_id.' - Project '.$p[$id]["project_name"];
                        $headers[] = 'From: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['purge_email_from'];
                        #$headers[] = 'Cc: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['purge_email_from'];
                        $headers[] = 'Reply-To: '.$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ng6']['purge_email_from'];
                        $headers[] = 'X-Mailer: PHP/' . phpversion();
                        
                        #mail($to, $subject, $mail, implode("\r\n", $headers));
                        return    $headers  ;
		}
                return $mail;
        }
Jerome Mariette's avatar
Jerome Mariette committed
203
204
205
206
207
208
}

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

209
?>