protected function generateThumbForFile($path, $file)
 {
     $filename = $path . $file;
     if (@file_exists($filename)) {
         $thumbpath = $path . $this->getThumbPrefix() . $file;
         $path_info = @pathinfo($filename);
         $ext = "";
         switch (strtoupper($path_info['extension'])) {
             case 'PNG':
                 $ext = 'PNG';
                 break;
             case 'GIF':
                 $ext = 'GIF';
                 break;
             default:
                 $ext = 'JPEG';
                 break;
         }
         ilUtil::convertImage($filename, $thumbpath, $ext, $this->getThumbSize());
     }
 }
 /**
  * Upload video preview picture
  *
  * @param
  * @return
  */
 function generatePreviewPic($a_width, $a_height)
 {
     $item = $this->getMediaItem("Standard");
     if ($item->getLocationType() == "LocalFile" && is_int(strpos($item->getFormat(), "image/"))) {
         $dir = ilObjMediaObject::_getDirectory($this->getId());
         $file = $dir . "/" . $item->getLocation();
         if (is_file($file)) {
             if (ilUtil::isConvertVersionAtLeast("6.3.8-3")) {
                 ilUtil::execConvert($file . "[0] -geometry " . $a_width . "x" . $a_height . "^ -gravity center -extent " . $a_width . "x" . $a_height . " PNG:" . $dir . "/mob_vpreview.png");
             } else {
                 ilUtil::convertImage($file, $dir . "/mob_vpreview.png", "PNG", $a_width . "x" . $a_height);
             }
         }
     }
 }
