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