ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
109
110 //
111 // export incl. settings
112 //
113
114 protected function initSettingsForm($a_is_excel = false)
115 {
116 // Check user selection
117 $this->exportSettings = new ilUserFormSettings('memexp');
118
119 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
120 $form = new ilPropertyFormGUI();
121 $form->setFormAction($this->ctrl->getFormAction($this));
122 $form->setTitle($this->lng->txt('ps_export_settings'));
123
124 if((bool)$a_is_excel)
125 {
126 $form->addCommandButton('exportExcel', $this->lng->txt('ps_export_excel'));
127 }
128 else
129 {
130 $form->addCommandButton('export', $this->lng->txt('ps_perform_export'));
131 }
132 $form->addCommandButton('show', $this->lng->txt('cancel'));
133
134 // roles
135 $roles = new ilCheckboxGroupInputGUI($this->lng->txt('ps_user_selection'), 'export_members');
136 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_admin'), 'admin'));
137 if($this->type == 'crs')
138 {
139 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_tutor'), 'tutor'));
140 }
141 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_member'), 'member'));
142 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_sub'), 'subscribers'));
143 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_wait'), 'waiting_list'));
144 $form->addItem($roles);
145
146 $current_roles = array();
147 foreach(array('admin', 'tutor', 'member', 'subscribers', 'waiting_list') as $role)
148 {
149 if($this->exportSettings->enabled($role))
150 {
151 $current_roles[] = $role;
152 }
153 }
154 $roles->setValue($current_roles);
155
156 // user data
157 $current_udata = array();
158 $udata = new ilCheckboxGroupInputGUI($this->lng->txt('ps_export_user_data'), 'export_members');
159 $form->addItem($udata);
160
161 // standard fields
162 $this->fields_info->sortExportFields();
163 foreach($this->fields_info->getFieldsInfo() as $field => $exportable)
164 {
165 if(!$exportable)
166 {
167 continue;
168 }
169 $udata->addOption(new ilCheckboxOption($this->lng->txt($field), $field));
170 if($this->exportSettings->enabled($field))
171 {
172 $current_udata[] = $field;
173 }
174 }
175
176 // udf
177 foreach(ilUserDefinedFields::_getInstance()->getExportableFields($this->obj_id) as $field_id => $udf_data)
178 {
179 $field = 'udf_'.$field_id;
180 $udata->addOption(new ilCheckboxOption($udf_data['field_name'], $field));
181 if($this->exportSettings->enabled($field))
182 {
183 $current_udata[] = $field;
184 }
185 }
186
187 $udata->setValue($current_udata);
188
189 // course custom data
190 $cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->obj_id);
191 if(count($cdf_fields))
192 {
193 $cdf = new ilCheckboxGroupInputGUI($this->lng->txt('ps_'.$this->type.'_user_fields'), 'export_members');
194 $form->addItem($cdf);
195
196 $current_cdf = array();
197 foreach($cdf_fields as $field_obj)
198 {
199 $field = 'cdf_'.$field_obj->getId();
200 $cdf->addOption(new ilCheckboxOption($field_obj->getName(), $field));
201 if($this->exportSettings->enabled($field))
202 {
203 $current_cdf[] = $field;
204 }
205 }
206
207 $cdf->setValue($current_cdf);
208 }
209
210 // consultation hours
211 include_once './Services/Booking/classes/class.ilBookingEntry.php';
212 if(ilBookingEntry::hasObjectBookingEntries($this->obj_id, $GLOBALS['ilUser']->getId()))
213 {
214 $this->lng->loadLanguageModule('dateplaner');
215 $chours = new ilCheckboxInputGUI($this->lng->txt('cal_ch_field_ch'), 'export_members[]');
216 $chours->setValue('consultation_hour');
217 $chours->setChecked($this->exportSettings->enabled('consultation_hour'));
218 $form->addItem($chours);
219 }
220
221 return $form;
222 }
223
224 public function initCSV(ilPropertyFormGUI $a_form = null)
225 {
226 if(!$a_form)
227 {
228 $a_form = $this->initSettingsForm();
229 }
230 $this->tpl->setContent($a_form->getHTML());
231 }
232
233 public function initExcel(ilPropertyFormGUI $a_form = null)
234 {
235 if(!$a_form)
236 {
237 $a_form = $this->initSettingsForm(true);
238 }
239 $this->tpl->setContent($a_form->getHTML());
240 }
241
248 public function show()
249 {
250 global $ilToolbar;
251
252 $ilToolbar->addButton($this->lng->txt('ps_perform_export'),
253 $this->ctrl->getLinkTarget($this, "initCSV"));
254 $ilToolbar->addButton($this->lng->txt('ps_export_excel'),
255 $this->ctrl->getLinkTarget($this, "initExcel"));
256
257 $this->showFileList();
258 }
259
260 protected function handleIncoming()
261 {
262 $settings = array();
263 $incoming = $_POST['export_members'];
264 if(is_array($incoming))
265 {
266 foreach($incoming as $id)
267 {
268 $settings[$id] = true;
269 }
270 }
271
272 // Save (form) settings
273 $this->exportSettings = new ilUserFormSettings('memexp');
274 $this->exportSettings->set($settings);
275 $this->exportSettings->store();
276 }
277
284 public function export()
285 {
286 $this->handleIncoming();
287
288 $this->export = new ilMemberExport($this->ref_id);
289 $this->export->create();
290
291 $filename = time().'_participant_export_csv_'.$this->obj_id.'.csv';
292 $this->fss_export->addMemberExportFile($this->export->getCSVString(),$filename);
293
294 $this->ctrl->redirect($this, 'show');
295 }
296
297 public function exportExcel()
298 {
299 $this->handleIncoming();
300
301 $filename = time().'_participant_export_xls_'.$this->obj_id.'.xls';
302 $this->fss_export->initMemberExportDirectory();
303 $filepath = $this->fss_export->getMemberExportDirectory().DIRECTORY_SEPARATOR.$filename;
304
305 $this->export = new ilMemberExport($this->ref_id,ilMemberExport::EXPORT_EXCEL);
306 $this->export->setFilename($filepath);
307 $this->export->create();
308
309 $this->ctrl->redirect($this, 'show');
310 }
311
319 public function deliverData()
320 {
321 foreach($this->fss_export->getMemberExportFiles() as $file)
322 {
323 if($file['name'] == $_SESSION['member_export_filename'])
324 {
325 $content = $this->fss_export->getMemberExportFile($_SESSION['member_export_filename']);
326 ilUtil::deliverData($content,date('Y_m_d_H-i',$file['timest']).
327 '_member_export_'.
328 $this->obj_id.
329 '.csv','text/csv');
330 }
331 }
332 }
333
340 public function showFileList()
341 {
342 include_once 'Services/Membership/classes/Export/class.ilMemberExportFileTableGUI.php';
343 $tbl = new ilMemberExportFileTableGUI($this, 'show', $this->fss_export);
344 $this->tpl->setContent($tbl->getHTML());
345 }
346
354 public function downloadExportFile()
355 {
356 $hash = trim($_GET['fl']);
357 if(!$hash)
358 {
359 $this->ctrl->redirect($this, 'show');
360 }
361
362 foreach($this->fss_export->getMemberExportFiles() as $file)
363 {
364 if(md5($file['name']) == $hash)
365 {
366 $contents = $this->fss_export->getMemberExportFile($file['timest'].'_participant_export_'.
367 $file['type'].'_'.$this->obj_id.'.'.$file['type']);
368
369 switch($file['type'])
370 {
371 case 'xls':
373 $contents,
374 date('Y_m_d_H-i'.$file['timest']).'_member_export_'.$this->obj_id.'.xls',
375 'application/vnd.ms-excel'
376 );
377
378 default:
379 case 'csv':
380 ilUtil::deliverData($contents,date('Y_m_d_H-i'.$file['timest']).
381 '_member_export_'.
382 $this->obj_id.
383 '.csv','text/csv');
384 break;
385 }
386 return true;
387 }
388 }
389 }
390
398 public function confirmDeleteExportFile()
399 {
400 if(!count($_POST['id']))
401 {
402 ilUtil::sendFailure($this->lng->txt('ps_select_one'), true);
403 $this->ctrl->redirect($this, 'show');
404 }
405
406 include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
407 $confirmation_gui = new ilConfirmationGUI();
408 $confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
409 $confirmation_gui->setHeaderText($this->lng->txt('info_delete_sure') /* .' '.$this->lng->txt('ps_delete_export_files') */);
410 $confirmation_gui->setCancel($this->lng->txt('cancel'), 'show');
411 $confirmation_gui->setConfirm($this->lng->txt('delete'), 'deleteExportFile');
412
413 $counter = 0;
414 foreach($this->fss_export->getMemberExportFiles() as $file)
415 {
416 if(!in_array(md5($file['name']), $_POST['id']))
417 {
418 continue;
419 }
420
421 $confirmation_gui->addItem("id[]", md5($file['name']),
422 strtoupper($file['type']).' - '.
424 }
425
426 $this->tpl->setContent($confirmation_gui->getHTML());
427 }
428
436 public function deleteExportFile()
437 {
438 if(!count($_POST['id']))
439 {
440 $this->ctrl->redirect($this, 'show');
441 }
442
443 $counter = 0;
444 foreach($this->fss_export->getMemberExportFiles() as $file)
445 {
446 if(!in_array(md5($file['name']), $_POST['id']))
447 {
448 continue;
449 }
450
451 $this->fss_export->deleteMemberExportFile($file['timest'].'_participant_export_'.$file['type'].'_'.$this->obj_id.'.'.$file['type']);
452 }
453
454 ilUtil::sendSuccess($this->lng->txt('ps_files_deleted'), true);
455 $this->ctrl->redirect($this, 'show');
456 }
457
458
463 protected function initFileSystemStorage()
464 {
465 if($this->type == 'crs')
466 {
467 $this->fss_export = new ilFSStorageCourse($this->obj_id);
468 }
469 if($this->type == 'grp')
470 {
471 $this->fss_export = new ilFSStorageGroup($this->obj_id);
472 }
473 }
474}
475?>
print $file
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
$_SESSION["AccountId"]
const IL_CAL_UNIX
static hasObjectBookingEntries($a_obj_id, $a_usr_id)
Check if object has assigned consultation hour appointments.
This class represents a property in a property form.
This class represents a checkbox property in a property form.
This class represents an option in a checkbox group.
Confirmation screen class.
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.
Table presentation of membership export files.
downloadExportFile()
Download export file.
deleteExportFile()
Delete member export files.
show()
Show list of export files.
export()
Export Create member export file and store it in data directory.
showFileList()
Show file list of available export files.
initSettingsForm($a_is_excel=false)
initExcel(ilPropertyFormGUI $a_form=null)
confirmDeleteExportFile()
Confirm deletion of export files.
initCSV(ilPropertyFormGUI $a_form=null)
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.
This class represents a property form user interface.
static _getInstance()
Get instance.
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.
$_POST['username']
Definition: cron.php:12
$tbl
Definition: example_048.php:81
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
global $ilUser
Definition: imgupload.php:15