ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSAHSLearningModuleGUI.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 
24 require_once "classes/class.ilObjectGUI.php";
25 require_once("classes/class.ilFileSystemGUI.php");
26 require_once("classes/class.ilTabsGUI.php");
27 
39 {
45  function ilObjSAHSLearningModuleGUI($a_data,$a_id,$a_call_by_reference, $a_prepare_output = true)
46  {
47  global $lng;
48 
49  $lng->loadLanguageModule("content");
50  $this->type = "sahs";
51  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,false);
52  #$this->tabs_gui =& new ilTabsGUI();
53 
54  }
55 
59  function &executeCommand()
60  {
61  global $ilAccess;
62 
63  if (strtolower($_GET["baseClass"]) == "iladministrationgui" ||
64  $this->getCreationMode() == true)
65  {
66  $this->prepareOutput();
67  }
68  else
69  {
70  $this->getTemplate();
71  $this->setLocator();
72  $this->setTabs();
73  }
74 
75  $next_class = $this->ctrl->getNextClass($this);
76  $cmd = $this->ctrl->getCmd();
77 
78  switch($next_class)
79  {
80  case 'ilmdeditorgui':
81 
82  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
83 
84  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
85  $md_gui->addObserver($this->object,'MDUpdateListener','General');
86 
87  $this->ctrl->forwardCommand($md_gui);
88  break;
89 
90  case 'ilpermissiongui':
91  include_once("./classes/class.ilPermissionGUI.php");
92  $perm_gui =& new ilPermissionGUI($this);
93  $ret =& $this->ctrl->forwardCommand($perm_gui);
94  break;
95 
96  case "ilfilesystemgui":
97  $this->fs_gui =& new ilFileSystemGUI($this->object->getDataDirectory());
98  $ret =& $this->ctrl->forwardCommand($this->fs_gui);
99  break;
100 
101  case "illearningprogressgui":
102  include_once './Services/Tracking/classes/class.ilLearningProgressGUI.php';
103 
104  $new_gui =& new ilLearningProgressGUI(LP_MODE_REPOSITORY,$this->object->getRefId());
105  $this->ctrl->forwardCommand($new_gui);
106 
107  break;
108 
109  case "ilinfoscreengui":
110  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
111 
112  $info = new ilInfoScreenGUI($this);
113  $info->enablePrivateNotes();
114  $info->enableLearningProgress();
115 
116  // add read / back button
117  if ($ilAccess->checkAccess("read", "", $_GET["ref_id"]))
118  {
119  $info->addButton($this->lng->txt("view"),
120  "ilias.php?baseClass=ilSAHSPresentationGUI&amp;ref_id=".$this->object->getRefID(),
121  ' target="ilContObj'.$this->object->getId().'" ');
122  }
123 
124  $info->enableNews();
125  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
126  {
127  $info->enableNewsEditing();
128  $news_set = new ilSetting("news");
129  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
130  if ($enable_internal_rss)
131  {
132  $info->setBlockProperty("news", "settings", true);
133  }
134  }
135  // show standard meta data section
136  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
137 
138  // forward the command
139  $this->ctrl->forwardCommand($info);
140  break;
141 
142  default:
143  $cmd = $this->ctrl->getCmd("frameset");
144  if ((strtolower($_GET["baseClass"]) == "iladministrationgui" ||
145  $this->getCreationMode() == true) &&
146  $cmd != "frameset")
147  {
148  $cmd.= "Object";
149  }
150 
151  $ret =& $this->$cmd();
152  break;
153  }
154  }
155 
156 
157  function viewObject()
158  {
159  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
160  {
162  }
163  else
164  {
165  }
166  }
167 
171  function properties()
172  {
173  }
174 
178  function saveProperties()
179  {
180  }
181 
182 
186  function createObject()
187  {
188  $this->importObject();
189  }
190 
196  function importObject()
197  {
198  // display import form
199  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.slm_import.html", "Modules/ScormAicc");
200 
201  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_slm.gif'));
202  $this->tpl->setVariable("ALT_IMG", $this->lng->txt("obj_sahs"));
203 
204  $this->ctrl->setParameter($this, "new_type", "sahs");
205  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
206 
207  $this->tpl->setVariable("BTN_NAME", "save");
208  $this->tpl->setVariable("TARGET", ' target="'.
209  ilFrameTargetInfo::_getFrame("MainContent").'" ');
210 
211  $this->tpl->setVariable("TXT_SELECT_LMTYPE", $this->lng->txt("type"));
212  $this->tpl->setVariable("TXT_TYPE_AICC", $this->lng->txt("lm_type_aicc"));
213  $this->tpl->setVariable("TXT_TYPE_HACP", $this->lng->txt("lm_type_hacp"));
214  $this->tpl->setVariable("TXT_TYPE_SCORM", $this->lng->txt("lm_type_scorm"));
215 
216  $this->tpl->setVariable("TXT_TYPE_SCORM2004", $this->lng->txt("lm_type_scorm2004"));
217 
218  $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
219  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
220  $this->tpl->setVariable("TXT_IMPORT_LM", $this->lng->txt("import_sahs"));
221  $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
222  $this->tpl->setVariable("TXT_VALIDATE_FILE", $this->lng->txt("cont_validate_file"));
223 
224  // get the value for the maximal uploadable filesize from the php.ini (if available)
225  $umf=get_cfg_var("upload_max_filesize");
226  // get the value for the maximal post data from the php.ini (if available)
227  $pms=get_cfg_var("post_max_size");
228 
229  //convert from short-string representation to "real" bytes
230  $multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
231 
232  $umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
233  $pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
234 
235  if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
236  if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
237 
238  // use the smaller one as limit
239  $max_filesize=min($umf, $pms);
240 
241  if (!$max_filesize) $max_filesize=max($umf, $pms);
242 
243  //format for display in mega-bytes
244  $max_filesize=sprintf("%.1f MB",$max_filesize/1024/1024);
245 
246  // gives out the limit as a little notice
247  $this->tpl->setVariable("TXT_FILE_INFO", $this->lng->txt("file_notice")." $max_filesize");
248  }
249 
256  function uploadObject()
257  {
258  global $_FILES, $rbacsystem;
259 
260  // check if file was uploaded
261  $source = $_FILES["scormfile"]["tmp_name"];
262  if (($source == 'none') || (!$source))
263  {
264  $this->ilias->raiseError("No file selected!",$this->ilias->error_obj->MESSAGE);
265  }
266  // check create permission
267  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], "sahs"))
268  {
269  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->WARNING);
270  }
271  // get_cfg_var("upload_max_filesize"); // get the may filesize form t he php.ini
272  switch ($__FILES["scormfile"]["error"])
273  {
274  case UPLOAD_ERR_INI_SIZE:
275  $this->ilias->raiseError($this->lng->txt("err_max_file_size_exceeds"),$this->ilias->error_obj->MESSAGE);
276  break;
277 
278  case UPLOAD_ERR_FORM_SIZE:
279  $this->ilias->raiseError($this->lng->txt("err_max_file_size_exceeds"),$this->ilias->error_obj->MESSAGE);
280  break;
281 
282  case UPLOAD_ERR_PARTIAL:
283  $this->ilias->raiseError($this->lng->txt("err_partial_file_upload"),$this->ilias->error_obj->MESSAGE);
284  break;
285 
286  case UPLOAD_ERR_NO_FILE:
287  $this->ilias->raiseError($this->lng->txt("err_no_file_uploaded"),$this->ilias->error_obj->MESSAGE);
288  break;
289  }
290 
291  $file = pathinfo($_FILES["scormfile"]["name"]);
292  $name = substr($file["basename"], 0, strlen($file["basename"]) - strlen($file["extension"]) - 1);
293  if ($name == "")
294  {
295  $name = $this->lng->txt("no_title");
296  }
297 
298  // create and insert object in objecttree
299  switch ($_POST["sub_type"])
300  {
301 
302  case "scorm2004":
303  include_once("./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php");
304  $newObj = new ilObjSCORM2004LearningModule();
305  break;
306 
307  case "scorm":
308  include_once("./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php");
309  $newObj = new ilObjSCORMLearningModule();
310  break;
311 
312  case "aicc":
313  include_once("./Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php");
314  $newObj = new ilObjAICCLearningModule();
315  break;
316 
317  case "hacp":
318  include_once("./Modules/ScormAicc/classes/class.ilObjHACPLearningModule.php");
319  $newObj = new ilObjHACPLearningModule();
320  break;
321  }
322 
323  $newObj->setTitle($name);
324  $newObj->setSubType($_POST["sub_type"]);
325  $newObj->setDescription("");
326  $newObj->create();
327  $newObj->createReference();
328  $newObj->putInTree($_GET["ref_id"]);
329  $newObj->setPermissions($_GET["ref_id"]);
330  $newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
331 
332  // create data directory, copy file to directory
333  $newObj->createDataDirectory();
334 
335  // copy uploaded file to data directory
336  $file_path = $newObj->getDataDirectory()."/".$_FILES["scormfile"]["name"];
337 
338  ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"],
339  $_FILES["scormfile"]["name"], $file_path);
340 
341  //move_uploaded_file($_FILES["scormfile"]["tmp_name"], $file_path);
342 
343  ilUtil::unzip($file_path);
344  ilUtil::renameExecutables($newObj->getDataDirectory());
345 
346  $title = $newObj->readObject();
347  if ($title != "")
348  {
349  ilObject::_writeTitle($newObj->getId(), $title);
350  $md = new ilMD($newObj->getId(),0, $newObj->getType());
351  if(is_object($md_gen = $md->getGeneral()))
352  {
353  $md_gen->setTitle($title);
354  $md_gen->update();
355  }
356  }
357 
358  ilUtil::sendInfo( $this->lng->txt($newObj->getType()."_added"), true);
359  ilUtil::redirect("ilias.php?baseClass=ilSAHSEditGUI&ref_id=".$newObj->getRefId());
360  }
361 
362  function upload()
363  {
364  $this->uploadObject();
365  }
366 
370  function saveObject()
371  {
372  global $rbacadmin;
373 
374  $this->uploadObject();
375  }
376 
377 
381  function info()
382  {
383  $this->infoObject();
384  }
385 
389  function owner()
390  {
391  $this->ownerObject();
392  }
393 
397  function getTemplate()
398  {
399  global $lng;
400 
401  $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
402  //$this->tpl->setVariable("HEADER", $a_header_title);
403  $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
404  //$this->tpl->setVariable("TXT_LOCATOR",$this->lng->txt("locator"));
405  }
406 
407 
413  function frameset()
414  {
415  $this->tpl = new ilTemplate("tpl.sahs_edit_frameset.html", false, false, "Modules/ScormAicc");
416  $this->tpl->setVariable("SRC",
417  $this->ctrl->getLinkTarget($this, "properties"));
418  $this->tpl->show("DEFAULT", false);
419  exit;
420  }
421 
425  function setTabs()
426  {
427  $this->tpl->setCurrentBlock("header_image");
428  $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_lm_b.gif"));
429  $this->tpl->parseCurrentBlock();
430 
431  $this->getTabs($this->tabs_gui);
432  #$this->tpl->setVariable("TABS", $this->tabs_gui->getHTML());
433  $this->tpl->setVariable("HEADER", $this->object->getTitle());
434  }
435 
441  function getTabs(&$tabs_gui)
442  {
443  global $rbacsystem,$ilUser;
444 
445  if ($this->ctrl->getCmd() == "delete")
446  {
447  return;
448  }
449 
450  // info screen
451  $force_active = ($this->ctrl->getNextClass() == "ilinfoscreengui")
452  ? true
453  : false;
454  $tabs_gui->addTarget("info_short",
455  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"), "",
456  "ilinfoscreengui", "", $force_active);
457 
458  // properties
459  $tabs_gui->addTarget("properties",
460  $this->ctrl->getLinkTarget($this, "properties"), "properties",
461  get_class($this));
462 
463  // file system gui tabs
464  // properties
465  $tabs_gui->addTarget("cont_list_files",
466  $this->ctrl->getLinkTargetByClass("ilfilesystemgui", "listFiles"), "",
467  "ilfilesystemgui");
468 
469  // tracking data
470  $tabs_gui->addTarget("cont_tracking_data",
471  $this->ctrl->getLinkTarget($this, "showTrackingItems"), "showTrackingItems",
472  get_class($this));
473 
474  // edit meta
475 /*
476  $tabs_gui->addTarget("meta_data",
477  $this->ctrl->getLinkTarget($this, "editMeta"), "editMeta",
478  get_class($this));
479 */
480  $tabs_gui->addTarget("meta_data",
481  $this->ctrl->getLinkTargetByClass('ilmdeditorgui',''),
482  "", "ilmdeditorgui");
483 
484  // learning progress
485  include_once './Services/Tracking/classes/class.ilLearningProgressAccess.php';
486  if(ilLearningProgressAccess::checkAccess($this->object->getRefId()))
487  {
488  $tabs_gui->addTarget('learning_progress',
489  $this->ctrl->getLinkTargetByClass(array('illearningprogressgui'),''),
490  '',
491  array('illplistofobjectsgui','illplistofsettingsgui','illearningprogressgui','illplistofprogressgui'));
492  }
493 
494  // perm
495  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
496  {
497  $tabs_gui->addTarget("perm_settings",
498  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
499  }
500 
501  // owner
502 /*
503  $tabs_gui->addTarget("owner",
504  $this->ctrl->getLinkTarget($this, "owner"), "owner",
505  get_class($this));
506 */
507  }
508 
512  function _goto($a_target)
513  {
514  global $ilAccess, $ilErr, $lng;
515 
516  // to do: force flat view
517  if ($ilAccess->checkAccess("visible", "", $a_target))
518  {
519  $_GET["cmd"] = "infoScreen";
520  $_GET["baseClass"] = "ilSAHSPresentationGUI";
521  $_GET["ref_id"] = $a_target;
522  include("ilias.php");
523  exit;
524  }
525  else
526  {
527  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
528  {
529  $_GET["cmd"] = "frameset";
530  $_GET["target"] = "";
531  $_GET["ref_id"] = ROOT_FOLDER_ID;
532  ilUtil::sendInfo(sprintf($lng->txt("msg_no_perm_read_item"),
534  include("repository.php");
535  exit;
536  }
537  }
538 
539  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
540  }
541 
542  function addLocatorItems()
543  {
544  global $ilLocator;
545 
546  if (is_object($this->object))
547  {
548  $ilLocator->addItem($this->object->getTitle(),
549  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"), "", $_GET["ref_id"]);
550  }
551  }
552 
553 } // END class.ilObjSAHSLearningModule
554 ?>