ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilMemberExportGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
25include_once('./Services/Membership/classes/Export/class.ilMemberExport.php');
26include_once('Modules/Course/classes/class.ilFSStorageCourse.php');
27include_once('Modules/Group/classes/class.ilFSStorageGroup.php');
28include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
29include_once('Services/User/classes/class.ilUserDefinedFields.php');
30include_once('Services/User/classes/class.ilUserFormSettings.php');
31
42{
43 private $ref_id;
44 private $obj_id;
45 private $type;
46 private $ctrl;
47 private $tpl;
48 private $lng;
49
50 private $fields_info;
51 private $fss_export = null;
52
60 public function __construct($a_ref_id)
61 {
62 global $ilCtrl,$tpl,$lng,$ilUser,$ilObjDataCache;
63
64 $this->ctrl = $ilCtrl;
65 $this->tpl = $tpl;
66 $this->lng = $lng;
67 $this->lng->loadLanguageModule('ps');
68 $this->ref_id = $a_ref_id;
69 $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
70 $this->type = ilObject::_lookupType($this->obj_id);
71
72 $this->fields_info = ilExportFieldsInfo::_getInstanceByType(ilObject::_lookupType($this->obj_id));
73 $this->initFileSystemStorage();
74 }
75
83 public function executeCommand()
84 {
85 global $ilAccess,$rbacsystem;
86
87 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
88 if(!ilPrivacySettings::_getInstance()->checkExportAccess($this->ref_id))
89 {
90 ilUtil::sendFailure($this->lng->txt('permission_denied'),true);
91 $this->ctrl->returnToParent($this);
92 }
93
94 $next_class = $this->ctrl->getNextClass($this);
95 $cmd = $this->ctrl->getCmd();
96
97 switch($next_class)
98 {
99 default:
100 if(!$cmd)
101 {
102 $cmd = 'show';
103 }
104 $this->$cmd();
105 break;
106 }
107 }
108
115 public function show($a_deliver_file = false)
116 {
117 $this->showFileList();
118 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.member_export.html','Modules/Course');
119 $this->tpl->setVariable('FORM_ACTION',$this->ctrl->getFormAction($this));
120 $this->tpl->setVariable('TXT_EXPORT_SETTINGS',$this->lng->txt('ps_export_settings'));
121 $this->tpl->setVariable('TXT_USER_SELECTION',$this->lng->txt('ps_user_selection'));
122 $this->tpl->setVariable('TXT_EXPORT_ADMIN',$this->lng->txt('ps_export_admin'));
123 $this->tpl->setVariable('TXT_EXPORT_MEMBER',$this->lng->txt('ps_export_member'));
124 $this->tpl->setVariable('TXT_EXPORT_WAIT',$this->lng->txt('ps_export_wait'));
125 $this->tpl->setVariable('TXT_EXPORT_SUB',$this->lng->txt('ps_export_sub'));
126
127 // Check user selection
128 $this->exportSettings = new ilUserFormSettings('memexp');
129
130 $this->tpl->setVariable('CHECK_EXPORT_ADMIN',ilUtil::formCheckbox($this->exportSettings->enabled('admin'),'export_members[admin]',1));
131 if($this->type == 'crs')
132 {
133 $this->tpl->setVariable('CHECK_EXPORT_TUTOR',ilUtil::formCheckbox($this->exportSettings->enabled('tutor'),'export_members[tutor]',1));
134 $this->tpl->setVariable('TXT_EXPORT_TUTOR',$this->lng->txt('ps_export_tutor'));
135 }
136 $this->tpl->setVariable('CHECK_EXPORT_MEMBER',ilUtil::formCheckbox($this->exportSettings->enabled('member'),'export_members[member]',1));
137 $this->tpl->setVariable('CHECK_EXPORT_SUB',ilUtil::formCheckbox($this->exportSettings->enabled('subscribers'),'export_members[subscribers]',1));
138 $this->tpl->setVariable('CHECK_EXPORT_WAIT',ilUtil::formCheckbox($this->exportSettings->enabled('waiting_list'),'export_members[waiting_list]',1));
139
140 $this->tpl->setVariable('TXT_EXPORT',$this->lng->txt('ps_perform_export'));
141 $this->tpl->setVariable('TXT_EXPORT_EXCEL',$this->lng->txt('ps_export_excel'));
142
143 // User Data
144 $this->tpl->setVariable('TXT_USER_DATA_SELECTION',$this->lng->txt('ps_export_data'));
145 $this->tpl->setVariable('TXT_EXPORT_USER_DATA_HEADER',$this->lng->txt('ps_export_user_data'));
146
147 include_once './Services/Booking/classes/class.ilBookingEntry.php';
148 if(ilBookingEntry::hasObjectBookingEntries($this->obj_id, $GLOBALS['ilUser']->getId()))
149 {
150 $this->tpl->setCurrentBlock('consultation');
151 $this->lng->loadLanguageModule('dateplaner');
152 $this->tpl->setVariable('TXT_CH',$this->lng->txt('cal_ch_field_ch'));
153 $this->tpl->setVariable('TXT_EXPORT_CH',$this->lng->txt('cal_ch_export_apps'));
154 $this->tpl->setVariable('CHECK_EXPORT_CH',ilUtil::formCheckbox($this->exportSettings->enabled('consultation_hour'), 'export_members[consultation_hour]', 1));
155 $this->tpl->parseCurrentBlock();
156 }
157 $this->fields_info->sortExportFields();
158 $fields = $this->fields_info->getFieldsInfo();
159 foreach($fields as $field => $exportable)
160 {
161 if(!$exportable)
162 {
163 continue;
164 }
165 $this->tpl->setCurrentBlock('user_data_row');
166 $this->tpl->setVariable('CHECK_EXPORT_USER_DATA',ilUtil::formCheckbox($this->exportSettings->enabled($field),'export_members['.$field.']',1));
167 $this->tpl->setVariable('TXT_EXPORT_USER_DATA',$this->lng->txt($field));
168
169 if($field == "username")//User Name Presentation Guideline; username should be named login
170 {
171 $this->tpl->setVariable('TXT_EXPORT_USER_DATA',$this->lng->txt("login"));
172 }
173 $this->tpl->parseCurrentBlock();
174 }
175
177 foreach($exp = $udf->getExportableFields($this->obj_id) as $field_id => $udf_data)
178 {
179 $this->tpl->setCurrentBlock('user_data_row');
180 $this->tpl->setVariable('CHECK_EXPORT_USER_DATA',ilUtil::formCheckbox($this->exportSettings->enabled('udf_'.$field_id),
181 'export_members[udf_'.$field_id.']',1));
182 $this->tpl->setVariable('TXT_EXPORT_USER_DATA',$udf_data['field_name']);
183 $this->tpl->parseCurrentBlock();
184 }
185
186
187 $cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->obj_id);
188 foreach($cdf_fields as $field_obj)
189 {
190 $this->tpl->setCurrentBlock('cdf_row');
191 $this->tpl->setVariable('CHECK_CDF_DATA',ilUtil::formCheckbox($this->exportSettings->enabled('cdf_'.$field_obj->getId()),
192 'export_members[cdf_'.$field_obj->getId().']',
193 1));
194 $this->tpl->setVariable('TXT_CDF_NAME',$field_obj->getName());
195 $this->tpl->parseCurrentBlock();
196 }
197 if(count($cdf_fields))
198 {
199 $this->tpl->setCurrentBlock('cdf_fields');
200 $this->tpl->setVariable('TXT_CDF_SELECTION',$this->lng->txt('ps_'.$this->type.'_user_fields'));
201 $this->tpl->parseCurrentBlock();
202 }
203
204 if($a_deliver_file and 0)
205 {
206 $this->tpl->setCurrentBlock('iframe');
207 $this->tpl->setVariable('SOURCE',$this->ctrl->getLinkTarget($this,'deliverData'));
208 }
209 }
210
218 public function deliverData()
219 {
220 foreach($this->fss_export->getMemberExportFiles() as $file)
221 {
222 if($file['name'] == $_SESSION['member_export_filename'])
223 {
224 $content = $this->fss_export->getMemberExportFile($_SESSION['member_export_filename']);
225 ilUtil::deliverData($content,date('Y_m_d_H-i',$file['timest']).
226 '_member_export_'.
227 $this->obj_id.
228 '.csv','text/csv');
229 }
230 }
231 }
232
239 public function showFileList()
240 {
241 global $ilUser;
242
243 if(!count($files = $this->fss_export->getMemberExportFiles()))
244 {
245 return false;
246 }
247
248 $a_tpl = new ilTemplate('tpl.table.html',true,true);
249 $a_tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.member_export_file_row.html", "Modules/Course");
250 $a_tpl->setVariable('FORMACTION',$this->ctrl->getFormaction($this));
251
252 include_once("./Services/Table/classes/class.ilTableGUI.php");
253 $tbl = new ilTableGUI();
254
255 // load template for table content data
256
257 $tbl->setTitle($this->lng->txt("ps_export_files"));
258
259 $tbl->setHeaderNames(array("", $this->lng->txt("type"),
260 $this->lng->txt("ps_size"),
261 $this->lng->txt("date") ));
262
263 $cols = array("", "type","size", "date");
264
265 $header_params = $this->ctrl->getParameterArray($this,'show');
266 $tbl->setHeaderVars($cols, $header_params);
267 $tbl->setColumnWidth(array("1%", "9%", "45%", "45%"));
268
269 // control
270 $tbl->setOrderColumn($_GET["sort_by"]);
271 $tbl->setOrderDirection($_GET["sort_order"]);
272 $tbl->setLimit($ilUser->getPref('hits_per_page',9999));
273 $tbl->setOffset($_GET["offset"]);
274 $tbl->setMaxCount(count($files));
275 $tbl->disable("sort");
276 $a_tpl->setVariable("COLUMN_COUNTS",4);
277
278 $files = array_reverse($files);
279 $files = array_slice($files, $_GET["offset"], $_GET["limit"]);
280 $num = 0;
281 $i=0;
282 foreach($files as $exp_file)
283 {
284 $a_tpl->setCurrentBlock("tbl_content");
285 $a_tpl->setVariable("TXT_FILENAME", $exp_file["file"]);
286
287 $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
288 $a_tpl->setVariable("CSS_ROW", $css_row);
289
290 $a_tpl->setVariable("TXT_SIZE",$exp_file['size']);
291 $a_tpl->setVariable("TXT_TYPE", strtoupper($exp_file["type"]));
292 $a_tpl->setVariable("CHECKBOX_ID",$exp_file["timest"]);
293 $a_tpl->setVariable("TXT_DATE", date("Y-m-d H:i",$exp_file['timest']));
294 $a_tpl->parseCurrentBlock();
295 }
296
297
298 // delete button
299 $a_tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
300 $a_tpl->setCurrentBlock("tbl_action_btn");
301 $a_tpl->setVariable("BTN_NAME", "confirmDeleteExportFile");
302 $a_tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
303 $a_tpl->parseCurrentBlock();
304
305 $a_tpl->setCurrentBlock("tbl_action_btn");
306 $a_tpl->setVariable("BTN_NAME", "downloadExportFile");
307 $a_tpl->setVariable("BTN_VALUE", $this->lng->txt("download"));
308 $a_tpl->parseCurrentBlock();
309
310 // footer
311 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
312 //$tbl->disable("footer");
313
314 $tbl->setTemplate($a_tpl);
315 $tbl->render();
316
317 #$this->tpl->setCurrentBlock('file_list');
318 $this->tpl->setVariable('FILE_LIST_TABLE',$a_tpl->get());
319 #$this->tpl->parseCurrentBlock();
320
321 }
322
330 public function downloadExportFile()
331 {
332 if(count($_POST['files']) != 1)
333 {
334 ilUtil::sendFailure($this->lng->txt('ps_select_one'));
335 $this->show();
336 return true;
337 }
338 foreach($this->fss_export->getMemberExportFiles() as $file)
339 {
340 if(!in_array($file['timest'],$_POST['files']))
341 {
342 continue;
343 }
344 $contents = $this->fss_export->getMemberExportFile($file['timest'].'_participant_export_'.
345 $file['type'].'_'.$this->obj_id.'.'.$file['type']);
346
347
348 switch($file['type'])
349 {
350 case 'xls':
352 $contents,
353 date('Y_m_d_H-i'.$file['timest']).'_member_export_'.$this->obj_id.'.xls',
354 'application/vnd.ms-excel'
355 );
356
357 default:
358 case 'csv':
359 ilUtil::deliverData($contents,date('Y_m_d_H-i'.$file['timest']).
360 '_member_export_'.
361 $this->obj_id.
362 '.csv','text/csv');
363 break;
364 }
365 return true;
366
367 }
368
369
370 }
371
379 public function confirmDeleteExportFile()
380 {
381 if(!count($_POST['files']))
382 {
383 ilUtil::sendFailure($this->lng->txt('ps_select_one'));
384 $this->show();
385 return false;
386 }
387 $_SESSION['il_del_member_export'] = $_POST['files'];
388 ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
389
390 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.member_export_confirm_delete.html','Modules/Course');
391 $this->tpl->setVariable('FORMACTION',$this->ctrl->getFormAction($this));
392 $this->tpl->setVariable('TEXT',$this->lng->txt('ps_delete_export_files'));
393
394
395 $counter = 0;
396 foreach($this->fss_export->getMemberExportFiles() as $file)
397 {
398 if(!in_array($file['timest'],$_POST['files']))
399 {
400 continue;
401 }
402 $this->tpl->setCurrentBlock('table_row');
403 $this->tpl->setVariable('CSS_ROW',ilUtil::switchColor($counter++,'tblrow1','tblrow2'));
404 $this->tpl->setVariable('TEXT_TYPE',strtoupper($file['type']));
405 $this->tpl->setVariable('DATE',ilDatePresentation::formatDate(new ilDateTime($file['timest'],IL_CAL_UNIX)));
406 $this->tpl->parseCurrentBlock();
407 }
408 $this->tpl->setCurrentBlock('operation_btn');
409 $this->tpl->setVariable('BTN_NAME','deleteExportFile');
410 $this->tpl->setVariable('BTN_VALUE',$this->lng->txt('delete'));
411 $this->tpl->parseCurrentBlock();
412
413 $this->tpl->setCurrentBlock('operation_btn');
414 $this->tpl->setVariable('BTN_NAME','show');
415 $this->tpl->setVariable('BTN_VALUE',$this->lng->txt('cancel'));
416 $this->tpl->parseCurrentBlock();
417
418 }
419
427 public function deleteExportFile()
428 {
429 if(!is_array($_SESSION['il_del_member_export']))
430 {
431 $this->show();
432 return false;
433 }
434 $counter = 0;
435 foreach($this->fss_export->getMemberExportFiles() as $file)
436 {
437 if(!in_array($file['timest'],$_SESSION['il_del_member_export']))
438 {
439 continue;
440 }
441 $this->fss_export->deleteMemberExportFile($file['timest'].'_participant_export_'.$file['type'].'_'.$this->obj_id.'.'.$file['type']);
442 }
443 ilUtil::sendSuccess($this->lng->txt('ps_files_deleted'));
444 $this->show();
445 }
446
447
448
449
456 public function export()
457 {
458 // Save settings
459 $this->exportSettings = new ilUserFormSettings('memexp');
460 $this->exportSettings->set($_POST['export_members']);
461 $this->exportSettings->store();
462
463 $this->export = new ilMemberExport($this->ref_id);
464 $this->export->create();
465
466 $filename = time().'_participant_export_csv_'.$this->obj_id.'.csv';
467 $this->fss_export->addMemberExportFile($this->export->getCSVString(),$filename);
468
469 $_SESSION['member_export_filename'] = $filename;
470
471 $this->show(true);
472 }
473
474 public function exportExcel()
475 {
476 $this->exportSettings = new ilUserFormSettings('memexp');
477 $this->exportSettings->set($_POST['export_members']);
478 $this->exportSettings->store();
479
480 $filename = time().'_participant_export_xls_'.$this->obj_id.'.xls';
481 $this->fss_export->initMemberExportDirectory();
482 $filepath = $this->fss_export->getMemberExportDirectory().DIRECTORY_SEPARATOR.$filename;
483
484 $this->export = new ilMemberExport($this->ref_id,ilMemberExport::EXPORT_EXCEL);
485 $this->export->setFilename($filepath);
486 $this->export->create();
487
488 $_SESSION['member_export_filename'] = $filename;
489
490 $this->show(true);
491
492 }
493
494
499 protected function initFileSystemStorage()
500 {
501 if($this->type == 'crs')
502 {
503 $this->fss_export = new ilFSStorageCourse($this->obj_id);
504 }
505 if($this->type == 'grp')
506 {
507 $this->fss_export = new ilFSStorageGroup($this->obj_id);
508 }
509
510 }
511}
512?>
print $file
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
const IL_CAL_UNIX
static hasObjectBookingEntries($a_obj_id, $a_usr_id)
Check if object has assigned consultation hour appointments.
static _getFields($a_container_id, $a_sort=IL_CDF_SORT_NAME)
Get all fields of a container.
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
static _getInstanceByType($a_type)
Get Singleton Instance.
downloadExportFile()
Download export file.
deleteExportFile()
Delete member export files.
export()
Export Create member export file and store it in data directory.
showFileList()
Show file list of available export files.
show($a_deliver_file=false)
Show list of export files.
confirmDeleteExportFile()
Confirm deletion of export files.
initFileSystemStorage()
Init file object.
__construct($a_ref_id)
Constructor.
executeCommand()
Execute Command.
Class for generation of member export files.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getInstance()
Get instance of ilPrivacySettings.
Class ilTableGUI.
special template class to simplify handling of ITX/PEAR
static _getInstance()
Get instance.
static formCheckbox($checked, $varname, $value, $disabled=false)
??? @access public
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
static switchColor($a_num, $a_css1, $a_css2)
switches style sheets for each even $a_num (used for changing colors of different result rows)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$_POST['username']
Definition: cron.php:12
$GLOBALS['ct_recipient']
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
global $ilUser
Definition: imgupload.php:15