class.tx_nG6_pi5.php 15.2 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?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');

class tx_nG6_pi5 extends tslib_pibase {
	var $prefixId = 'tx_nG6_pi5';		// Same as class name
	var $scriptRelPath = 'pi5/class.tx_nG6_pi5.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;		 

		return $this->pi_wrapInBaseClass($this->pi_form_view());
	}

	function pi_form_view () {

		// add the jquery libs + the tree plugins and its css
		$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] = '
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.js"></script> 
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.cookie.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.hotkeys.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.jstree.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.ui.core.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.ui.dialog.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.ui.draggable.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.ui.resizable.min.js"></script> 
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.bgiframe.min.js"></script>
			<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/js/jquery.url.packed.js"></script>
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.core.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.theme.css"/>
			<link type="text/css" rel="stylesheet" media="screen" href="'.t3lib_extMgm::siteRelPath($this->extKey).'res/css/jquery.ui.dialog.css"/>';

Jerome Mariette's avatar
Jerome Mariette committed
78

Jerome Mariette's avatar
Jerome Mariette committed
79
		// Sets the page content
Jerome Mariette's avatar
Jerome Mariette committed
80
81
82
		// First get the temp url :
		$tmp_url = substr($this->conf["temp"], strpos($this->conf["temp"], "fileadmin"));

83
		$content = '<h2>'.$this->getFieldHeader('title').'</h2>';
