ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCourseArchivesGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 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
36{
39
40 public $tpl;
41 public $ctrl;
42 public $lng;
43 public $tabs_gui;
44
49 public function __construct($content_gui)
50 {
51 global $tpl,$ilCtrl,$lng,$ilObjDataCache,$ilTabs;
52
53 $this->tpl = $tpl;
54 $this->ctrl = $ilCtrl;
55 $this->lng = $lng;
56 $this->tabs_gui = $ilTabs;
57
58 $this->content_gui = $content_gui;
59 $this->content_obj = $this->content_gui->object;
60
61 $this->__initCourseObject();
62 }
63
64
65
66 public function executeCommand()
67 {
68 switch ($this->ctrl->getNextClass($this)) {
69 case 'ilobjectcopygui':
70 include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
71 $cp = new ilObjectCopyGUI($this);
72 $cp->setType('crs');
73 $this->ctrl->forwardCommand($cp);
74 break;
75
76 default:
77 $cmd = $this->ctrl->getCmd();
78 if (!$cmd = $this->ctrl->getCmd()) {
79 $cmd = "view";
80 }
81 $this->$cmd();
82 break;
83 }
84 }
85
86 public function view()
87 {
88 global $ilAccess,$ilErr;
89
90 // MINIMUM ACCESS LEVEL = 'write'
91 if (!$ilAccess->checkAccess("read", '', $this->course_obj->getRefId())) {
92 $ilErr->raiseError($this->lng->txt('msg_no_perm_write'), $ilErr->MESSAGE);
93 }
94
95
96 $this->is_tutor = $ilAccess->checkAccess('write', '', $this->course_obj->getRefId());
97 $this->download_allowed = ($this->is_tutor or $this->course_obj->getArchiveType() == $this->course_obj->ARCHIVE_DOWNLOAD);
98
99 $this->course_obj->initCourseArchiveObject();
100 $this->course_obj->archives_obj->initCourseFilesObject();
101
102
103 $archives = $this->is_tutor ?
104 $this->course_obj->archives_obj->getArchives() :
105 $this->course_obj->archives_obj->getPublicArchives();
106
107 require_once("./Services/Table/classes/class.ilTableGUI.php");
108 $tbl = new ilTableGUI();
109
110 $this->__showArchivesMenu();
111 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
112 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.crs_archives_row.html", 'Modules/Course');
113
114 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
115
116 $tbl->setTitle($this->lng->txt("crs_header_archives"));
117
118
119 if ($this->download_allowed or $this->is_tutor) {
120 $header_names = array('',
121 $this->lng->txt("type"),
122 $this->lng->txt("crs_file_name"),
123 $this->lng->txt("crs_size"),
124 $this->lng->txt("crs_create_date"),
125 $this->lng->txt("crs_archive_lang"));
126
127 $header_vars = array("",
128 "type",
129 "name",
130 "size",
131 "date",
132 "lang");
133 $column_width = array("1%","9%","30%","20%","20%","20%");
134 $this->tpl->setVariable("COLUMN_COUNTS", 6);
135 } else {
136 $header_names = array($this->lng->txt("type"),
137 $this->lng->txt("crs_file_name"),
138 $this->lng->txt("crs_create_date"),
139 $this->lng->txt("crs_size"),
140 $this->lng->txt("crs_archive_lang"));
141
142 $header_vars = array("type",
143 "name",
144 "date",
145 "size",
146 "lang");
147 $column_width = array("10%","30%","20%","20%","20%");
148 $this->tpl->setVariable("COLUMN_COUNTS", 5);
149 }
150
151 $tbl->setHeaderNames($header_names);
152 $tbl->setHeaderVars(
153 $header_vars,
154 array("ref_id" => $this->course_obj->getRefId(),
155 "cmd" => "view",
156 "cmdClass" => strtolower(get_class($this)))
157 );
158 $tbl->setColumnWidth($column_width);
159
160
161 // control
162 $tbl->setOrderColumn($_GET["sort_by"]);
163 $tbl->setOrderDirection($_GET["sort_order"]);
164 $tbl->setLimit($_GET["limit"]);
165 $tbl->setOffset($_GET["offset"]);
166 $tbl->disable("sort");
167
168 if ($this->download_allowed) {
169 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
170 if ($this->is_tutor) {
171 // delete
172 $this->tpl->setCurrentBlock("tbl_action_btn");
173 $this->tpl->setVariable("BTN_NAME", "confirmDeleteArchives");
174 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
175 $this->tpl->parseCurrentBlock();
176 }
177
178 // download
179 $this->tpl->setCurrentBlock("tbl_action_btn");
180 $this->tpl->setVariable("BTN_NAME", "downloadArchives");
181 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("download"));
182 $this->tpl->parseCurrentBlock();
183 }
184
185 $tbl->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next"));
186 $tbl->setMaxCount(count($archives));
187 $archives = array_slice($archives, $_GET['offset'], $_GET['limit']);
188 $tbl->render();
189
190 if (!count($archives)) {
191 $this->tpl->setCurrentBlock("notfound");
192 $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
193 $this->tpl->setVariable("NUM_COLS", 6);
194 $this->tpl->parseCurrentBlock();
195 }
196
197
198 $counter = 0;
199 foreach ($archives as $archive_data) {
200 $this->tpl->setCurrentBlock("tbl_content");
201 $this->tpl->setVariable("CSS_ROW", ilUtil::switchColor($counter++, 'tblrow1', 'tblrow2'));
202
203
204 if ($this->download_allowed) {
205 $this->tpl->setVariable("VAL_CHECK", ilUtil::formCheckbox(0, "archives[]", $archive_data['archive_id']));
206 }
207 // Type
208 switch ($archive_data["archive_type"]) {
209 case $this->course_obj->archives_obj->ARCHIVE_XML:
210 $type = $this->lng->txt("crs_xml");
211 break;
212
213 case $this->course_obj->archives_obj->ARCHIVE_HTML:
214 $type = $this->lng->txt("crs_html");
215 break;
216
217 case $this->course_obj->archives_obj->ARCHIVE_PDF:
218 $type = $this->lng->txt("crs_pdf");
219 break;
220 }
221 $this->tpl->setVariable("VAL_TYPE", $type);
222
223 // Name
224 if ($archive_data['archive_type'] == $this->course_obj->archives_obj->ARCHIVE_HTML) {
225 $link = '<a href="' . $this->course_obj->archives_obj->course_files_obj->getOnlineLink($archive_data['archive_name']) . '"' .
226 ' target="_blank">' . $archive_data["archive_name"] . '</a>';
227 } else {
228 $link = $archive_data['archive_name'];
229 }
230
231 $this->tpl->setVariable("VAL_NAME", $link);
232 $this->tpl->setVariable("VAL_SIZE", $archive_data['archive_size']);
233 $this->tpl->setVariable('VAL_DATE', ilDatePresentation::formatDate(new ilDateTime($archive_data['archive_name'], IL_CAL_UNIX)));
234
235 if ($archive_data["archive_lang"]) {
236 $this->tpl->setVariable("VAL_LANG", $this->lng->txt('lang_' . $archive_data["archive_lang"]));
237 } else {
238 $this->tpl->setVariable("VAL_LANG", $this->lng->txt('crs_not_available'));
239 }
240 $this->tpl->parseCurrentBlock();
241 }
242 $this->tpl->parseCurrentBlock();
243 }
244
245
246 public function confirmDeleteArchives()
247 {
248 global $ilAccess,$ilErr;
249
250 // MINIMUM ACCESS LEVEL = 'write'
251 if (!$ilAccess->checkAccess("write", '', $this->course_obj->getRefId())) {
252 $ilErr->raiseError($this->lng->txt('msg_no_perm_write'), $ilErr->MESSAGE);
253 }
254
255 if (!$_POST['archives']) {
256 ilUtil::sendFailure($this->lng->txt("crs_no_archives_selected"));
257 $this->view();
258 return false;
259 }
260 $_SESSION["crs_archives"] = $_POST["archives"];
261 ilUtil::sendQuestion($this->lng->txt("crs_sure_delete_selected_archives"));
262
263 $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.crs_confirm_delete_archives.html', 'Modules/Course');
264 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
265 $this->tpl->setVariable("TXT_ARCHIVE_NAME", $this->lng->txt('crs_file_name'));
266
267 $this->course_obj->initCourseArchiveObject();
268 $counter = 0;
269
270 foreach ($_POST['archives'] as $archive_id) {
271 $archive = $this->course_obj->archives_obj->getArchive($archive_id);
272 $this->tpl->setCurrentBlock("archives");
273
274 $this->tpl->setVariable("ARCHIVE_NAME", $archive['archive_name']);
275 $this->tpl->setVariable("CSS_ROW", ilUtil::switchColor($counter++, 'tblrow1', 'tblrow2'));
276 $this->tpl->parseCurrentBlock();
277 }
278
279 $this->tpl->setVariable("DELETE", $this->lng->txt('delete'));
280 $this->tpl->setVariable("CANCEL", $this->lng->txt('cancel'));
281
282 return true;
283 }
284
285 public function delete()
286 {
287 global $ilAccess,$ilErr;
288
289 // MINIMUM ACCESS LEVEL = 'write'
290 if (!$ilAccess->checkAccess("write", '', $this->course_obj->getRefId())) {
291 $ilErr->raiseError($this->lng->txt('msg_no_perm_write'), $ilErr->MESSAGE);
292 }
293
294 if (!$_SESSION['crs_archives']) {
295 ilUtil::sendFailure($this->lng->txt("crs_no_archives_selected"));
296 $this->view();
297 }
298
299 $this->course_obj->initCourseArchiveObject();
300 foreach ($_SESSION['crs_archives'] as $archive_id) {
301 $this->course_obj->archives_obj->delete($archive_id);
302 }
303
304 ilUtil::sendSuccess($this->lng->txt('crs_archives_deleted'));
305 unset($_SESSION["crs_archives"]);
306
307 $this->view();
308 return true;
309 }
310
314 public function selectXMLArchiveItems()
315 {
316 global $tpl;
317
318 include_once("./Services/Export/classes/class.ilSubItemSelectionTableGUI.php");
319 $sel_table = new ilSubItemSelectionTableGUI(
320 $this,
321 "selectXMlArchiveItems",
322 $this->course_obj->getRefId(),
323 "addXMLArchive",
324 $this->lng->txt("crs_add_archive_xml")
325 );
326 $tpl->setContent($sel_table->getHTML());
327 }
328
329 public function addXMLArchive()
330 {
331 global $ilAccess;
332
333 // MINIMUM ACCESS LEVEL = 'write'
334 if (!$ilAccess->checkAccess("write", '', $this->course_obj->getRefId())) {
335 $ilErr->raiseError($this->lng->txt('msg_no_perm_write'), $ilErr->MESSAGE);
336 }
337
338 $this->course_obj->initCourseArchiveObject();
339 $this->course_obj->archives_obj->addXML($_POST["sel"]);
340
341 ilUtil::sendSuccess($this->lng->txt("crs_added_new_archive"));
342 $this->view();
343
344 return true;
345 }
346
347 public function selectArchiveLanguage()
348 {
349 global $ilAccess;
350
351 // MINIMUM ACCESS LEVEL = 'write'
352 if (!$ilAccess->checkAccess("write", '', $this->course_obj->getRefId())) {
353 $ilErr->raiseError($this->lng->txt('msg_no_perm_write'), $ilErr->MESSAGE);
354 }
355
356 foreach ($this->lng->getInstalledLanguages() as $lang_code) {
357 $actions["$lang_code"] = $this->lng->txt('lang_' . $lang_code);
358
359 if ($this->lng->getLangKey() == $lang_code) {
360 $selected = $lang_code;
361 }
362 }
363
364 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_selectLanguage.html", 'Modules/Course');
365
366 $this->tpl->setVariable("LANGUAGE_SELECTION", $this->lng->txt('crs_archive_language_selection'));
367 $this->tpl->setVariable("LANGUAGE", $this->lng->txt('obj_lng'));
368 $this->tpl->setVariable("INFO_TXT", $this->lng->txt('crs_select_archive_language'));
369 $this->tpl->setVariable("SELECT_FORMACTION", $this->ctrl->getFormAction($this));
370 $this->tpl->setVariable("LANG_SELECTOR", ilUtil::formSelect($selected, 'lang', $actions, false, true));
371 $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt('cancel'));
372 $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt('crs_add_html_archive'));
373
374 return true;
375 }
376
377 public function addHTMLArchive()
378 {
379 global $ilAccess;
380
381 // MINIMUM ACCESS LEVEL = 'write'
382 if (!$ilAccess->checkAccess("write", '', $this->course_obj->getRefId())) {
383 $ilErr->raiseError($this->lng->txt('msg_no_perm_write'), $ilErr->MESSAGE);
384 }
385
386 $this->course_obj->initCourseArchiveObject();
387 $this->course_obj->archives_obj->setLanguage($_POST['lang']);
388 $this->course_obj->archives_obj->addHTML();
389
390 ilUtil::sendSuccess($this->lng->txt("crs_added_new_archive"));
391 $this->view();
392
393 return true;
394 }
395
396 public function downloadArchives()
397 {
398 global $ilAccess;
399
400 // MINIMUM ACCESS LEVEL = 'write'
401 if (!$ilAccess->checkAccess("read", '', $this->course_obj->getRefId())) {
402 $ilErr->raiseError($this->lng->txt('msg_no_perm_write'), $ilErr->MESSAGE);
403 }
404
405 $_POST["archives"] = $_POST["archives"] ? $_POST["archives"] : array();
406
407 if (!count($_POST['archives'])) {
408 ilUtil::sendFailure($this->lng->txt('crs_no_archive_selected'));
409 $this->view();
410
411 return false;
412 }
413 if (count($_POST['archives']) > 1) {
414 ilUtil::sendFailure($this->lng->txt('crs_select_one_archive'));
415 $this->view();
416
417 return false;
418 }
419
420 $this->course_obj->initCourseArchiveObject();
421
422 $abs_path = $this->course_obj->archives_obj->getArchiveFile((int) $_POST['archives'][0]);
423 $basename = basename($abs_path);
424
425 ilUtil::deliverFile($abs_path, $basename);
426 }
427
428
429 public function __showArchivesMenu()
430 {
431 if (!$this->is_tutor) {
432 return false;
433 }
434 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
435
436 if (!PATH_TO_ZIP) {
437 ilUtil::sendFailure($this->lng->txt('zip_test_failed'));
438 return true;
439 }
440 /*
441 $this->tpl->setCurrentBlock("btn_cell");
442 $link = $this->ctrl->getLinkTargetByClass(
443 'ilobjectcopygui',
444 'initSourceSelection'
445 );
446 $this->tpl->setVariable('BTN_LINK',$link);
447 $this->tpl->setVariable("BTN_TXT", $this->lng->txt("clone_existing_course"));
448 $this->tpl->parseCurrentBlock();
449 */
450 // create xml archive button
451 $this->tpl->setCurrentBlock("btn_cell");
452 $this->tpl->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this, "selectXMLArchiveItems"));
453 $this->tpl->setVariable("BTN_TXT", $this->lng->txt("crs_add_archive_xml"));
454 $this->tpl->parseCurrentBlock();
455
456 $this->tpl->setCurrentBlock("btn_cell");
457 $this->tpl->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this, "selectArchiveLanguage"));
458 $this->tpl->setVariable("BTN_TXT", $this->lng->txt("crs_add_archive_html"));
459 $this->tpl->parseCurrentBlock();
460
461 return true;
462 }
463
464 public function __initCourseObject()
465 {
466 global $tree;
467
468 if ($this->content_obj->getType() == 'crs') {
469 // Container is course
470 $this->course_obj =&$this->content_obj;
471 } else {
472 $course_ref_id = $tree->checkForParentType($this->content_obj->getRefId(), 'crs');
473 $this->course_obj =&ilObjectFactory::getInstanceByRefId($course_ref_id);
474 }
475 return true;
476 }
477} // END class.ilCourseArchivesGUI
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Class ilCourseArchivesGUI.
__construct($content_gui)
Constructor @access public.
selectXMLArchiveItems()
Select items for archive.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
@classDescription Date and time handling
GUI class for the workflow of copying objects.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilTableGUI.
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 switchColor($a_num, $a_css1, $a_css2)
switches style sheets for each even $a_num (used for changing colors of different result rows)
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static formSelect( $selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$counter
$tbl
Definition: example_048.php:81
global $ilCtrl
Definition: ilias.php:18
$type