/**
  * Function to parse incoming data from form input value $value. returns the strin/number/etc. to store in the database.
  * @param $value
  * @param ilDataCollectionRecordField $record_field
  * @return int|string
  */
 public function parseValue($value, ilDataCollectionRecordField $record_field)
 {
     $return = false;
     if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_FILE) {
         $file = $value;
         if ($file['tmp_name']) {
             $file_obj = new ilObjFile();
             $file_obj->setType("file");
             $file_obj->setTitle($file["name"]);
             $file_obj->setFileName($file["name"]);
             $file_obj->setFileType(ilMimeTypeUtil::getMimeType("", $file["name"], $file["type"]));
             $file_obj->setFileSize($file["size"]);
             $file_obj->setMode("object");
             $file_obj->create();
             $file_obj->getUploadFile($file["tmp_name"], $file["name"]);
             $file_id = $file_obj->getId();
             $return = $file_id;
         } else {
             $return = $record_field->getValue();
         }
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_MOB) {
         if ($value == -1) {
             //marked for deletion.
             return 0;
         }
         $media = $value;
         if ($media['tmp_name']) {
             $mob = new ilObjMediaObject();
             $mob->setTitle($media['name']);
             $mob->create();
             $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
             if (!is_dir($mob_dir)) {
                 $mob->createDirectory();
             }
             $media_item = new ilMediaItem();
             $mob->addMediaItem($media_item);
             $media_item->setPurpose("Standard");
             $file_name = ilUtil::getASCIIFilename($media['name']);
             $file_name = str_replace(" ", "_", $file_name);
             $file = $mob_dir . "/" . $file_name;
             $title = $file_name;
             ilUtil::moveUploadedFile($media['tmp_name'], $file_name, $file);
             ilUtil::renameExecutables($mob_dir);
             list($width, $height, $type, $attr) = getimagesize($file);
             $arr_properties = $record_field->getField()->getProperties();
             $new_width = $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH];
             $new_height = $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT];
             if ($new_width || $new_height) {
                 //only resize if it is bigger, not if it is smaller
                 if ($new_height < $height && $new_width < $width) {
                     //resize proportional
                     if (!$new_height || !$new_width) {
                         $format = ilObjMediaObject::getMimeType($file);
                         $wh = ilObjMediaObject::_determineWidthHeight("", "", $format, "File", $file, "", true, false, $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH], (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]);
                     } else {
                         $wh['width'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH];
                         $wh['height'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT];
                     }
                 }
                 $location = ilObjMediaObject::_resizeImage($file, $wh['width'], $wh['height'], false);
             } else {
                 $location = $title;
             }
             ilObjMediaObject::_saveUsage($mob->getId(), "dcl:html", $record_field->getRecord()->getTable()->getCollectionObject()->getId());
             $format = ilObjMediaObject::getMimeType($file);
             $media_item->setFormat($format);
             $media_item->setLocation($location);
             $media_item->setLocationType("LocalFile");
             $mob->update();
             $return = $mob->getId();
         } else {
             $return = $record_field->getValue();
         }
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) {
         return $value["date"] . " " . $value["time"];
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) {
         $return = $value ? 1 : 0;
     } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_TEXT) {
         $arr_properties = $record_field->getField()->getProperties();
         if ($arr_properties[ilDataCollectionField::PROPERTYID_TEXTAREA]) {
             $return = nl2br($value);
         } else {
             $return = $value;
         }
     } else {
         if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) {
             $return = $value == '' ? null : $value;
             //SW, Ilias Mantis #0011799: Return null otherwise '' is casted to 0 in DB
         } else {
             $return = $value;
         }
     }
     return $return;
 }
 /**
  * save properties in db and return to page edit screen
  */
 function savePropertiesObject()
 {
     global $lng, $tpl;
     $this->initForm("edit");
     if ($this->form_gui->checkInput()) {
         $title = trim($_POST["standard_title"]);
         $this->object->setTitle($title);
         $std_item = $this->object->getMediaItem("Standard");
         $location = $std_item->getLocation();
         $format = $std_item->getFormat();
         if ($_POST["standard_type"] == "Reference") {
             $format = ilObjMediaObject::getMimeType(ilUtil::stripSlashes($_POST["standard_reference"]));
             $std_item->setFormat($format);
             $std_item->setLocation(ilUtil::secureLink(ilUtil::stripSlashes($_POST["standard_reference"])));
             $std_item->setLocationType("Reference");
         }
         $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
         if ($_POST["standard_type"] == "File") {
             $resize = false;
             if ($_FILES['standard_file']['name'] != "") {
                 $file_name = ilObjMediaObject::fixFilename($_FILES['standard_file']['name']);
                 $file = $mob_dir . "/" . $file_name;
                 ilUtil::moveUploadedFile($_FILES['standard_file']['tmp_name'], $file_name, $file);
                 // get mime type
                 $format = ilObjMediaObject::getMimeType($file);
                 $location = $file_name;
                 $resize = true;
             } else {
                 if ($_POST["standard_resize"]) {
                     $file = $mob_dir . "/" . $location;
                     $resize = true;
                 }
             }
             // resize
             if ($resize) {
                 if ($_POST["standard_size"] != "original" && is_int(strpos($format, "image"))) {
                     $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["standard_width_height"]["width"], (int) $_POST["standard_width_height"]["height"], (bool) $_POST["standard_width_height"]["contr_prop"]);
                 }
                 $std_item->setFormat($format);
                 $std_item->setLocation($location);
             }
             $std_item->setLocationType("LocalFile");
         }
         $this->object->setDescription($format);
         // determine width and height of known image types
         $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format, $_POST["standard_type"], $mob_dir . "/" . $location, $std_item->getLocation(), $_POST["standard_width_height"]["constr_prop"], $_POST["standard_size"] == "original", $_POST["standard_width_height"]["width"], $_POST["standard_width_height"]["height"]);
         if ($wh["info"] != "") {
             ilUtil::sendInfo($wh["info"], true);
         }
         $std_item->setWidth($wh["width"]);
         $std_item->setHeight($wh["height"]);
         // set caption
         $std_item->setCaption(ilUtil::stripSlashes($_POST["standard_caption"]));
         // text representation
         $std_item->setTextRepresentation(ilUtil::stripSlashes($_POST["text_representation"]));
         // set parameters
         if (!in_array($std_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes())) {
             if (ilObjMediaObject::_useAutoStartParameterOnly($std_item->getLocation(), $std_item->getFormat())) {
                 if ($_POST["standard_autostart"]) {
                     $std_item->setParameters('autostart="true"');
                 } else {
                     $std_item->setParameters("");
                 }
             } else {
                 $std_item->setParameters(ilUtil::stripSlashes(utf8_decode($_POST["standard_parameters"])));
             }
         }
         // "None" selected
         if ($_POST["full_type"] == "None") {
             if ($this->object->hasFullscreenItem()) {
                 $this->object->removeMediaItem("Fullscreen");
             }
         } else {
             if ($this->object->hasFullscreenItem()) {
                 $full_item = $this->object->getMediaItem("Fullscreen");
             } else {
                 $full_item = new ilMediaItem();
                 $this->object->addMediaItem($full_item);
                 $full_item->setPurpose("Fullscreen");
             }
             $location = $full_item->getLocation();
             $format = $full_item->getFormat();
             if ($_POST["full_type"] == "Reference") {
                 $format = ilObjMediaObject::getMimeType(ilUtil::stripSlashes($_POST["full_reference"]));
                 $full_item->setFormat($format);
                 $full_item->setLocationType("Reference");
                 $location = ilUtil::stripSlashes($_POST["full_reference"]);
                 $type = "Reference";
             }
             $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
             if ($_POST["full_type"] == "File") {
                 $resize = false;
                 if ($_FILES['full_file']['name'] != "") {
                     $full_file_name = ilObjMediaObject::fixFilename($_FILES['full_file']['name']);
                     $file = $mob_dir . "/" . $full_file_name;
                     ilUtil::moveUploadedFile($_FILES['full_file']['tmp_name'], $full_file_name, $file);
                     $format = ilObjMediaObject::getMimeType($file);
                     $location = $full_file_name;
                     $resize = true;
                 } else {
                     if ($_POST["full_resize"]) {
                         $file = $mob_dir . "/" . $location;
                         $resize = true;
                     }
                 }
                 // resize
                 if ($resize) {
                     if ($_POST["full_size"] != "original" && is_int(strpos($format, "image"))) {
                         $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["full_width_height"]["width"], (int) $_POST["full_width_height"]["height"], (bool) $_POST["full_width_height"]["contr_prop"]);
                     }
                     $full_item->setFormat($format);
                     $full_item->setLocation($location);
                 }
                 $full_item->setLocationType("LocalFile");
                 $type = "File";
             }
             if ($_POST["full_type"] == "Standard") {
                 $format = $std_item->getFormat();
                 $location = $std_item->getLocation();
                 $full_item->setLocationType($std_item->getLocationType());
                 $full_item->setFormat($format);
                 $full_item->setLocation($location);
                 $type = $std_item->getLocationType();
                 if ($type == "LocalFile") {
                     $type = "File";
                 }
                 // resize image
                 //echo "-".$_POST["full_size"]."-".is_int(strpos($format, "image"))."-".$full_item->getLocationType()."-";
                 if ($_POST["full_size"] != "original" && is_int(strpos($format, "image")) && $full_item->getLocationType() == "LocalFile") {
                     $file = $mob_dir . "/" . $location;
                     $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["full_width_height"]["width"], (int) $_POST["full_width_height"]["height"], (bool) $_POST["full_width_height"]["contr_prop"]);
                 }
             }
             // determine width and height of known image types
             $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format, $type, $mob_dir . "/" . $location, $full_item->getLocation(), $_POST["full_width_height"]["constr_prop"], $_POST["full_size"] == "original", $_POST["full_width_height"]["width"], $_POST["full_width_height"]["height"]);
             if ($wh["info"] != "") {
                 ilUtil::sendInfo($wh["info"], true);
             }
             $full_item->setWidth($wh["width"]);
             $full_item->setHeight($wh["height"]);
             $full_item->setLocation($location);
             $full_item->setCaption(ilUtil::stripSlashes($_POST["full_caption"]));
             // text representation
             $full_item->setTextRepresentation(ilUtil::stripSlashes($_POST["full_text_representation"]));
             // set parameters
             if (!in_array($std_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes())) {
                 if (ilObjMediaObject::_useAutoStartParameterOnly($std_item->getLocation(), $std_item->getFormat())) {
                     if ($_POST["full_autostart"]) {
                         $full_item->setParameters('autostart="true"');
                     } else {
                         $full_item->setParameters("");
                     }
                 } else {
                     $full_item->setParameters(ilUtil::stripSlashes(utf8_decode($_POST["full_parameters"])));
                 }
             }
         }
         ilUtil::renameExecutables(ilObjMediaObject::_getDirectory($this->object->getId()));
         $this->object->update();
         ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
         $this->ctrl->redirect($this, "edit");
     } else {
         $this->form_gui->setValuesByPost();
         $tpl->setContent($this->form_gui->getHTML());
     }
 }