Jerome Mariette's avatar
Jerome Mariette committed
84
85
86
87
88
89
90
91
92
93
94
95
		$content .= '<script type="text/javascript" class="source">
						$(function () {
						    $("#download_tree").jstree({
								"themes" : {
									"theme" : "default",
									"icons" : false
								},
						        "html_data" : {
						            "data" : $("#html_tree").attr("value"),
						            "ajax" : {
						            	"url" : "index.php?eID=tx_nG6",
						            	"data" : function (n) {
96
97
98
99
100
101
102
											return {
												raw_data_label : "'.$this->getFieldHeader('raw_data_label').'",
												run_printing : "'.$this->getFieldHeader('run_description').'",
												analyse_printing : "'.$this->getFieldHeader('analyse_description').'",
												id : n.attr("id").split("_")[1],
												type : n.attr("id").split("_")[0]
											};
Jerome Mariette's avatar
Jerome Mariette committed
103
104
105
106
						            	}
						            }
						        },
						        "plugins" : [ "themes", "html_data", "ui", "checkbox" ]
Jerome Mariette's avatar
Jerome Mariette committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
						    }).bind("change_state.jstree", function(event, data) {
							var nb_selected = 0;
							$("#download_list").html("<ul>");
							$(".jstree-checked > ul > .jstree-checked, .jstree-undetermined > ul > .jstree-checked").each(function(){
                                                        	nb_selected += 1;
								if ($(this).attr("id").split("_")[0] == "run") {
									$("#download_list > ul").append("<li>"+$(this).attr("id")+"</li>");
									//alert($(this).html());
								} else if ($(this).attr("id").split("_")[0] == "analyse") {
									$("#download_list > ul").append("<li>"+$(this).html()+"</li>");
									//alert($(this).html());
								}
                                                        });
						 	if (nb_selected == 0) {
								$("#download_btn").addClass("tx-nG6-pi5-download-disable");
								$("#download_list > ul").append("<li>'.$this->getFieldHeader('download_list_no_select').'</li>");
							} else {
								$("#download_btn").removeClass("tx-nG6-pi5-download-disable");
							}
Jerome Mariette's avatar
Jerome Mariette committed
126
127
128
129
130
131
132
133
134
135
136
137
						    });
						  	$("#download_dialog").dialog({
						    	autoOpen: false,
						    	bgiframe: true,
						    	resizable: false,
						    	position: "center",
						    	modal: true,
						    	overlay: {
						      		backgroundColor: "#000",
						      		opacity: 0.5
						    	}
						  	});
Jerome Mariette's avatar
Jerome Mariette committed
138
139
140
141
142
143
144
145
146
147


						    $("#download_btn").click(function() {
							if (!$(this).hasClass("tx-nG6-pi5-download-disable")) {
						    		var url_val = "index.php?eID=tx_nG6&type=download&data_folder='.$this->conf["data"].'&tmp_folder='.$this->conf["temp"].'&ids=";
						    		$(".jstree-checked > ul > .jstree-checked, .jstree-undetermined > ul > .jstree-checked").each(function(){
						    			url_val += $(this).attr("id")+";";
						    		});
						    		$("#download_dialog").dialog("option", "title", "'.$this->getFieldHeader('download_dialog_title').'");
						    		$("#download_dialog").html(\'<img src="fileadmin/templates/nG6template/images/light_wait.gif"/> '.$this->getFieldHeader('download_dialog_msg').'\').dialog("open");
Jerome Mariette's avatar
Jerome Mariette committed
148
							  	$.ajax({
Jerome Mariette's avatar
Jerome Mariette committed
149
150
151
							    		url: url_val,
							    		success: function(val) {
							      			$("#download_dialog").dialog("close");
Jerome Mariette's avatar
Jerome Mariette committed
152
										location.href = "'.$tmp_url.'/"+val;
Jerome Mariette's avatar
Jerome Mariette committed
153
							    		}
Jerome Mariette's avatar
Jerome Mariette committed
154
							  	});
Jerome Mariette's avatar
Jerome Mariette committed
155
						    	  } 
Jerome Mariette's avatar
Jerome Mariette committed
156
						    });
Jerome Mariette's avatar
Jerome Mariette committed
157
							
Jerome Mariette's avatar
Jerome Mariette committed
158
159
160
161
162
						});
					</script> ';

		// Build the lists of all elements */
		$arrayProject = $this->get_project_list();
Jerome Mariette's avatar
Jerome Mariette committed
163
164
					
		$html_tree = "<input type='hidden' name = 'html_tree' id='html_tree'  value='";
Jerome Mariette's avatar
Jerome Mariette committed
165
		foreach($arrayProject as $project_id => $project_array) {   
Jerome Mariette's avatar
Jerome Mariette committed
166
167
			$html_tree .= "<li class=\"jstree-closed\" id=\"".$project_id."\"> <a href=\"#\">".
					str_replace(array('###SPAN_NAME###'), array($project_array['name']), $this->getFieldHeader('project_description'))."</a></li>";
Jerome Mariette's avatar
Jerome Mariette committed
168
		} 
Jerome Mariette's avatar
Jerome Mariette committed
169
		$html_tree .= "' />";
Jerome Mariette's avatar
Jerome Mariette committed
170

Jerome Mariette's avatar
Jerome Mariette committed
171
172
173
174
175
176
177
		$content .= '<div '.$this->pi_classParam('download-builder-tree').'> <div '.$this->pi_classParam('download-builder-header').'> <h3> <img src="'.t3lib_extMgm::siteRelPath($this->extKey).'res/img/download_builder.png" alt="" width="91" height="88" />'.$this->getFieldHeader('msg').'</h3></div> <div id="download_dialog" title=""></div>'.$html_tree;
		$content .= '<div id="download_tree"></div></div>';
		$content .= '<div '.$this->pi_classParam('download-builder').'> ';
		$content .= '<div '.$this->pi_classParam('download-builder-group').'> <h2>'.$this->getFieldHeader('download_list_title').'<h2> <div id="download_list"> <ul><li>'.$this->getFieldHeader('download_list_no_select').'</li></ul></div></div>';
		$content .= '<div '.$this->pi_classParam('download-builder-group').'> <h2>'.$this->getFieldHeader('download_format_title').'</h2>';
		$content .= '<input type="radio" name="format" value="tar.gz"> .tar.gz <br /><input type="radio" name="format" value="zip"> .zip</div>';
		$content .= '<div '.$this->pi_classParam('download-builder-group').' style="border-bottom: 0;margin-top: 0;margin-bottom:0;padding-bottom:0;"> <input class="tx-nG6-pi5-download tx-nG6-pi5-download-disable" id="download_btn" type="button" value="'.$this->getFieldHeader('download_btn_label').'" /> </div> </div>';
Jerome Mariette's avatar
Jerome Mariette committed
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
		return $content;
	}
	
	function get_project_list() {
		
		$results = array();
		
		// If the user is not logged on display demonstration project
		if (!$GLOBALS['TSFE']->loginUser) { 
			$where = 'fe_group=0';
		} else {
			$where = 'fe_group IN ('.$this->getCurrentUserGroups().')';	
		}
		
		//First, get the analyzis project-scale
		$queryParts = array( 
			'SELECT' => 'tx_nG6_project.uid AS project_id, '.
						'tx_nG6_project.name AS project_name, '.
						'tx_nG6_project.description AS project_description',
			'FROM' => 'tx_nG6_project',
			'WHERE' => $where,
			'GROUPBY' => '',
			'ORDERBY' => '',
			'LIMIT' => ''
		); 
		
		$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))
		{
			
			$project_id = $row['project_id'];
			$analyze_id = $row['analyze_id'];
			$analyze_content = array( 
				'directory'					=> $row['directory'], 
				'name' 						=> $row['analyze_name'],
				'date'						=> $row['analyze_date'],
				'description' 				=> $row['analyse_description']				
			);
				
			if (! isset ($results['project_'.$project_id]) ) //new project
			{				
				$results['project_'.$project_id] = array(
					'id'				=> $project_id,				
					'name'			=> $row['project_name'],
					'description'	=> $row['project_description'],
					'contents'		=> Array() );
			}
			//then add content	
			$results['project_'.$project_id]['contents']['analyze'.$analyze_id] = $analyze_content;							
		}
		return $results;
	}
	
	/**
	 * Returns the content of a given field
	 *
	 * @param	string		$fN: name of table field
	 * @return	Value of the field
	 */
	function getFieldContent($fN, $mergeArr=array())	{
		switch($fN) {
			case 'uid':
				return $this->pi_list_linkSingle($this->internal['currentRow'][$fN],$this->internal['currentRow']['uid'],1, $mergeArr);	
				// The "1" means that the display of single items is CACHED! Set to zero to disable caching.
			break;
			case 'name':
				return $this->pi_list_linkSingle($this->internal['currentRow'][$fN],$this->internal['currentRow']['uid'],1, $mergeArr);	
				// The "1" means that the display of single items is CACHED! Set to zero to disable caching.
			break;
			case 'date':
					// %A %e. %B %Y
				return strftime('%d-%m-%y',$this->internal['currentRow']['date']);
			break;			
			default:
				return $this->internal['currentRow'][$fN];
			break;
		}
	}
	/**
	 * Returns the label for a fieldname from local language array
	 *
	 * @param	[type]		$fN: ...
	 * @return	[type]		...
	 */
	function getFieldHeader($fN)	{
		switch($fN) {
			
			default:
				return $this->pi_getLL('listFieldHeader_'.$fN,'['.$fN.']');
			break;
		}
	}
	
	// return true if $str ends with $sub
	function endsWith( $str, $sub ) {
		return ( substr( $str, strlen( $str ) - strlen( $sub ) ) == $sub );
	}
	
	function getCurrentUserGroups() {
		$tab_groups = array();
		$this->getSubGroups($GLOBALS['TSFE']->fe_user->user['usergroup'], '', $tab_groups);
		$groups = '';
		foreach($tab_groups as $valeur) { $groups .= $valeur.','; }
		return substr($groups, 0, -1);	
	}

	/**
	 * Fetches subgroups of groups. Function is called recursively for each subgroup.
	 * Function was previously copied from t3lib_userAuthGroup->fetchGroups and has been slightly modified.
	 *
	 * @param	string		Commalist of fe_groups uid numbers
	 * @param	string		List of already processed fe_groups-uids so the function will not fall into a eternal recursion.
	 * @return	array
	 * @access private
	 */
	function getSubGroups($grList, $idList='', &$groups)	{

			// Fetching records of the groups in $grList (which are not blocked by lockedToDomain either):
		$lockToDomain_SQL = ' AND (lockToDomain=\'\' OR lockToDomain IS NULL OR lockToDomain=\''.$this->authInfo['HTTP_HOST'].'\')';
		if (!$this->authInfo['showHiddenRecords'])	$hiddenP = 'AND hidden=0 ';
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,subgroup', 'fe_groups', 'deleted=0 '.$hiddenP.' AND uid IN ('.$grList.')'.$lockToDomain_SQL);

		$groupRows = array();	// Internal group record storage

			// The groups array is filled
		while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{
			if(!in_array($row['uid'], $groups))	{ $groups[] = $row['uid']; }
			$groupRows[$row['uid']] = $row;
		}

			// Traversing records in the correct order
		$include_staticArr = t3lib_div::intExplode(',', $grList);
		foreach($include_staticArr as $uid)	{	// traversing list

				// Get row:
			$row=$groupRows[$uid];
			if (is_array($row) && !t3lib_div::inList($idList,$uid))	{	
			// Must be an array and $uid should not be in the idList, because then it is somewhere previously in the grouplist

					// Include sub groups
				if (trim($row['subgroup']))	{
					$theList = implode(',',t3lib_div::intExplode(',',$row['subgroup']));	// Make integer list
					$this->getSubGroups($theList, $idList.','.$uid, $groups);		
					// Call recursively, pass along list of already processed groups so they are not recursed again.
				}
			}
		}
	}
	
	function userIsAuthorized () {
		if ($this->piVars['project_id']) {
			$queryParts = array(
				'SELECT' => 'fe_group',
				'FROM' => 'tx_nG6_project',
				'WHERE' => 'uid='.$this->piVars['project_id'],
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
			$authorized_group = $val['fe_group'];
		} elseif ($this->piVars['run_id']) {
			$queryParts = array(
				'SELECT' => 'project_id',
				'FROM' => 'tx_nG6_project_run',
				'WHERE' => 'run_id='.$this->piVars['run_id'],
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res1 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res1);
			$queryParts = array(
				'SELECT' => 'fe_group',
				'FROM' => 'tx_nG6_project',
				'WHERE' => 'uid='.$val['project_id'],
				'GROUPBY' => '',
				'ORDERBY' => '',
				'LIMIT' => ''
			);
			$res2 = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
			$val = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
			$authorized_group = $val['fe_group'];
		} else {
			return true;
		}
		if (!$GLOBALS['TSFE']->loginUser) { // If the user is not logged on
			return $authorized_group == 0;
		} else {
			return in_array($authorized_group, split(",", $this->getCurrentUserGroups()));
		}
	}	
	
}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/pi5/class.tx_nG6_pi5.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/pi5/class.tx_nG6_pi5.php']);
}

?>