ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSCORMLearningModuleGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObjectGUI.php";
6 require_once("./Services/FileSystem/classes/class.ilFileSystemGUI.php");
7 require_once("Services/User/classes/class.ilObjUser.php");
8 
9 require_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModuleGUI.php");
10 require_once("./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php");
11 
26 {
27  const EXPORT_UNDEF = 0;
28  const EXPORT_ALL = 1;
29  const EXPORT_SELECTED = 2;
30 
31  const EXPORT_TYPE_RAW = 1;
33 
39  function ilObjSCORMLearningModuleGUI($a_data,$a_id,$a_call_by_reference, $a_prepare_output = true)
40  {
41  global $lng;
42 
43  $lng->loadLanguageModule("content");
44  $lng->loadLanguageModule("search");
45 
46  $this->type = "sahs";
47  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,false);
48  }
49 
53  function assignObject()
54  {
55  if ($this->id != 0)
56  {
57  if ($this->call_by_reference)
58  {
59  $this->object =& new ilObjSCORMLearningModule($this->id, true);
60  }
61  else
62  {
63  $this->object =& new ilObjSCORMLearningModule($this->id, false);
64  }
65  }
66  }
67 
71  function properties()
72  {
73  global $rbacsystem, $tree, $tpl;
74 
75  // edit button
76  $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
77 
78  // view link
79  $this->tpl->setCurrentBlock("btn_cell");
80  $this->tpl->setVariable("BTN_LINK","ilias.php?baseClass=ilSAHSPresentationGUI&amp;ref_id=".$this->object->getRefID());
81  $this->tpl->setVariable("BTN_TARGET"," target=\"ilContObj".$this->object->getID()."\" ");
82  $this->tpl->setVariable("BTN_TXT",$this->lng->txt("view"));
83  $this->tpl->parseCurrentBlock();
84 
85  if (ilObjSAHSLearningModule::_lookupSubType($this->object->getID()) == "scorm") {
86  // upload new version
87  $this->tpl->setCurrentBlock("btn_cell");
88  $this->tpl->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this, "newModuleVersion"));
89  $this->tpl->setVariable("BTN_TXT",$this->lng->txt("cont_sc_new_version"));
90  $this->tpl->parseCurrentBlock();
91  }
92 
93  // scorm lm properties
94  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.sahs_properties.html", "Modules/ScormAicc");
95  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
96  $this->tpl->setVariable("TXT_PROPERTIES", $this->lng->txt("cont_lm_properties"));
97 
98  // online
99  $this->tpl->setVariable("TXT_ONLINE", $this->lng->txt("cont_online"));
100  $this->tpl->setVariable("CBOX_ONLINE", "cobj_online");
101  $this->tpl->setVariable("VAL_ONLINE", "y");
102  if ($this->object->getOnline())
103  {
104  $this->tpl->setVariable("CHK_ONLINE", "checked");
105  }
106 
107  //open
108  $this->tpl->setVariable("TXT_OPEN", $this->lng->txt("cont_open"));
109  $open_modes = array(
110  "0" => $this->lng->txt("cont_open_normal"),
111  "1" => $this->lng->txt("cont_open_iframe_max"),
112  "2" => $this->lng->txt("cont_open_iframe_defined"),
113  "5" => $this->lng->txt("cont_open_window_undefined"),
114  "6" => $this->lng->txt("cont_open_window_defined")
115  );
116  $sel_open = ilUtil::formSelect($this->object->getOpenMode(),
117  "open_mode", $open_modes, false, true);
118  $this->tpl->setVariable("SEL_OPEN", $sel_open);
119 
120  //width
121  $this->tpl->setVariable("TXT_WIDTH", $this->lng->txt("cont_open_width"));
122  $this->tpl->setVariable("VAL_WIDTH", $this->object->getWidth());
123 
124  //heigth
125  $this->tpl->setVariable("TXT_HEIGHT", $this->lng->txt("cont_open_heigth"));
126  $this->tpl->setVariable("VAL_HEIGHT", $this->object->getHeight());
127 
128  // api adapter name
129  $this->tpl->setVariable("TXT_API_ADAPTER", $this->lng->txt("cont_api_adapter"));
130  $this->tpl->setVariable("VAL_API_ADAPTER", $this->object->getAPIAdapterName());
131 
132  // api functions prefix
133  $this->tpl->setVariable("TXT_API_PREFIX", $this->lng->txt("cont_api_func_prefix"));
134  $this->tpl->setVariable("VAL_API_PREFIX", $this->object->getAPIFunctionsPrefix());
135 
136  // default lesson mode
137  $this->tpl->setVariable("TXT_LESSON_MODE", $this->lng->txt("cont_def_lesson_mode"));
138  $lesson_modes = array("normal" => $this->lng->txt("cont_sc_less_mode_normal"),
139  "browse" => $this->lng->txt("cont_sc_less_mode_browse"));
140  $sel_lesson = ilUtil::formSelect($this->object->getDefaultLessonMode(),
141  "lesson_mode", $lesson_modes, false, true);
142  $this->tpl->setVariable("SEL_LESSON_MODE", $sel_lesson);
143 
144  // credit mode
145  $this->tpl->setVariable("TXT_CREDIT_MODE", $this->lng->txt("cont_credit_mode"));
146  $credit_modes = array("credit" => $this->lng->txt("cont_credit_on"),
147  "no_credit" => $this->lng->txt("cont_credit_off"));
148  $sel_credit = ilUtil::formSelect($this->object->getCreditMode(),
149  "credit_mode", $credit_modes, false, true);
150  $this->tpl->setVariable("SEL_CREDIT_MODE", $sel_credit);
151 
152  // auto review mode
153  $this->tpl->setVariable("TXT_AUTO_REVIEW", $this->lng->txt("cont_sc_auto_review"));
154  $this->tpl->setVariable("CBOX_AUTO_REVIEW", "auto_review");
155  $this->tpl->setVariable("VAL_AUTO_REVIEW", "y");
156  if ($this->object->getAutoReview())
157  {
158  $this->tpl->setVariable("CHK_AUTO_REVIEW", "checked");
159  }
160 
161  // max attempts
162  $this->tpl->setVariable("MAX_ATTEMPTS", $this->lng->txt("cont_sc_max_attempt"));
163  $this->tpl->setVariable("VAL_MAX_ATTEMPT", $this->object->getMaxAttempt());
164 
165  // version
166  $this->tpl->setVariable("TXT_VERSION", $this->lng->txt("cont_sc_version"));
167  $this->tpl->setVariable("VAL_VERSION", $this->object->getModuleVersion());
168 
169  //unlimited session
170  $this->tpl->setVariable("TXT_SESSION", $this->lng->txt("cont_sc_usession"));
171  $this->tpl->setVariable("CBOX_SESSION", "cobj_session");
172  $this->tpl->setVariable("VAL_SESSION", "y");
173  if ($this->object->getSession())
174  {
175  $this->tpl->setVariable("CHK_SESSION", "checked");
176  }
177 
178  // auto continue
179  $this->tpl->setVariable("TXT_AUTO_CONTINUE", $this->lng->txt("cont_sc_auto_continue"));
180  $this->tpl->setVariable("CBOX_AUTO_CONTINUE", "auto_continue");
181  $this->tpl->setVariable("VAL_AUTO_CONTINUE", "y");
182  if ($this->object->getAutoContinue())
183  {
184  $this->tpl->setVariable("CHK_AUTO_CONTINUE", "checked");
185  }
186 
187  //enable auto navigation to last visited item
188  $this->tpl->setVariable("TXT_AUTO_LAST_VISITED", $this->lng->txt("cont_auto_last_visited"));
189  $this->tpl->setVariable("CBOX_AUTO_LAST_VISITED", "cobj_auto_last_visited");
190  $this->tpl->setVariable("VAL_AUTO_LAST_VISITED", "y");
191  if ($this->object->getAuto_last_visited())
192  {
193  $this->tpl->setVariable("CHK_AUTO_LAST_VISITED", "checked");
194  }
195 
196  //check_values
197  $this->tpl->setVariable("TXT_CHECK_VALUES", $this->lng->txt("cont_check_values"));
198  $this->tpl->setVariable("CBOX_CHECK_VALUES", "cobj_check_values");
199  $this->tpl->setVariable("VAL_CHECK_VALUES", "y");
200  if ($this->object->getCheck_values())
201  {
202  $this->tpl->setVariable("CHK_CHECK_VALUES", "checked");
203  }
204 
205  //debug
206  $this->tpl->setVariable("TXT_DEBUG", $this->lng->txt("cont_debug"));
207  $this->tpl->setVariable("CBOX_DEBUG", "cobj_debug");
208  $this->tpl->setVariable("VAL_DEBUG", "y");
209  if ($this->object->getDebug())
210  {
211  $this->tpl->setVariable("CHK_DEBUG", "checked");
212  }
213 
214  //debugActivated
215  if ($this->object->getDebugActivated() == false) {
216  $this->tpl->setVariable("CHK_ACTIVATED", "disabled");
217  $this->tpl->setVariable("TXT_ACTIVATED", $this->lng->txt("cont_debug_deactivated"));
218  } else {
219  $this->tpl->setVariable("TXT_ACTIVATED", $this->lng->txt("cont_debug_deactivate"));
220  }
221 
222  $this->tpl->setCurrentBlock("commands");
223  $this->tpl->setVariable("BTN_NAME", "saveProperties");
224  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
225  $this->tpl->parseCurrentBlock();
226 
227  }
228 
232  function newModuleVersion()
233  {
236 
237  // display import form
238  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.scorm_new_version_import.html", "Modules/ScormAicc");
239 
240  $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_slm.png'));
241  $this->tpl->setVariable("ALT_IMG", $this->lng->txt("obj_sahs"));
242 
243  $this->ctrl->setParameter($this, "new_type", "sahs");
244  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
245 
246  $this->tpl->setVariable("BTN_NAME", "newModuleVersionUpload");
247  $this->tpl->setVariable("TARGET", ' target="'.
248  ilFrameTargetInfo::_getFrame("MainContent").'" ');
249 
250  $this->tpl->setVariable("TXT_SELECT_LMTYPE", $this->lng->txt("type"));
251 
252  if ($type == "scorm2004") {
253  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("lm_type_scorm2004"));
254  } else {
255  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("lm_type_scorm"));
256  }
257 
258  include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
260  {
262  foreach($files as $file)
263  {
264  $file = htmlspecialchars($file, ENT_QUOTES, "utf-8");
265  $this->tpl->setCurrentBlock("option_uploaded_file");
266  $this->tpl->setVariable("UPLOADED_FILENAME", $file);
267  $this->tpl->setVariable("TXT_UPLOADED_FILENAME", $file);
268  $this->tpl->parseCurrentBlock();
269  }
270  $this->tpl->setCurrentBlock("select_uploaded_file");
271  $this->tpl->setVariable("TXT_SELECT_FROM_UPLOAD_DIR", $this->lng->txt("cont_select_from_upload_dir"));
272  $this->tpl->setVariable("TXT_UPLOADED_FILE", $this->lng->txt("cont_uploaded_file"));
273  $this->tpl->parseCurrentBlock();
274  }
275 
276  $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
277  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
278  $this->tpl->setVariable("TXT_IMPORT_LM", $this->lng->txt("import_sahs"));
279  $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
280 
281  // gives out the limit as a little notice
282  $this->tpl->setVariable("TXT_FILE_INFO", $this->lng->txt("file_notice")." ".$this->getMaxFileSize());
283  }
284 
285 
286  function getMaxFileSize()
287  {
288  // get the value for the maximal uploadable filesize from the php.ini (if available)
289  $umf=get_cfg_var("upload_max_filesize");
290  // get the value for the maximal post data from the php.ini (if available)
291  $pms=get_cfg_var("post_max_size");
292 
293  //convert from short-string representation to "real" bytes
294  $multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
295 
296  $umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
297  $pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
298 
299  if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
300  if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
301 
302  // use the smaller one as limit
303  $max_filesize=min($umf, $pms);
304 
305  if (!$max_filesize) $max_filesize=max($umf, $pms);
306 
307  //format for display in mega-bytes
308  return $max_filesize=sprintf("%.1f MB",$max_filesize/1024/1024);
309  }
310 
311 
313  {
314  global $_FILES, $rbacsystem;
315 
316  $unzip = PATH_TO_UNZIP;
317  $tocheck = "imsmanifest.xml";
318 
319  include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
320 
321  // check create permission before because the uploaded file will be copied
322  if (!$rbacsystem->checkAccess("write", $_GET["ref_id"]))
323  {
324  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->WARNING);
325  }
326  elseif ($_FILES["scormfile"]["name"])
327  {
328  // check if file was uploaded
329  $source = $_FILES["scormfile"]["tmp_name"];
330  if (($source == 'none') || (!$source))
331  {
332  ilUtil::sendInfo($this->lng->txt("upload_error_file_not_found"),true);
333  $this->newModuleVersion();
334  return;
335  }
336  }
337  elseif ($_POST["uploaded_file"])
338  {
339  // check if the file is in the ftp directory and readable
340  if (!ilUploadFiles::_checkUploadFile($_POST["uploaded_file"]))
341  {
342  $this->ilias->raiseError($this->lng->txt("upload_error_file_not_found"),$this->ilias->error_obj->MESSAGE);
343  }
344  // copy the uploaded file to the client web dir to analyze the imsmanifest
345  // the copy will be moved to the lm directory or deleted
346  $source = CLIENT_WEB_DIR . "/" . $_POST["uploaded_file"];
347  ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $source);
348  $source_is_copy = true;
349  }
350  else
351  {
352  ilUtil::sendInfo($this->lng->txt("upload_error_file_not_found"),true);
353  $this->newModuleVersion();
354  return;
355  }
356  // fim.
357 
358  //unzip the imsmanifest-file from new uploaded file
359  $pathinfo = pathinfo($source);
360  $dir = $pathinfo["dirname"];
361  $file = $pathinfo["basename"];
362  $cdir = getcwd();
363  chdir($dir);
364 
365  //we need more flexible unzip here than ILIAS standard classes allow
366  $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($source)." ".$tocheck;
367  exec($unzipcmd);
368  chdir($cdir);
369  $tmp_file = $dir."/".$tocheck.".".$_GET["ref_id"];
370 
371  rename($dir."/".$tocheck,$tmp_file);
372  $new_manifest = file_get_contents($tmp_file);
373 
374  //remove temp file
375  unlink($tmp_file);
376 
377  //get old manifest file
378  $old_manifest = file_get_contents($this->object->getDataDirectory()."/".$tocheck);
379 
380  //reload fixed version of file
381  $check ='/xmlns="http:\/\/www.imsglobal.org\/xsd\/imscp_v1p1"/';
382  $replace="xmlns=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2\"";
383  $reload_manifest = preg_replace($check, $replace, $new_manifest);
384 
385  //do testing for converted versions as well as earlier ILIAS version messed up utf8 conversion
386  if (strcmp($new_manifest,$old_manifest) == 0 || strcmp(utf8_encode($new_manifest),$old_manifest) == 0 ||
387  strcmp ($reload_manifest, $old_manifest) == 0 || strcmp(utf8_encode($reload_manifest),$old_manifest) == 0 ){
388 
389  //get exisiting module version
390  $module_version = $this->object->getModuleVersion();
391 
392  if ($_FILES["scormfile"]["name"])
393  {
394  //build targetdir in lm_data
395  $file_path = $this->object->getDataDirectory()."/".$_FILES["scormfile"]["name"].".".$module_version;
396 
397  //move to data directory and add subfix for versioning
398  ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"],$_FILES["scormfile"]["name"], $file_path);
399  }
400  else
401  {
402  //build targetdir in lm_data
403  $file_path = $this->object->getDataDirectory()."/".$_POST["uploaded_file"].".".$module_version;
404  // move the already copied file to the lm_data directory
405  rename($source, $file_path);
406  }
407 
408  //unzip and replace old extracted files
409  ilUtil::unzip($file_path, true);
410  ilUtil::renameExecutables($this->object->getDataDirectory()); //(security)
411 
412  //increase module version
413  $this->object->setModuleVersion($module_version+1);
414  $this->object->update();
415 
416  //redirect to properties and display success
417  ilUtil::sendInfo( $this->lng->txt("cont_new_module_added"), true);
418  ilUtil::redirect("ilias.php?baseClass=ilSAHSEditGUI&ref_id=".$_GET["ref_id"]);
419  exit;
420  }
421  else
422  {
423  if ($source_is_copy)
424  {
425  unlink($source);
426  }
427 
428  ilUtil::sendInfo($this->lng->txt("cont_invalid_new_module"),true);
429  $this->newModuleVersion();
430  }
431  }
432 
436  function saveProperties()
437  {
438  $this->object->setOnline(ilUtil::yn2tf($_POST["cobj_online"]));
439  $this->object->setOpenMode($_POST["open_mode"]);
440  $this->object->setWidth($_POST["width"]);
441  $this->object->setHeight($_POST["height"]);
442  $this->object->setAutoReview(ilUtil::yn2tf($_POST["auto_review"]));
443  $this->object->setAPIAdapterName($_POST["api_adapter"]);
444  $this->object->setAPIFunctionsPrefix($_POST["api_func_prefix"]);
445  $this->object->setCreditMode($_POST["credit_mode"]);
446  $this->object->setDefaultLessonMode($_POST["lesson_mode"]);
447  $this->object->setMaxAttempt($_POST["max_attempt"]);
448  $this->object->setSession(ilUtil::yn2tf($_POST["cobj_session"]));
449  $this->object->setDebug(ilUtil::yn2tf($_POST["cobj_debug"]));
450  $this->object->setAutoContinue(ilUtil::yn2tf($_POST["auto_continue"]));
451  $this->object->setAuto_last_visited(ilUtil::yn2tf($_POST["cobj_auto_last_visited"]));
452  $this->object->setCheck_values(ilUtil::yn2tf($_POST["cobj_check_values"]));
453  $this->object->update();
454  ilUtil::sendInfo($this->lng->txt("msg_obj_modified"), true);
455  $this->ctrl->redirect($this, "properties");
456  }
457 
461  protected function showTrackingItemsBySco()
462  {
463  global $ilTabs;
464 
465  include_once "./Services/Table/classes/class.ilTableGUI.php";
466 
467  $this->setSubTabs();
468  $ilTabs->setTabActive("cont_tracking_data");
469  $ilTabs->setSubTabActive("cont_tracking_bysco");
470 
471  include_once './Modules/ScormAicc/classes/class.ilSCORMTrackingItemsPerScoTableGUI.php';
472  $tbl = new ilSCORMTrackingItemsPerScoTableGUI($this->object->getId(), $this, 'showTrackingItemsBySco');
473  $tbl->parse();
474  $this->tpl->setContent($tbl->getHTML());
475  return true;
476  }
477 
478 
484  protected function showTrackingItems()
485  {
486  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
487  $privacy = ilPrivacySettings::_getInstance();
488  if(!$privacy->enabledSahsProtocolData())
489  {
490  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
491  }
492 
493  global $ilTabs, $ilToolbar;
494 
495  include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
496  $ilToolbar->addButton(
497  $this->lng->txt('import'),
498  $this->ctrl->getLinkTarget($this, 'importForm')
499  );
500  $ilToolbar->addButton(
501  $this->lng->txt('cont_export_all'),
502  $this->ctrl->getLinkTarget($this, 'exportSelectionAll')
503  );
504 
505  $this->setSubTabs();
506  $ilTabs->setTabActive('cont_tracking_data');
507  $ilTabs->setSubTabActive('cont_tracking_byuser');
508 
509  include_once './Modules/ScormAicc/classes/class.ilSCORMTrackingUsersTableGUI.php';
510  $tbl = new ilSCORMTrackingUsersTableGUI($this->object->getId(), $this, 'showtrackingItems');
511  $tbl->parse();
512  $this->tpl->setContent($tbl->getHTML());
513  }
514 
515 
519  protected function applyUserTableFilter()
520  {
521  include_once './Modules/ScormAicc/classes/class.ilSCORMTrackingUsersTableGUI.php';
522  $tbl = new ilSCORMTrackingUsersTableGUI($this->object->getId(), $this, 'showtrackingItems');
523  $tbl->writeFilterToSession();
524  $tbl->resetOffset();
525  $this->showTrackingItems();
526  }
527 
531  protected function resetUserTableFilter()
532  {
533  include_once './Modules/ScormAicc/classes/class.ilSCORMTrackingUsersTableGUI.php';
534  $tbl = new ilSCORMTrackingUsersTableGUI($this->object->getId(), $this, 'showtrackingItems');
535  $tbl->resetFilter();
536  $tbl->resetOffset();
537  $this->showTrackingItems();
538  }
539 
544  {
545  if(!isset($_POST["user"]))
546  {
547  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
548  }
549 
550  // display confirmation message
551  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
552  $cgui = new ilConfirmationGUI();
553  $cgui->setFormAction($this->ctrl->getFormAction($this));
554  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
555  $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
556  $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
557 
558  foreach($_POST["user"] as $id)
559  {
560  if (ilObject::_exists($id) && ilObject::_lookUpType($id)=="usr" )
561  {
562  $user = new ilObjUser($id);
563 
564  $caption = ilUtil::getImageTagByType("sahs", $this->tpl->tplPath).
565  " ".$this->lng->txt("cont_tracking_data").
566  ": ".$user->getLastname().", ".$user->getFirstname();
567 
568 
569  $cgui->addItem("user[]", $id, $caption);
570  }
571  }
572 
573  $this->tpl->setContent($cgui->getHTML());
574  }
575 
579  function cancelDelete()
580  {
581  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
582  $this->ctrl->redirect($this, "showTrackingItems");
583  }
584 
585  function confirmedDelete()
586  {
587  global $ilDB;
588 
589  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
590 
591  foreach($_POST["user"] as $user)
592  {
593  $ilDB->manipulateF('
594  DELETE FROM scorm_tracking
595  WHERE user_id = %s
596  AND obj_id = %s',
597  array('integer', 'integer'),
598  array($user, $this->object->getID()));
599 
600  ilLPStatusWrapper::_updateStatus($this->object->getId(), $user);
601  }
602 
603  $this->ctrl->redirect($this, "showTrackingItems");
604  }
605 
609  function cancel()
610  {
611  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
612  $this->ctrl->redirect($this, "properties");
613  }
614 
618  protected function import()
619  {
620  $form = $this->initImportForm();
621  if($form->checkInput())
622  {
623  $source = $form->getInput('csv');
624  $error = $this->object->importTrackingData($source['tmp_name']);
625  switch($error)
626  {
627  case 0 :
628  ilUtil::sendInfo('Tracking data imported', true);
629  $this->ctrl->redirect($this, "showTrackingItems");
630  break;
631  case -1 :
632  ilUtil::sendInfo($this->lng->txt('err_check_input'));
633  $this->importForm();
634  break;
635  }
636  }
637  ilUtil::sendInfo($this->lng->txt('err_check_input'));
638  $form->setValuesByPost();
639  $this->importForm();
640  }
641 
645  protected function importForm()
646  {
647  global $ilTabs;
648 
649  $ilTabs->clearTargets();
650  $ilTabs->setBackTarget($this->lng->txt('back'),$this->ctrl->getLinkTarget($this,'showTrackingItems'));
651 
652  $form = $this->initImportForm();
653  $this->tpl->setContent($form->getHTML());
654  }
655 
659  protected function initImportForm()
660  {
661  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
662  $form = new ilPropertyFormGUI();
663  $form->setFormAction($this->ctrl->getFormAction($this));
664  $form->setTitle($this->lng->txt('cont_import_tracking'));
665  $form->addCommandButton('import', $this->lng->txt('import'));
666  $form->addCommandButton('showTrackingItems', $this->lng->txt('cancel'));
667 
668  $csv = new ilFileInputGUI($this->lng->txt('select_file'),'csv');
669  $csv->setRequired(true);
670  $csv->setSuffixes(array('csv'));
671  $form->addItem($csv);
672 
673  return $form;
674  }
675 
679  protected function exportSelectionAll()
680  {
681  $this->exportSelection(self::EXPORT_ALL);
682  }
683 
687  protected function exportSelectionUsers()
688  {
689  if(!count((array) $_POST['user']))
690  {
691  ilUtil::sendFailure($this->lng->txt('select_one'),true);
692  $this->ctrl->redirect($this,'showTrackingItems');
693  }
694 
695  $this->exportSelection(self::EXPORT_SELECTED);
696  }
697 
702  protected function exportSelection($a_type)
703  {
704  global $ilTabs;
705 
706  $ilTabs->clearTargets();
707  $ilTabs->setBackTarget(
708  $this->lng->txt('back'),
709  $this->ctrl->getLinkTarget($this,'showTrackingItems')
710  );
711 
712  $form = $this->initExportForm($a_type);
713  $this->tpl->setContent($form->getHTML());
714  }
715 
720  protected function initExportForm($a_type)
721  {
722  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
723 
724  $form = new ilPropertyFormGUI();
725  $form->setFormAction($this->ctrl->getFormAction($this,'showTrackingItems'));
726  $form->setTitle($this->lng->txt('cont_export_tracking'));
727  $form->addCommandButton('export', $this->lng->txt('export'));
728  $form->addCommandButton('showTrackingItems', $this->lng->txt('cancel'));
729 
730  $type = new ilRadioGroupInputGUI($this->lng->txt('cont_export_type'), 'type');
731  $type->setRequired(true);
732  $type->setValue(self::EXPORT_TYPE_RAW);
733  $form->addItem($type);
734 
735  $raw = new ilRadioOption($this->lng->txt('cont_export_raw'), self::EXPORT_TYPE_RAW);
736  $type->addOption($raw);
737 
738  $suc = new ilRadioOption($this->lng->txt('cont_export_success'), self::EXPORT_TYPE_SUCCESS);
739  $type->addOption($suc);
740 
741  $etype = new ilHiddenInputGUI('etype');
742  $etype->setValue($a_type);
743  $form->addItem($etype);
744 
745  switch($a_type)
746  {
747  case self::EXPORT_SELECTED:
748  $users = new ilHiddenInputGUI('users');
749  $users->setValue(htmlentities(serialize($_POST['user'])));
750  $form->addItem($users);
751  break;
752  }
753  return $form;
754  }
755 
756 
760  protected function export()
761  {
762  $form = $this->initExportForm(self::EXPORT_UNDEF);
763  if($form->checkInput())
764  {
765  if($form->getInput('type') == self::EXPORT_TYPE_RAW)
766  {
767  if($form->getInput('etype') == self::EXPORT_ALL)
768  {
769  return $this->object->exportSelectedRaw(true);
770  }
771  else
772  {
773  $users = (array) unserialize(html_entity_decode($form->getInput('users')));
774  return $this->object->exportSelectedRaw(false,$users);
775  }
776  }
777  else
778  {
779  if($form->getInput('etype') == self::EXPORT_ALL)
780  {
781  return $this->object->exportSelected(true);
782  }
783  else
784  {
785  $users = (array) unserialize(html_entity_decode($form->getInput('users')));
786  return $this->object->exportSelected(false,$users);
787  }
788  }
789  }
790  ilUtil::sendFailure($this->lng->txt('err_check_input'));
791  $this->ctrl->redirect($this,'showTrackingItems');
792  }
793 
794  function decreaseAttempts()
795  {
796  global $ilDB, $ilUser;
797 
798  if (!isset($_POST["user"]))
799  {
800  ilUtil::sendInfo($this->lng->txt("no_checkbox"),true);
801  }
802 
803  foreach ($_POST["user"] as $user)
804  {
805  //first check if there is a package_attempts entry
806  //get existing account - sco id is always 0
807  $val_set = $ilDB->queryF('
808  SELECT * FROM scorm_tracking
809  WHERE user_id = %s
810  AND sco_id = %s
811  AND lvalue = %s
812  AND obj_id = %s',
813  array('integer','integer','text','integer'),
814  array($user,0,'package_attempts',$this->object->getID()));
815 
816  $val_rec = $ilDB->fetchAssoc($val_set);
817 
818  $val_rec["rvalue"] = str_replace("\r\n", "\n", $val_rec["rvalue"]);
819  if ($val_rec["rvalue"] != null && $val_rec["rvalue"] != 0)
820  {
821  $new_rec = $val_rec["rvalue"]-1;
822  //decrease attempt by 1
823  if($res = $ilDB->numRows($val_set) > 0)
824  {
825  $ilDB->update('scorm_tracking',
826  array(
827  'rvalue' => array('clob', $new_rec)
828  ),
829  array(
830  'user_id' => array('integer', $user),
831  'sco_id' => array('integer', 0),
832  'obj_id' => array('integer', $this->object->getId()),
833  'lvalue' => array('text', 'package_attempts')
834  )
835  );
836  }
837  else
838  {
839  $ilDB->insert('scorm_tracking', array(
840  'rvalue' => array('clob', $new_rec),
841  'user_id' => array('integer', $user),
842  'sco_id' => array('integer', 0),
843  'obj_id' => array('integer', $this->object->getId()),
844  'lvalue' => array('text', 'package_attempts')
845  ));
846  }
847 
848  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
849  ilLPStatusWrapper::_updateStatus($this->object->getId(), $user);
850  }
851  }
852 
853  //$this->ctrl->saveParameter($this, "cdir");
854  $this->ctrl->redirect($this, "showTrackingItems");
855  }
856 
857 
861  protected function showTrackingItem()
862  {
863  global $ilTabs;
864 
865  include_once "./Services/Table/classes/class.ilTableGUI.php";
866 
867  $this->setSubTabs();
868  $ilTabs->setTabActive("cont_tracking_data");
869  $ilTabs->setSubTabActive("cont_tracking_byuser");
870 
871  include_once './Modules/ScormAicc/classes/class.ilSCORMTrackingItemsPerUserTableGUI.php';
872  $tbl = new ilSCORMTrackingItemsPerUserTableGUI($this->object->getId(), $this, 'showTrackingItem');
873  $tbl->setUserId((int) $_REQUEST['user_id']);
874  $tbl->parse();
875  $this->tpl->setContent($tbl->getHTML());
876  return true;
877  }
878 
882  protected function showTrackingItemSco()
883  {
884  global $ilTabs;
885 
886  include_once "./Services/Table/classes/class.ilTableGUI.php";
887 
888  $this->setSubTabs();
889  $ilTabs->setTabActive("cont_tracking_data");
890  $ilTabs->setSubTabActive("cont_tracking_bysco");
891 
892  include_once './Modules/ScormAicc/classes/class.ilSCORMTrackingItemsScoTableGUI.php';
893  $tbl = new ilSCORMTrackingItemsScoTableGUI($this->object->getId(), $this, 'showTrackingItemSco');
894  $tbl->setScoId((int) $_GET['obj_id']);
895  $tbl->parse();
896  $this->tpl->setContent($tbl->getHTML());
897  return true;
898  }
899 
903  protected function showTrackingItemPerUser()
904  {
905  global $ilTabs;
906 
907  include_once "./Services/Table/classes/class.ilTableGUI.php";
908 
909  $this->setSubTabs();
910  $ilTabs->setTabActive("cont_tracking_data");
911  $ilTabs->setSubTabActive("cont_tracking_byuser");
912 
913  $this->ctrl->setParameter($this,'obj_id',(int) $_REQUEST['obj_id']);
914  $this->ctrl->setParameter($this,'user_id',(int) $_REQUEST['user_id']);
915 
916  include_once './Modules/ScormAicc/classes/class.ilSCORMTrackingItemPerUserTableGUI.php';
917  $tbl = new ilSCORMTrackingItemPerUserTableGUI($this->object->getId(), $this, 'showTrackingItemPerUser');
918  $tbl->setUserId((int) $_REQUEST['user_id']);
919  $tbl->setScoId((int) $_REQUEST['obj_id']);
920  $tbl->parse();
921  $this->tpl->setContent($tbl->getHTML());
922  return true;
923  }
924 
925  //setTabs
926  function setSubTabs()
927  {
928  global $lng, $ilTabs, $ilCtrl;
929 
930  $ilTabs->addSubTabTarget("cont_tracking_byuser",
931  $this->ctrl->getLinkTarget($this, "showTrackingItems"), array("edit", ""),
932  get_class($this));
933 
934  $ilTabs->addSubTabTarget("cont_tracking_bysco",
935  $this->ctrl->getLinkTarget($this, "showTrackingItemsBySco"), array("edit", ""),
936  get_class($this));
937  }
938 
939 }
940 // END class.ilObjSCORMLearningModule
941 ?>