ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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;
56
64 public function __construct($a_ref_id)
65 {
66 global $ilCtrl,$tpl,$lng,$ilUser,$ilObjDataCache;
67
68 $this->ctrl = $ilCtrl;
69 $this->tpl = $tpl;
70 $this->lng = $lng;
71 $this->lng->loadLanguageModule('ps');
72 $this->ref_id = $a_ref_id;
73 $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
74 $this->type = ilObject::_lookupType($this->obj_id);
75
76 $this->fields_info = ilExportFieldsInfo::_getInstanceByType(ilObject::_lookupType($this->obj_id));
77 $this->initFileSystemStorage();
78 }
79
87 public function executeCommand()
88 {
89 global $ilAccess,$rbacsystem;
90
91
92 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
93 if (!ilPrivacySettings::_getInstance()->checkExportAccess($this->ref_id)) {
94 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
95 $this->ctrl->returnToParent($this);
96 }
97
98 $next_class = $this->ctrl->getNextClass($this);
99 $cmd = $this->ctrl->getCmd();
100
101 switch ($next_class) {
102 default:
103 if (!$cmd) {
104 $cmd = 'show';
105 }
106 $this->$cmd();
107 break;
108 }
109 }
110
111
112 //
113 // export incl. settings
114 //
115
116 protected function initSettingsForm($a_is_excel = false)
117 {
118 // Check user selection
119 $this->exportSettings = new ilUserFormSettings('memexp');
120
121 include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
122 $form = new ilPropertyFormGUI();
123 $form->setFormAction($this->ctrl->getFormAction($this));
124 $form->setTitle($this->lng->txt('ps_export_settings'));
125
126 if ((bool) $a_is_excel) {
127 $form->addCommandButton('exportExcel', $this->lng->txt('ps_export_excel'));
128 } else {
129 $form->addCommandButton('export', $this->lng->txt('ps_perform_export'));
130 }
131 $form->addCommandButton('show', $this->lng->txt('cancel'));
132
133 // roles
134 $roles = new ilCheckboxGroupInputGUI($this->lng->txt('ps_user_selection'), 'export_members');
135 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_admin'), 'admin'));
136 if ($this->type == 'crs') {
137 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_tutor'), 'tutor'));
138 }
139 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_member'), 'member'));
140 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_sub'), 'subscribers'));
141 $roles->addOption(new ilCheckboxOption($this->lng->txt('ps_export_wait'), 'waiting_list'));
142 $form->addItem($roles);
143
144 $current_roles = array();
145 foreach (array('admin', 'tutor', 'member', 'subscribers', 'waiting_list') as $role) {
146 if ($this->exportSettings->enabled($role)) {
147 $current_roles[] = $role;
148 }
149 }
150 $roles->setValue($current_roles);
151
152 // user data
153 $current_udata = array();
154 $udata = new ilCheckboxGroupInputGUI($this->lng->txt('ps_export_user_data'), 'export_members');
155 $form->addItem($udata);
156
157 // standard fields
158 $this->fields_info->sortExportFields();
159 foreach ($this->fields_info->getFieldsInfo() as $field => $exportable) {
160 if (!$exportable) {
161 continue;
162 }
163 $udata->addOption(new ilCheckboxOption($this->lng->txt($field), $field));
164 if ($this->exportSettings->enabled($field)) {
165 $current_udata[] = $field;
166 }
167 }
168
169 // udf
170 foreach (ilUserDefinedFields::_getInstance()->getExportableFields($this->obj_id) as $field_id => $udf_data) {
171 $field = 'udf_' . $field_id;
172 $udata->addOption(new ilCheckboxOption($udf_data['field_name'], $field));
173 if ($this->exportSettings->enabled($field)) {
174 $current_udata[] = $field;
175 }
176 }
177
178 $udata->setValue($current_udata);
179
180 // course custom data
181 $cdf_fields = ilCourseDefinedFieldDefinition::_getFields($this->obj_id);
182 if (count($cdf_fields)) {
183 $cdf = new ilCheckboxGroupInputGUI($this->lng->txt('ps_' . $this->type . '_user_fields'), 'export_members');
184 $form->addItem($cdf);
185
186 $current_cdf = array();
187 foreach ($cdf_fields as $field_obj) {
188 $field = 'cdf_' . $field_obj->getId();
189 $cdf->addOption(new ilCheckboxOption($field_obj->getName(), $field));
190 if ($this->exportSettings->enabled($field)) {
191 $current_cdf[] = $field;
192 }
193 }
194
195 $cdf->setValue($current_cdf);
196 }
197
198 // consultation hours
199 include_once './Services/Booking/classes/class.ilBookingEntry.php';
200 if (ilBookingEntry::hasObjectBookingEntries($this->obj_id, $GLOBALS['ilUser']->getId())) {
201 $this->lng->loadLanguageModule('dateplaner');
202 $chours = new ilCheckboxInputGUI($this->lng->txt('cal_ch_field_ch'), 'export_members[]');
203 $chours->setValue('consultation_hour');
204 $chours->setChecked($this->exportSettings->enabled('consultation_hour'));
205 $form->addItem($chours);
206 }
207
208 $grp_membr = new ilCheckboxInputGUI($this->lng->txt('crs_members_groups'), 'export_members[]');
209 $grp_membr->setValue('group_memberships');
210 $grp_membr->setChecked($this->exportSettings->enabled('group_memberships'));
211 $form->addItem($grp_membr);
212 return $form;
213 }
214
215 public function initCSV(ilPropertyFormGUI $a_form = null)
216 {
217 if (!$a_form) {
218 $a_form = $this->initSettingsForm();
219 }
220 $this->tpl->setContent($a_form->getHTML());
221 }
222
223 public function initExcel(ilPropertyFormGUI $a_form = null)
224 {
225 if (!$a_form) {
226 $a_form = $this->initSettingsForm(true);
227 }
228 $this->tpl->setContent($a_form->getHTML());
229 }
230
237 public function show()
238 {
239 global $ilToolbar;
240
241 $ilToolbar->addButton(
242 $this->lng->txt('ps_perform_export'),
243 $this->ctrl->getLinkTarget($this, "initCSV")
244 );
245 $ilToolbar->addButton(
246 $this->lng->txt('ps_export_excel'),
247 $this->ctrl->getLinkTarget($this, "initExcel")
248 );
249
250 $this->showFileList();
251 }
252
253 protected function handleIncoming()
254 {
255 $settings = array();
256 $incoming = $_POST['export_members'];
257 if (is_array($incoming)) {
258 foreach ($incoming as $id) {
259 $settings[$id] = true;
260 }
261 }
262
263 // Save (form) settings
264 $this->exportSettings = new ilUserFormSettings('memexp');
265 $this->exportSettings->set($settings);
266 $this->exportSettings->store();
267 }
268
275 public function export()
276 {
277 $this->handleIncoming();
278
279 $this->export = new ilMemberExport($this->ref_id);
280 $this->export->create();
281
282 $filename = time() . '_participant_export_csv_' . $this->obj_id . '.csv';
283 $this->fss_export->addMemberExportFile($this->export->getCSVString(), $filename);
284
285 $this->ctrl->redirect($this, 'show');
286 }
287
288 public function exportExcel()
289 {
290 $this->handleIncoming();
291
292 $filename = time() . '_participant_export_xls_' . $this->obj_id;
293 $this->fss_export->initMemberExportDirectory();
294 $filepath = $this->fss_export->getMemberExportDirectory() . DIRECTORY_SEPARATOR . $filename;
295
296 $this->export = new ilMemberExport($this->ref_id, ilMemberExport::EXPORT_EXCEL);
297 $this->export->setFilename($filepath);
298 $this->export->create();
299
300 $this->ctrl->redirect($this, 'show');
301 }
302
310 public function deliverData()
311 {
312 foreach ($this->fss_export->getMemberExportFiles() as $file) {
313 if ($file['name'] == $_SESSION['member_export_filename']) {
314 $content = $this->fss_export->getMemberExportFile($_SESSION['member_export_filename']);
315 ilUtil::deliverData($content, date('Y_m_d_H-i', $file['timest']) .
316 '_member_export_' .
317 $this->obj_id .
318 '.csv', 'text/csv');
319 }
320 }
321 }
322
329 public function showFileList()
330 {
331 include_once 'Services/Membership/classes/Export/class.ilMemberExportFileTableGUI.php';
332 $tbl = new ilMemberExportFileTableGUI($this, 'show', $this->fss_export);
333 $this->tpl->setContent($tbl->getHTML());
334 }
335
343 public function downloadExportFile()
344 {
345 $hash = trim($_GET['fl']);
346 if (!$hash) {
347 $this->ctrl->redirect($this, 'show');
348 }
349
350 foreach ($this->fss_export->getMemberExportFiles() as $file) {
351 if (md5($file['name']) == $hash) {
352 $contents = $this->fss_export->getMemberExportFile($file['timest'] . '_participant_export_' .
353 $file['type'] . '_' . $this->obj_id . '.' . $file['type']);
354
355 // newer export files could be .xlsx
356 if ($file['type'] == 'xls' && !$contents) {
357 $contents = $this->fss_export->getMemberExportFile($file['timest'] . '_participant_export_' .
358 $file['type'] . '_' . $this->obj_id . '.xlsx');
359 $file['type'] = 'xlsx';
360 }
361
362 switch ($file['type']) {
363 case 'xlsx':
365 $contents,
366 date('Y_m_d_H-i' . $file['timest']) . '_member_export_' . $this->obj_id . '.xlsx',
367 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
368 );
369
370 // no break
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 // no break
379 default:
380 case 'csv':
381 ilUtil::deliverData($contents, date('Y_m_d_H-i' . $file['timest']) .
382 '_member_export_' .
383 $this->obj_id .
384 '.csv', 'text/csv');
385 break;
386 }
387 return true;
388 }
389 }
390 }
391
399 public function confirmDeleteExportFile()
400 {
401 if (!count($_POST['id'])) {
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 if (!in_array(md5($file['name']), $_POST['id'])) {
416 continue;
417 }
418
419 $confirmation_gui->addItem(
420 "id[]",
421 md5($file['name']),
422 strtoupper($file['type']) . ' - ' .
424 );
425 }
426
427 $this->tpl->setContent($confirmation_gui->getHTML());
428 }
429
437 public function deleteExportFile()
438 {
439 if (!count($_POST['id'])) {
440 $this->ctrl->redirect($this, 'show');
441 }
442
443 $counter = 0;
444 foreach ($this->fss_export->getMemberExportFiles() as $file) {
445 if (!in_array(md5($file['name']), $_POST['id'])) {
446 continue;
447 }
448
449 $ret = $this->fss_export->deleteMemberExportFile($file['timest'] . '_participant_export_' .
450 $file['type'] . '_' . $this->obj_id . '.' . $file['type']);
451
452 //try xlsx if return is false and type is xls
453 if ($file['type'] == "xls" && !$ret) {
454 $this->fss_export->deleteMemberExportFile($file['timest'] . '_participant_export_' .
455 $file['type'] . '_' . $this->obj_id . '.' . "xlsx");
456 }
457 }
458
459 ilUtil::sendSuccess($this->lng->txt('ps_files_deleted'), true);
460 $this->ctrl->redirect($this, 'show');
461 }
462
463
468 protected function initFileSystemStorage()
469 {
470 if ($this->type == 'crs') {
471 $this->fss_export = new ilFSStorageCourse($this->obj_id);
472 }
473 if ($this->type == 'grp') {
474 $this->fss_export = new ilFSStorageGroup($this->obj_id);
475 }
476 }
477}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
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, $a_skip_day=false, $a_include_wd=false)
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.
$counter
$tbl
Definition: example_048.php:81
if(!array_key_exists('StateId', $_REQUEST)) $id
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
$ret
Definition: parser.php:6
if(isset($_POST['submit'])) $form
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$ilUser
Definition: imgupload.php:18