Example #3
0
 /**
  * Copy the orginal file
  */
 function copyOriginal()
 {
     global $lng;
     $this->createWorkDirectory();
     if ($this->getLocationType() != "Reference") {
         ilUtil::convertImage($this->getDirectory() . "/" . $this->getLocation(), $this->getMapWorkCopyName(), $this->getMapWorkCopyType());
     } else {
         // first copy the external file, if necessary
         if (!is_file($this->getMapWorkCopyName(true)) || filesize($this->getMapWorkCopyName(true)) == 0) {
             $handle = @fopen($this->getLocation(), "r");
             $lcopy = fopen($this->getMapWorkCopyName(true), "w");
             if ($handle && $lcopy) {
                 while (!feof($handle)) {
                     $content = fread($handle, 4096);
                     fwrite($lcopy, $content);
                 }
             }
             @fclose($lcopy);
             @fclose($handle);
         }
         // now, create working copy
         ilUtil::convertImage($this->getMapWorkCopyName(true), $this->getMapWorkCopyName(), $this->getMapWorkCopyType());
     }
     if (!is_file($this->getMapWorkCopyName())) {
         ilUtil::sendFailure($lng->txt("cont_map_file_not_generated"));
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * Reads an import ZIP file and creates a certificate of it
  *
  * @return boolean TRUE if the import succeeds, FALSE otherwise
  */
 public function importCertificate($zipfile, $filename)
 {
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     $importpath = $this->createArchiveDirectory();
     if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename)) {
         ilUtil::delDir($importpath);
         return FALSE;
     }
     ilUtil::unzip($importpath . $filename, TRUE);
     $subdir = str_replace(".zip", "", strtolower($filename)) . "/";
     $copydir = "";
     if (is_dir($importpath . $subdir)) {
         $dirinfo = ilUtil::getDir($importpath . $subdir);
         $copydir = $importpath . $subdir;
     } else {
         $dirinfo = ilUtil::getDir($importpath);
         $copydir = $importpath;
     }
     $xmlfiles = 0;
     $otherfiles = 0;
     foreach ($dirinfo as $file) {
         if (strcmp($file["type"], "file") == 0) {
             if (strpos($file["entry"], ".xml") !== FALSE) {
                 $xmlfiles++;
             } else {
                 if (strpos($file["entry"], ".zip") !== FALSE) {
                 } else {
                     $otherfiles++;
                 }
             }
         }
     }
     // if one XML file is in the archive, we try to import it
     if ($xmlfiles == 1) {
         foreach ($dirinfo as $file) {
             if (strcmp($file["type"], "file") == 0) {
                 if (strpos($file["entry"], ".xml") !== FALSE) {
                     $xsl = file_get_contents($copydir . $file["entry"]);
                     // as long as we cannot make RPC calls in a given directory, we have
                     // to add the complete path to every url
                     $xsl = preg_replace("/url\\([']{0,1}(.*?)[']{0,1}\\)/", "url(" . $this->getAdapter()->getCertificatePath() . "\${1})", $xsl);
                     $this->saveCertificate($xsl);
                 } else {
                     if (strpos($file["entry"], ".zip") !== FALSE) {
                     } else {
                         @copy($copydir . $file["entry"], $this->getAdapter()->getCertificatePath() . $file["entry"]);
                         if (strcmp($this->getBackgroundImagePath(), $this->getAdapter()->getCertificatePath() . $file["entry"]) == 0) {
                             // upload of the background image, create a preview
                             ilUtil::convertImage($this->getBackgroundImagePath(), $this->getBackgroundImageThumbPath(), "JPEG", 100);
                         }
                     }
                 }
             }
         }
     } else {
         ilUtil::delDir($importpath);
         return FALSE;
     }
     ilUtil::delDir($importpath);
     return TRUE;
 }
 /**
  * Uploads a background image for the certificate. Creates a new directory for the
  * certificate if needed. Removes an existing certificate image if necessary
  *
  * @param string $image_tempfilename Name of the temporary uploaded image file
  * @return integer An errorcode if the image upload fails, 0 otherwise
  */
 public function uploadBackgroundImage($image_tempfilename)
 {
     if (!empty($image_tempfilename)) {
         $image_filename = "background_upload";
         $convert_filename = $this->getBackgroundImageName();
         $imagepath = $this->getBackgroundImageDefaultFolder();
         if (!file_exists($imagepath)) {
             ilUtil::makeDirParents($imagepath);
         }
         // upload the file
         if (!ilUtil::moveUploadedFile($image_tempfilename, $image_filename, $this->getBackgroundImageTempfilePath())) {
             return FALSE;
         }
         // convert the uploaded file to JPEG
         ilUtil::convertImage($this->getBackgroundImageTempfilePath(), $this->getBackgroundImagePath(), "JPEG");
         ilUtil::convertImage($this->getBackgroundImageTempfilePath(), $this->getBackgroundImageThumbPath(), "JPEG", 100);
         if (!file_exists($this->getBackgroundImagePath())) {
             // something went wrong converting the file. use the original file and hope, that PDF can work with it
             if (!ilUtil::moveUploadedFile($this->getBackgroundImageTempfilePath(), $convert_filename, $this->getBackgroundImagePath())) {
                 return FALSE;
             }
         }
         unlink($this->getBackgroundImageTempfilePath());
         if (file_exists($this->getBackgroundImagePath()) && filesize($this->getBackgroundImagePath()) > 0) {
             return TRUE;
         }
     }
     return FALSE;
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $shuffle = 0;
     $now = getdate();
     $foundimage = FALSE;
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $answers = array();
     $type = OQ_TERMS;
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $type = $response->getIdent();
                 if ($response->getIdent() == 'OQP') {
                     $type = OQ_PICTURES;
                 } else {
                     if ($response->getIdent() == 'OQNP') {
                         $type = OQ_NESTED_PICTURES;
                     } else {
                         if ($response->getIdent() == 'OQNT') {
                             $type = OQ_NESTED_TERMS;
                         } else {
                             if ($response->getIdent() == 'OQT') {
                                 $type = OQ_TERMS;
                             }
                         }
                     }
                 }
                 $rendertype = $response->getRenderType();
                 switch (strtolower(get_class($rendertype))) {
                     case "ilqtirenderchoice":
                         $shuffle = $rendertype->getShuffle();
                         $answerorder = 0;
                         foreach ($rendertype->response_labels as $response_label) {
                             $ident = $response_label->getIdent();
                             $answertext = "";
                             foreach ($response_label->material as $mat) {
                                 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
                                     $foundmat = $mat->getMaterial($m);
                                     if (strcmp($foundmat["material"]->getLabel(), "answerdepth") == 0) {
                                         $answerdepth = $foundmat["material"]->getContent();
                                     }
                                     if (strcmp($foundmat["type"], "mattext") == 0 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
                                         $answertext .= $foundmat["material"]->getContent();
                                     }
                                     if (strcmp($foundmat["type"], "matimage") == 0 && strcmp($foundmat["material"]->getLabel(), "answerdepth") != 0) {
                                         $foundimage = TRUE;
                                         $answerimage = array("imagetype" => $foundmat["material"]->getImageType(), "label" => $foundmat["material"]->getLabel(), "content" => $foundmat["material"]->getContent());
                                     }
                                 }
                             }
                             $answers[$ident] = array("answertext" => $answertext, "answerimage" => $answerimage, "points" => 0, "answerorder" => $answerorder++, "answerdepth" => $answerdepth, "correctness" => "", "action" => "");
                         }
                         break;
                 }
                 break;
         }
     }
     $responses = array();
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->respcondition as $respcondition) {
             $ident = "";
             $correctness = 1;
             $conditionvar = $respcondition->getConditionvar();
             foreach ($conditionvar->order as $order) {
                 switch ($order["field"]) {
                     case "arr_not":
                         $correctness = 0;
                         break;
                     case "varequal":
                         $ident = $conditionvar->varequal[$order["index"]]->getContent();
                         $orderindex = $conditionvar->varequal[$order["index"]]->getIndex();
                         break;
                 }
             }
             foreach ($respcondition->setvar as $setvar) {
                 if (strcmp($ident, "") != 0) {
                     $answers[$ident]["solutionorder"] = $orderindex;
                     $answers[$ident]["action"] = $setvar->getAction();
                     $answers[$ident]["points"] = $setvar->getContent();
                 }
             }
             if (count($respcondition->displayfeedback)) {
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[1] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[1] = $material;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacksgeneric[0] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacksgeneric[0] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setOrderingType($type);
     $this->object->setObjId($questionpool_id);
     $this->object->setThumbGeometry($item->getMetadataEntry("thumb_geometry"));
     $this->object->setElementHeight($item->getMetadataEntry("element_height"));
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setShuffle($shuffle);
     $points = 0;
     $solanswers = array();
     foreach ($answers as $answer) {
         $solanswers[$answer["solutionorder"]] = $answer;
     }
     ksort($solanswers);
     foreach ($solanswers as $answer) {
         $points += $answer["points"];
         if ($type == OQ_TERMS || $type == OQ_NESTED_TERMS) {
             $this->object->addAnswer($answer["answertext"], -1, $answer['answerdepth']);
         } else {
             if ($type == OQ_PICTURES || $type == OQ_NESTED_PICTURES) {
                 $this->object->addAnswer($answer["answerimage"]["label"], -1, $answer['answerdepth']);
             }
         }
     }
     $points = $item->getMetadataEntry("points") > 0 ? $item->getMetadataEntry("points") : $points;
     $this->object->setPoints($points);
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     foreach ($answers as $answer) {
         if ($type == OQ_PICTURES || $type == OQ_NESTED_PICTURES) {
             include_once "./Services/Utilities/classes/class.ilUtil.php";
             $image =& base64_decode($answer["answerimage"]["content"]);
             $imagepath = $this->object->getImagePath();
             if (!file_exists($imagepath)) {
                 ilUtil::makeDirParents($imagepath);
             }
             $imagepath .= $answer["answerimage"]["label"];
             $fh = fopen($imagepath, "wb");
             if ($fh == false) {
                 //									global $ilErr;
                 //									$ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
                 //									return;
             } else {
                 $imagefile = fwrite($fh, $image);
                 fclose($fh);
             }
             // create thumbnail file
             $thumbpath = $imagepath . "." . "thumb.jpg";
             ilUtil::convertImage($imagepath, $thumbpath, "JPEG", $this->object->getThumbGeometry());
         }
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     $questiontext = $this->object->getQuestion();
     $answers =& $this->object->getAnswers();
     // handle the import of media objects in XHTML code
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($answers as $key => $value) {
                 $answer_obj =& $answers[$key];
                 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
             }
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($answers as $key => $value) {
         $answer_obj =& $answers[$key];
         $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1));
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }