/**
  * Renders the specified object into images.
  * The images do not need to be of the preview image size.
  * 
  * @param ilObjFile $obj The object to create images from.
  * @return array An array of ilRenderedImage containing the absolute file paths to the images.
  */
 protected function renderImages($obj)
 {
     $numOfPreviews = $this->getMaximumNumberOfPreviews();
     // get file path
     $filepath = $obj->getFile();
     $inputFile = $this->prepareFileForExec($filepath);
     // create a temporary file name and remove its extension
     $output = str_replace(".tmp", "", ilUtil::ilTempnam());
     // use '#' instead of '%' as it gets replaced by 'escapeShellArg' on windows!
     $outputFile = $output . "_#02d.png";
     // create images with ghostscript (we use PNG here as it has better transparency quality)
     // gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=pngalpha -dEPSCrop -r72 -o $outputFile $inputFile
     // gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=jpeg -dJPEGQ=90 -r72 -o $outputFile $inputFile
     $args = sprintf("-dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=%d -sDEVICE=pngalpha -dEPSCrop -r72 -o %s %s", $numOfPreviews, str_replace("#", "%", ilUtil::escapeShellArg($outputFile)), ilUtil::escapeShellArg($inputFile));
     ilUtil::execQuoted(PATH_TO_GHOSTSCRIPT, $args);
     // was a temporary file created? then delete it
     if ($filepath != $inputFile) {
         @unlink($inputFile);
     }
     // check each file and add it
     $images = array();
     $outputFile = str_replace("#", "%", $outputFile);
     for ($i = 1; $i <= $numOfPreviews; $i++) {
         $imagePath = sprintf($outputFile, $i);
         if (!file_exists($imagePath)) {
             break;
         }
         $images[] = new ilRenderedImage($imagePath);
     }
     return $images;
 }
Exemplo n.º 2
0
 public function storeFileForRest($content)
 {
     $tmpname = ilUtil::ilTempnam();
     $path = $this->getPath() . '/' . basename($tmpname);
     $this->writeToFile($content, $path);
     return basename($tmpname);
 }
Exemplo n.º 3
0
 /**
  * Get xml record
  *
  * @param
  * @return
  */
 function getXmlRecord($a_entity, $a_version, $a_set)
 {
     global $ilLog;
     if ($a_entity == "usr_profile") {
         $tmp_dir = ilUtil::ilTempnam();
         ilUtil::makeDir($tmp_dir);
         include_once "./Services/User/classes/class.ilObjUser.php";
         ilObjUser::copyProfilePicturesToDirectory($a_set["Id"], $tmp_dir);
         $this->temp_picture_dirs[$a_set["Id"]] = $tmp_dir;
         $a_set["Picture"] = $tmp_dir;
     }
     return $a_set;
 }
 /**
  * Checks whether the specified file path can be used with exec() commands.
  * If the file name is not conform with exec() commands, a temporary file is
  * created and the path to that file is returned.  
  * 
  * @param string $filepath The path of the file to check.
  * @return string The specified file path if conform with exec(); otherwise, the path to a temporary copy of the file.
  */
 public function prepareFileForExec($filepath)
 {
     $pos = strrpos($filepath, "/");
     $name = $pos !== false ? substr($filepath, $pos + 1) : $filepath;
     // if the file path contains any characters that could cause problems
     // we copy the file to a temporary file
     $normName = preg_replace("/[^A-Za-z0-9.\\- +_&]/", "", $name);
     if ($normName != $name) {
         $tempPath = ilUtil::ilTempnam();
         if (copy($filepath, $tempPath)) {
             return $tempPath;
         }
     }
     return $filepath;
 }
Exemplo n.º 5
0
 /**
  * ilImagemapPreview constructor
  *
  * Creates an instance of the ilImagemapPreview class
  *
  * @param integer $id The database id of a image map question object
  * @access public
  */
 function ilImagemapPreview($imagemap_filename = "")
 {
     global $lng;
     $this->lng =& $lng;
     $this->imagemap_filename = $imagemap_filename;
     $this->preview_filename = $preview_filename;
     if (!@is_file($this->preview_filename)) {
         $extension = ".jpg";
         if (preg_match("/.*\\.(png|jpg|gif|jpeg)\$/", $this->imagemap_filename, $matches)) {
             $extension = "." . $matches[1];
         }
         include_once "./Services/Utilities/classes/class.ilUtil.php";
         $this->preview_filename = ilUtil::ilTempnam() . $extension;
     }
     $this->areas = array();
     $this->points = array();
     $this->linewidth_outer = 4;
     $this->linewidth_inner = 2;
 }
 /**
  * Saves binary image data to a temporary image file and returns
  * the name of the image file on success.
  */
 function saveTempImage($image_data, $filename)
 {
     $tempname = ilUtil::ilTempnam() . $filename;
     $fh = fopen($tempname, "wb");
     if ($fh == false) {
         return "";
     }
     $imagefile = fwrite($fh, $image_data);
     fclose($fh);
     return $tempname;
 }
 /**
  * saveUnzip object
  *
  * @access	public
  */
 function saveUnzip()
 {
     $zip_form_gui = $this->initZipUploadForm();
     if ($this->checkPermissionBool("create", "", "file")) {
         if ($zip_form_gui->checkInput()) {
             $zip_file = $zip_form_gui->getInput("zip_file");
             $adopt_structure = $zip_form_gui->getInput("adopt_structure");
             include_once "Services/Utilities/classes/class.ilFileUtils.php";
             // Create unzip-directory
             $newDir = ilUtil::ilTempnam();
             ilUtil::makeDir($newDir);
             // Check if permission is granted for creation of object, if necessary
             if ($this->id_type != self::WORKSPACE_NODE_ID) {
                 $type = ilObject::_lookupType((int) $this->parent_id, true);
             } else {
                 $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
             }
             $tree = $access_handler = null;
             switch ($type) {
                 // workspace structure
                 case 'wfld':
                 case 'wsrt':
                     $permission = $this->checkPermissionBool("create", "", "wfld");
                     $containerType = "WorkspaceFolder";
                     $tree = $this->tree;
                     $access_handler = $this->getAccessHandler();
                     break;
                     // use categories as structure
                 // use categories as structure
                 case 'cat':
                 case 'root':
                     $permission = $this->checkPermissionBool("create", "", "cat");
                     $containerType = "Category";
                     break;
                     // use folders as structure (in courses)
                 // use folders as structure (in courses)
                 default:
                     $permission = $this->checkPermissionBool("create", "", "fold");
                     $containerType = "Folder";
                     break;
             }
             // 	processZipFile (
             //		Dir to unzip,
             //		Path to uploaded file,
             //		should a structure be created (+ permission check)?
             //		ref_id of parent
             //		object that contains files (folder or category)
             //		should sendInfo be persistent?)
             try {
                 $processDone = ilFileUtils::processZipFile($newDir, $zip_file["tmp_name"], $adopt_structure && $permission, $this->parent_id, $containerType, $tree, $access_handler);
                 ilUtil::sendSuccess($this->lng->txt("file_added"), true);
             } catch (ilFileUtilsException $e) {
                 ilUtil::sendFailure($e->getMessage(), true);
             }
             ilUtil::delDir($newDir);
             $this->ctrl->returnToParent($this);
         } else {
             $zip_form_gui->setValuesByPost();
             $this->tpl->setContent($zip_form_gui->getHTML());
         }
     } else {
         $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
     }
 }
Exemplo n.º 8
0
 /**
  * update resource
  *
  * @access public
  * @param string resource "path"
  * @param int econtent id
  * @param string post content
  * @throws ilECSConnectorException
  */
 public function updateResource($a_path, $a_econtent_id, $a_post_string)
 {
     global $ilLog;
     $ilLog->write(__METHOD__ . ': Update resource with id ' . $a_econtent_id);
     $this->path_postfix = $a_path;
     if ($a_econtent_id) {
         $this->path_postfix .= '/' . (int) $a_econtent_id;
     } else {
         throw new ilECSConnectorException('Error calling updateResource: No content id given.');
     }
     try {
         $this->prepareConnection();
         $this->addHeader('Content-Type', 'application/json');
         $this->addHeader('Accept', 'application/json');
         $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
         $this->curl->setOpt(CURLOPT_HEADER, true);
         $this->curl->setOpt(CURLOPT_PUT, true);
         $tempfile = ilUtil::ilTempnam();
         $ilLog->write(__METHOD__ . ': Created new tempfile: ' . $tempfile);
         $fp = fopen($tempfile, 'w');
         fwrite($fp, $a_post_string);
         fclose($fp);
         $this->curl->setOpt(CURLOPT_UPLOAD, true);
         $this->curl->setOpt(CURLOPT_INFILESIZE, filesize($tempfile));
         $fp = fopen($tempfile, 'r');
         $this->curl->setOpt(CURLOPT_INFILE, $fp);
         $res = $this->call();
         fclose($fp);
         unlink($tempfile);
         return new ilECSResult($res);
     } catch (ilCurlConnectionException $exc) {
         throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
     }
 }
Exemplo n.º 9
0
 /**
  * Delivers a PDF file from a XSL-FO string
  *
  * @param string $fo The XSL-FO string
  * @access public
  */
 public function deliverPDFfromFO($fo, $title = null)
 {
     global $ilLog;
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     $fo_file = ilUtil::ilTempnam() . ".fo";
     $fp = fopen($fo_file, "w");
     fwrite($fp, $fo);
     fclose($fp);
     include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
     try {
         $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($fo);
         $filename = strlen($title) ? $title : $this->getTitle();
         ilUtil::deliverData($pdf_base64->scalar, ilUtil::getASCIIFilename($filename) . ".pdf", "application/pdf", false, true);
         return true;
     } catch (XML_RPC2_FaultException $e) {
         $ilLog->write(__METHOD__ . ': ' . $e->getMessage());
         return false;
     } catch (Exception $e) {
         $ilLog->write(__METHOD__ . ': ' . $e->getMessage());
         return false;
     }
     /*
     include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
     $fo2pdf = new ilFO2PDF();
     $fo2pdf->setFOString($fo);
     $result = $fo2pdf->send();
     $filename = (strlen($title)) ? $title : $this->getTitle();
     ilUtil::deliverData($result, ilUtil::getASCIIFilename($filename) . ".pdf", "application/pdf", false, true);
     */
 }
Exemplo n.º 10
0
 /**
  * Export the user specific results for the survey
  *
  * Export the user specific results for the survey
  *
  * @access private
  */
 function exportUserSpecificResults($export_format, $export_label, $finished_ids)
 {
     global $ilLog;
     // #13620
     ilDatePresentation::setUseRelativeDates(false);
     $csvfile = array();
     $csvrow = array();
     $csvrow2 = array();
     $questions = array();
     $questions =& $this->object->getSurveyQuestions(true);
     array_push($csvrow, $this->lng->txt("lastname"));
     // #12756
     array_push($csvrow, $this->lng->txt("firstname"));
     array_push($csvrow, $this->lng->txt("login"));
     array_push($csvrow, $this->lng->txt('workingtime'));
     // #13622
     array_push($csvrow, $this->lng->txt('survey_results_finished'));
     array_push($csvrow2, "");
     array_push($csvrow2, "");
     array_push($csvrow2, "");
     array_push($csvrow2, "");
     array_push($csvrow2, "");
     if ($this->object->canExportSurveyCode()) {
         array_push($csvrow, $this->lng->txt("codes"));
         array_push($csvrow2, "");
     }
     /* #8211
     		if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF)
     		{
     			array_push($csvrow, $this->lng->txt("gender"));
     		}		 
     	    */
     $cellcounter = 1;
     foreach ($questions as $question_id => $question_data) {
         include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
         $question = SurveyQuestion::_instanciateQuestion($question_data["question_id"]);
         switch ($export_label) {
             case "label_only":
                 $question->addUserSpecificResultsExportTitles($csvrow, true);
                 break;
             case "title_only":
                 $question->addUserSpecificResultsExportTitles($csvrow, false);
                 break;
             default:
                 $question->addUserSpecificResultsExportTitles($csvrow, false);
                 $question->addUserSpecificResultsExportTitles($csvrow2, true, false);
                 break;
         }
         $questions[$question_data["question_id"]] = $question;
     }
     array_push($csvfile, $csvrow);
     if (sizeof($csvrow2) && implode("", $csvrow2)) {
         array_push($csvfile, $csvrow2);
     }
     if (!$finished_ids) {
         $participants =& $this->object->getSurveyFinishedIds();
     } else {
         $participants = $finished_ids;
     }
     $finished_data = array();
     foreach ($this->object->getSurveyParticipants($participants) as $item) {
         $finished_data[$item["active_id"]] = $item;
     }
     foreach ($participants as $user_id) {
         if ($user_id < 1) {
             continue;
         }
         $resultset =& $this->object->getEvaluationByUser($questions, $user_id);
         $csvrow = array();
         // #12756
         array_push($csvrow, trim($resultset["lastname"]) ? $resultset["lastname"] : $resultset["name"]);
         // anonymous
         array_push($csvrow, $resultset["firstname"]);
         array_push($csvrow, $resultset["login"]);
         // #10579
         if ($this->object->canExportSurveyCode()) {
             array_push($csvrow, $user_id);
         }
         /* #8211
         			if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF)
         			{
         				array_push($csvrow, $resultset["gender"]);
         			}			
         		    */
         $wt = $this->object->getWorkingtimeForParticipant($user_id);
         array_push($csvrow, $wt);
         $finished = $finished_data[$user_id];
         if ((bool) $finished["finished"]) {
             array_push($csvrow, ilDatePresentation::formatDate(new ilDateTime($finished["finished_tstamp"], IL_CAL_UNIX)));
         } else {
             array_push($csvrow, "-");
         }
         foreach ($questions as $question_id => $question) {
             $question->addUserSpecificResultsData($csvrow, $resultset);
         }
         array_push($csvfile, $csvrow);
     }
     // #11179
     $surveyname = $this->object->getTitle() . " " . $this->lng->txt("svy_eval_user") . " " . date("Y-m-d");
     $surveyname = preg_replace("/\\s/", "_", trim($surveyname));
     $surveyname = ilUtil::getASCIIFilename($surveyname);
     switch ($export_format) {
         case self::TYPE_XLS:
             include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
             $excelfile = ilUtil::ilTempnam();
             $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
             $workbook = $adapter->getWorkbook();
             $workbook->setVersion(8);
             // Use Excel97/2000 Format
             // Creating a worksheet
             $format_bold =& $workbook->addFormat();
             $format_bold->setBold();
             $format_percent =& $workbook->addFormat();
             $format_percent->setNumFormat("0.00%");
             $format_datetime =& $workbook->addFormat();
             $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
             $format_title =& $workbook->addFormat();
             $format_title->setBold();
             $format_title->setColor('black');
             $format_title->setPattern(1);
             $format_title->setFgColor('silver');
             $format_title_plain =& $workbook->addFormat();
             $format_title_plain->setColor('black');
             $format_title_plain->setPattern(1);
             $format_title_plain->setFgColor('silver');
             // Creating a worksheet
             $pages = floor(count($csvfile[0]) / 250) + 1;
             $worksheets = array();
             for ($i = 0; $i < $pages; $i++) {
                 $worksheets[$i] =& $workbook->addWorksheet();
             }
             $row = 0;
             include_once "./Services/Excel/classes/class.ilExcelUtils.php";
             $contentstartrow = 0;
             foreach ($csvfile as $csvrow) {
                 $col = 0;
                 if ($row == 0) {
                     $worksheet = 0;
                     $mainworksheet =& $worksheets[$worksheet];
                     foreach ($csvrow as $text) {
                         if (is_array($text)) {
                             $textcount = 0;
                             foreach ($text as $string) {
                                 $mainworksheet->writeString($row + $textcount, $col, ilExcelUtils::_convert_text($string, $_POST["export_format"]), $format_title);
                                 $textcount++;
                                 $contentstartrow = max($contentstartrow, $textcount);
                             }
                             $col++;
                         } else {
                             $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]), $format_title);
                         }
                         if ($col % 251 == 0) {
                             $worksheet++;
                             $col = 1;
                             $mainworksheet =& $worksheets[$worksheet];
                             $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]), $format_title);
                         }
                     }
                     $row = $contentstartrow;
                 } else {
                     $worksheet = 0;
                     $mainworksheet =& $worksheets[$worksheet];
                     foreach ($csvrow as $text) {
                         if (is_numeric($text)) {
                             $mainworksheet->writeNumber($row, $col++, $text);
                         } else {
                             $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]));
                         }
                         if ($col % 251 == 0) {
                             $worksheet++;
                             $col = 1;
                             $mainworksheet =& $worksheets[$worksheet];
                             $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]));
                         }
                     }
                 }
                 $row++;
             }
             $workbook->close();
             ilUtil::deliverFile($excelfile, "{$surveyname}.xls", "application/vnd.ms-excel");
             exit;
             break;
         case self::TYPE_SPSS:
             $csv = "";
             $separator = ";";
             foreach ($csvfile as $idx => $csvrow) {
                 $csvrow =& str_replace("\n", " ", $this->object->processCSVRow($csvrow, TRUE, $separator));
                 $csv .= join($csvrow, $separator) . "\n";
             }
             include_once "./Services/Utilities/classes/class.ilUtil.php";
             ilUtil::deliverData($csv, "{$surveyname}.csv");
             exit;
             break;
     }
 }
Exemplo n.º 11
0
 /**
  * Import repository object export file
  *
  * @param	string		absolute filename of temporary upload file
  */
 public final function importObject($a_new_obj, $a_tmp_file, $a_filename, $a_type, $a_comp = "", $a_copy_file = false)
 {
     // create temporary directory
     $tmpdir = ilUtil::ilTempnam();
     ilUtil::makeDir($tmpdir);
     if ($a_copy_file) {
         copy($a_tmp_file, $tmpdir . "/" . $a_filename);
     } else {
         ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $tmpdir . "/" . $a_filename);
     }
     ilUtil::unzip($tmpdir . "/" . $a_filename);
     $dir = $tmpdir . "/" . substr($a_filename, 0, strlen($a_filename) - 4);
     $GLOBALS['ilLog']->write(__METHOD__ . ': do import with dir ' . $dir);
     $new_id = $this->doImportObject($dir, $a_type, $a_comp, $tmpdir);
     // delete temporary directory
     ilUtil::delDir($tmpdir);
     return $new_id;
 }
 /**
  * Create a temporary path to store the preview
  *
  * @return string
  */
 public function getCertificatePath()
 {
     if (!$this->temp_dir) {
         $tmpdir = ilUtil::ilTempnam();
         ilUtil::makeDir($tmpdir);
         $this->temp_dir = $tmpdir;
     }
     return $this->temp_dir;
 }
 /**
  * Updates a content on the Adobe Connect server
  *
  * @access public
  */
 public function updateContent()
 {
     $this->initFormContent(self::CONTENT_MOD_EDIT, (int) $_GET['content_id']);
     if ($this->cform->checkInput()) {
         $this->pluginObj->includeClass('class.ilAdobeConnectDuplicateContentException.php');
         $this->pluginObj->includeClass('class.ilAdobeConnectContentUploadException.php');
         $fdata = $this->cform->getInput('file');
         $target = '';
         if ($fdata['name'] != '') {
             $target = dirname(ilUtil::ilTempnam());
             ilUtil::moveUploadedFile($fdata['tmp_name'], $fdata['name'], $target . '/' . $fdata['name']);
         }
         try {
             $title = strlen($this->cform->getInput('tit')) ? $this->cform->getInput('tit') : $fdata['name'];
             $this->object->updateContent((int) $_GET['content_id'], $title, $this->cform->getInput('des'));
             if ($fdata['name'] != '') {
                 $curl = curl_init($this->object->uploadContent((int) $_GET['content_id']));
                 curl_setopt($curl, CURLOPT_VERBOSE, true);
                 curl_setopt($curl, CURLOPT_POST, true);
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                 # curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
                 curl_setopt($curl, CURLOPT_POSTFIELDS, array('file' => '@' . $target . '/' . $fdata['name']));
                 $postResult = curl_exec($curl);
                 curl_close($curl);
                 @unlink($target . '/' . $fdata['name']);
             }
             ilUtil::sendSuccess($this->txt('virtualClassroom_content_updated'), true);
             $this->showContent();
             return true;
         } catch (ilAdobeConnectException $e) {
             if ($fdata['name'] != '') {
                 @unlink($target . '/' . $fdata['name']);
             }
             ilUtil::sendFailure($this->txt($e->getMessage()));
             $this->cform->setValuesByPost();
             return $this->editItem();
         }
     } else {
         $this->cform->setValuesByPost();
         return $this->editItem();
     }
 }
 /**
  * send  bookmarks as attachment
  */
 function sendmail()
 {
     global $ilUser;
     include_once './Services/Mail/classes/class.ilFileDataMail.php';
     require_once "Services/Mail/classes/class.ilFormatMail.php";
     $mfile = new ilFileDataMail($ilUser->getId());
     $umail = new ilFormatMail($ilUser->getId());
     $html_content = $this->export(false);
     $tempfile = ilUtil::ilTempnam();
     $fp = fopen($tempfile, 'w');
     fwrite($fp, $html_content);
     fclose($fp);
     $filename = 'bookmarks.html';
     $mfile->copyAttachmentFile($tempfile, $filename);
     $umail->savePostData($ilUser->getId(), array($filename), '', '', '', '', '', '', '', 0);
     require_once 'Services/Mail/classes/class.ilMailFormCall.php';
     ilUtil::redirect(ilMailFormCall::getRedirectTarget($this, '', array(), array('type' => 'attach')));
 }
 /**
  * handler for end of element
  *
  * @param	resource	$a_xml_parser		xml parser
  * @param	string		$a_name				element name
  */
 function handlerEndTag($a_xml_parser, $a_name)
 {
     $this->cdata = trim($this->cdata);
     $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->cdata);
     switch ($a_name) {
         case 'File':
             $this->result = true;
             break;
         case 'Filename':
             if (strlen($this->cdata) == 0) {
                 throw new ilFileException("Filename ist missing!");
             }
             $this->file->setFilename($this->cdata);
             $this->file->setTitle($this->cdata);
             break;
         case 'Title':
             $this->file->setTitle(trim($this->cdata));
             break;
         case 'Description':
             $this->file->setDescription(trim($this->cdata));
             break;
         case 'Content':
             $GLOBALS['ilLog']->write($this->mode);
             $this->isReadingFile = false;
             $baseDecodedFilename = ilUtil::ilTempnam();
             if ($this->mode == ilFileXMLParser::$CONTENT_COPY) {
                 $this->tmpFilename = $this->getImportDirectory() . "/" . $this->cdata;
             } elseif ($this->mode == ilFileXMLParser::$CONTENT_REST) {
                 include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
                 $storage = new ilRestFileStorage();
                 $this->tmpFilename = $storage->getStoredFilePath($this->cdata);
                 if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename)) {
                     throw new ilFileException("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED);
                 }
                 $this->tmpFilename = $baseDecodedFilename;
             } else {
                 if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename)) {
                     throw new ilFileException("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED);
                 }
                 if ($this->mode == ilFileXMLParser::$CONTENT_GZ_COMPRESSED) {
                     if (!ilFileUtils::fastGunzip($baseDecodedFilename, $this->tmpFilename)) {
                         throw new ilFileException("Deflating with fastzunzip failed", ilFileException::$DECOMPRESSION_FAILED);
                     }
                     unlink($baseDecodedFilename);
                 } elseif ($this->mode == ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED) {
                     if (!ilFileUtils::fastGunzip($baseDecodedFilename, $this->tmpFilename)) {
                         throw new ilFileException("Deflating with fastDecompress failed", ilFileException::$DECOMPRESSION_FAILED);
                     }
                     unlink($baseDecodedFilename);
                 } else {
                     $this->tmpFilename = $baseDecodedFilename;
                 }
             }
             //$this->content = $content;
             $this->file->setFileSize(filesize($this->tmpFilename));
             // strlen($this->content));
             // if no file type is given => lookup mime type
             if (!$this->file->getFileType()) {
                 global $ilLog;
                 #$ilLog->write(__METHOD__.': Trying to detect mime type...');
                 include_once './Services/Utilities/classes/class.ilFileUtils.php';
                 $this->file->setFileType(ilFileUtils::_lookupMimeType($this->tmpFilename));
             }
             break;
     }
     $this->cdata = '';
     return;
 }
 /**
  * Download the given IDs of certificates as ZIP-File.
  * Note: No permission checking, this must be done by the controller calling this method
  *
  * @param array $cert_ids
  * @param string $filename Filename of zip, appended to the current date
  */
 public static function downloadAsZip(array $cert_ids = array(), $filename = 'certificates')
 {
     if (count($cert_ids)) {
         $zip_filename = date('d-m-Y') . '-' . $filename;
         // Make a random temp dir in ilias data directory
         $tmp_dir = ilUtil::ilTempnam();
         ilUtil::makeDir($tmp_dir);
         $zip_base_dir = $tmp_dir . DIRECTORY_SEPARATOR . $zip_filename;
         ilUtil::makeDir($zip_base_dir);
         // Copy all PDFs in folder
         foreach ($cert_ids as $cert_id) {
             /** @var srCertificate $cert */
             $cert = srCertificate::find((int) $cert_id);
             if (!is_null($cert) && $cert->getStatus() == srCertificate::STATUS_PROCESSED) {
                 copy($cert->getFilePath(), $zip_base_dir . DIRECTORY_SEPARATOR . $cert->getFilename(true));
             }
         }
         $tmp_zip_file = $tmp_dir . DIRECTORY_SEPARATOR . $zip_filename . '.zip';
         try {
             ilUtil::zip($zip_base_dir, $tmp_zip_file);
             rename($tmp_zip_file, $zip_file = ilUtil::ilTempnam());
             ilUtil::delDir($tmp_dir);
             ilUtil::deliverFile($zip_file, $zip_filename . '.zip', '', false, true);
         } catch (ilFileException $e) {
             ilUtil::sendInfo($e->getMessage());
         }
     }
 }
Exemplo n.º 17
0
 /**
  * Create member status record for a new assignment for all participants
  */
 function sendMultiFeedbackStructureFile()
 {
     global $ilDB;
     // send and delete the zip file
     $deliverFilename = trim(str_replace(" ", "_", $this->getTitle() . "_" . $this->getId()));
     $deliverFilename = ilUtil::getASCIIFilename($deliverFilename);
     $deliverFilename = "multi_feedback_" . $deliverFilename;
     $exc = new ilObjExercise($this->getExerciseId(), false);
     $cdir = getcwd();
     // create temporary directoy
     $tmpdir = ilUtil::ilTempnam();
     ilUtil::makeDir($tmpdir);
     $mfdir = $tmpdir . "/" . $deliverFilename;
     ilUtil::makeDir($mfdir);
     // create subfolders <lastname>_<firstname>_<id> for each participant
     include_once "./Modules/Exercise/classes/class.ilExerciseMembers.php";
     $exmem = new ilExerciseMembers($exc);
     $mems = $exmem->getMembers();
     foreach ($mems as $mem) {
         $name = ilObjUser::_lookupName($mem);
         $subdir = $name["lastname"] . "_" . $name["firstname"] . "_" . $name["login"] . "_" . $name["user_id"];
         $subdir = ilUtil::getASCIIFilename($subdir);
         ilUtil::makeDir($mfdir . "/" . $subdir);
     }
     // create the zip file
     chdir($tmpdir);
     $tmpzipfile = $tmpdir . "/multi_feedback.zip";
     ilUtil::zip($tmpdir, $tmpzipfile, true);
     chdir($cdir);
     ilUtil::deliverFile($tmpzipfile, $deliverFilename . ".zip", "", false, true);
 }
Exemplo n.º 18
0
 private function downloadMultipleObjects($a_ref_ids)
 {
     global $lng, $rbacsystem, $ilAccess;
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     include_once 'Modules/Folder/classes/class.ilObjFolder.php';
     include_once 'Modules/File/classes/class.ilObjFile.php';
     include_once 'Modules/File/classes/class.ilFileException.php';
     // create temporary file to download
     $zip = PATH_TO_ZIP;
     $tmpdir = ilUtil::ilTempnam();
     ilUtil::makeDir($tmpdir);
     try {
         // copy each selected object
         foreach ($a_ref_ids as $ref_id) {
             if (!$ilAccess->checkAccess("read", "", $ref_id)) {
                 continue;
             }
             if (ilObject::_isInTrash($ref_id)) {
                 continue;
             }
             // get object
             $object =& $this->ilias->obj_factory->getInstanceByRefId($ref_id);
             $obj_type = $object->getType();
             if ($obj_type == "fold") {
                 // copy folder to temp directory
                 self::recurseFolder($ref_id, $object->getTitle(), $tmpdir);
             } else {
                 if ($obj_type == "file") {
                     // copy file to temp directory
                     self::copyFile($object->getId(), $object->getTitle(), $tmpdir);
                 }
             }
         }
         // compress the folder
         $deliverFilename = ilUtil::getAsciiFilename($this->object->getTitle()) . ".zip";
         $tmpzipfile = ilUtil::ilTempnam() . ".zip";
         ilUtil::zip($tmpdir, $tmpzipfile, true);
         ilUtil::delDir($tmpdir);
         ilUtil::deliverFile($tmpzipfile, $deliverFilename, '', false, true, true);
     } catch (ilFileException $e) {
         ilUtil::sendInfo($e->getMessage(), true);
     }
 }
 /**
  * Export page layout template object
  */
 function exportLayoutObject()
 {
     include_once "./Services/Export/classes/class.ilExport.php";
     $exp = new ilExport();
     $tmpdir = ilUtil::ilTempnam();
     ilUtil::makeDir($tmpdir);
     $succ = $exp->exportEntity("pgtp", (int) $_GET["layout_id"], "4.2.0", "Services/COPage", "Title", $tmpdir);
     if ($succ["success"]) {
         ilUtil::deliverFile($succ["directory"] . "/" . $succ["file"], $succ["file"], "", false, false, false);
     }
     if (is_file($succ["directory"] . "/" . $succ["file"])) {
         unlink($succ["directory"] . "/" . $succ["file"]);
     }
     if (is_dir($succ["directory"])) {
         unlink($succ["directory"]);
     }
 }
Exemplo n.º 20
0
 /**
  * unzip file
  *
  * @param	string	$a_file		full path/filename
  * @param	boolean	$overwrite	pass true to overwrite existing files
  * @static
  * 
  */
 public static function unzip($a_file, $overwrite = false, $a_flat = false)
 {
     if (!is_file($a_file)) {
         return;
     }
     // if flat, move file to temp directory first
     if ($a_flat) {
         $tmpdir = ilUtil::ilTempnam();
         ilUtil::makeDir($tmpdir);
         copy($a_file, $tmpdir . DIRECTORY_SEPARATOR . basename($a_file));
         $orig_file = $a_file;
         $a_file = $tmpdir . DIRECTORY_SEPARATOR . basename($a_file);
         $origpathinfo = pathinfo($orig_file);
     }
     $pathinfo = pathinfo($a_file);
     $dir = $pathinfo["dirname"];
     $file = $pathinfo["basename"];
     // unzip
     $cdir = getcwd();
     chdir($dir);
     $unzip = PATH_TO_UNZIP;
     // the following workaround has been removed due to bug
     // http://www.ilias.de/mantis/view.php?id=7578
     // since the workaround is quite old, it may not be necessary
     // anymore, alex 9 Oct 2012
     /*
     		// workaround for unzip problem (unzip of subdirectories fails, so
     		// we create the subdirectories ourselves first)
     		// get list
     		$unzipcmd = "-Z -1 ".ilUtil::escapeShellArg($file);
     		$arr = ilUtil::execQuoted($unzip, $unzipcmd);
     		$zdirs = array();
     
     		foreach($arr as $line)
     		{
     			if(is_int(strpos($line, "/")))
     			{
     				$zdir = substr($line, 0, strrpos($line, "/"));
     				$nr = substr_count($zdir, "/");
     				//echo $zdir." ".$nr."<br>";
     				while ($zdir != "")
     				{
     					$nr = substr_count($zdir, "/");
     					$zdirs[$zdir] = $nr;				// collect directories
     					//echo $dir." ".$nr."<br>";
     					$zdir = substr($zdir, 0, strrpos($zdir, "/"));
     				}
     			}
     		}
     
     		asort($zdirs);
     
     		foreach($zdirs as $zdir => $nr)				// create directories
     		{
     			ilUtil::createDirectory($zdir);
     		}
     */
     // real unzip
     if (!$overwrite) {
         $unzipcmd = ilUtil::escapeShellArg($file);
     } else {
         $unzipcmd = "-o " . ilUtil::escapeShellArg($file);
     }
     ilUtil::execQuoted($unzip, $unzipcmd);
     chdir($cdir);
     // if flat, get all files and move them to original directory
     if ($a_flat) {
         include_once "./Services/Utilities/classes/class.ilFileUtils.php";
         $filearray = array();
         ilFileUtils::recursive_dirscan($tmpdir, $filearray);
         if (is_array($filearray["file"])) {
             foreach ($filearray["file"] as $k => $f) {
                 if (substr($f, 0, 1) != "." && $f != basename($orig_file)) {
                     copy($filearray["path"][$k] . $f, $origpathinfo["dirname"] . DIRECTORY_SEPARATOR . $f);
                 }
             }
         }
         ilUtil::delDir($tmpdir);
     }
 }
 /**
  * Download all submitted files of an assignment (all user)
  *
  * @param	$members		array of user names, key is user id
  */
 function downloadAllDeliveredFiles($a_eph_id, $a_ass_id, $members)
 {
     global $lng, $ilObjDataCache, $ilias;
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/classes/class.ilFSStorageEphorus.php";
     $storage = new ilFSStorageEphorus($a_eph_id, $a_ass_id);
     $storage->create();
     ksort($members);
     //$savepath = $this->getEphorusPath() . "/" . $this->obj_id . "/";
     $savepath = $storage->getAbsoluteSubmissionPath();
     $cdir = getcwd();
     // important check: if the directory does not exist
     // ILIAS stays in the current directory (echoing only a warning)
     // and the zip command below archives the whole ILIAS directory
     // (including the data directory) and sends a mega file to the user :-o
     if (!is_dir($savepath)) {
         return;
     }
     // Safe mode fix
     //		chdir($this->getEphorusPath());
     chdir($storage->getTempPath());
     $zip = PATH_TO_ZIP;
     // check first, if we have enough free disk space to copy all files to temporary directory
     $tmpdir = ilUtil::ilTempnam();
     ilUtil::makeDir($tmpdir);
     chdir($tmpdir);
     $dirsize = 0;
     foreach ($members as $id => $object) {
         $directory = $savepath . DIRECTORY_SEPARATOR . $id;
         $dirsize += ilUtil::dirsize($directory);
     }
     if ($dirsize > disk_free_space($tmpdir)) {
         return -1;
     }
     // copy all member directories to the temporary folder
     // switch from id to member name and append the login if the member name is double
     // ensure that no illegal filenames will be created
     // remove timestamp from filename
     $cache = array();
     foreach ($members as $id => $user) {
         $sourcedir = $savepath . DIRECTORY_SEPARATOR . $id;
         if (!is_dir($sourcedir)) {
             continue;
         }
         $userName = ilObjUser::_lookupName($id);
         $directory = ilUtil::getASCIIFilename(trim($userName["lastname"]) . "_" . trim($userName["firstname"]));
         if (array_key_exists($directory, $cache)) {
             // first try is to append the login;
             $directory = ilUtil::getASCIIFilename($directory . "_" . trim(ilObjUser::_lookupLogin($id)));
             if (array_key_exists($directory, $cache)) {
                 // second and secure: append the user id as well.
                 $directory .= "_" . $id;
             }
         }
         $cache[$directory] = $directory;
         ilUtil::makeDir($directory);
         $sourcefiles = scandir($sourcedir);
         foreach ($sourcefiles as $sourcefile) {
             if ($sourcefile == "." || $sourcefile == "..") {
                 continue;
             }
             $targetfile = trim(basename($sourcefile));
             $pos = strpos($targetfile, "_");
             if ($pos === false) {
             } else {
                 $targetfile = substr($targetfile, $pos + 1);
             }
             $targetfile = $directory . DIRECTORY_SEPARATOR . $targetfile;
             $sourcefile = $sourcedir . DIRECTORY_SEPARATOR . $sourcefile;
             if (!copy($sourcefile, $targetfile)) {
                 //echo 'Could not copy '.$sourcefile.' to '.$targetfile;
                 $ilias->raiseError('Could not copy ' . basename($sourcefile) . " to '" . $targetfile . "'.", $ilias->error_obj->MESSAGE);
             } else {
                 // preserve time stamp
                 touch($targetfile, filectime($sourcefile));
             }
         }
     }
     $tmpfile = ilUtil::ilTempnam();
     $tmpzipfile = $tmpfile . ".zip";
     // Safe mode fix
     $zipcmd = $zip . " -r " . ilUtil::escapeShellArg($tmpzipfile) . " .";
     exec($zipcmd);
     ilUtil::delDir($tmpdir);
     $assTitle = ilEphAssignment::lookupTitle($a_ass_id);
     chdir($cdir);
     ilUtil::deliverFile($tmpzipfile, (strlen($assTitle) == 0 ? strtolower($lng->txt("rep_robj_xeph_ephorus_assignment")) : $assTitle) . ".zip", "", false, true);
 }
Exemplo n.º 22
0
    /**
     * Generates a ZIP file containing all file uploads for a given test and the original id of the question
     *
     * @param int $test_id
     */
    public function getFileUploadZIPFile($test_id)
    {
        /** @var ilDB $ilDB */
        global $ilDB;
        $query = "\n\t\tSELECT \n\t\t\ttst_solutions.solution_id, tst_solutions.pass, tst_solutions.active_fi, tst_solutions.question_fi, \n\t\t\ttst_solutions.value1, tst_solutions.value2, tst_solutions.tstamp \n\t\tFROM tst_solutions, tst_active, qpl_questions \n\t\tWHERE tst_solutions.active_fi = tst_active.active_id \n\t\tAND tst_solutions.question_fi = qpl_questions.question_id \n\t\tAND tst_solutions.question_fi = %s \n\t\tAND tst_active.test_fi = %s \n\t\tORDER BY tst_solutions.active_fi, tst_solutions.tstamp";
        $result = $ilDB->queryF($query, array("integer", "integer"), array($this->getId(), $test_id));
        $zipfile = ilUtil::ilTempnam() . ".zip";
        $tempdir = ilUtil::ilTempnam();
        if ($result->numRows()) {
            $userdata = array();
            $data .= "<html><head>";
            $data .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />';
            $data .= '<style>
			 table { border: 1px #333 solid; border-collapse:collapse;}	
			 td, th { border: 1px #333 solid; padding: 0.25em;}	
			 th { color: #fff; background-color: #666;}
			</style>
			';
            $data .= "<title>" . $this->getTitle() . "</title></head><body>\n";
            $data .= "<h1>" . $this->getTitle() . "</h1>\n";
            $data .= "<table><thead>\n";
            $data .= "<tr><th>" . $this->lng->txt("name") . "</th><th>" . $this->lng->txt("filename") . "</th><th>" . $this->lng->txt("pass") . "</th><th>" . $this->lng->txt("location") . "</th><th>" . $this->lng->txt("date") . "</th></tr></thead><tbody>\n";
            while ($row = $ilDB->fetchAssoc($result)) {
                ilUtil::makeDirParents($tempdir . "/" . $row["active_fi"] . "/" . $row["question_fi"]);
                @copy($this->getFileUploadPath($test_id, $row["active_fi"], $row["question_fi"]) . $row["value1"], $tempdir . "/" . $row["active_fi"] . "/" . $row["question_fi"] . "/" . $row["value1"]);
                if (!array_key_exists($row["active_fi"], $userdata)) {
                    include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
                    $userdata[$row["active_fi"]] = ilObjTestAccess::_getParticipantData($row["active_fi"]);
                }
                $data .= "<tr><td>" . $userdata[$row["active_fi"]] . "</td><td><a href=\"" . $row["active_fi"] . "/" . $row["question_fi"] . "/" . $row["value1"] . "\" target=\"_blank\">" . $row["value2"] . "</a></td><td>" . $row["pass"] . "</td><td>" . $row["active_fi"] . "/" . $row["question_fi"] . "/" . $row["value1"] . "</td>";
                $data .= "<td>" . ilFormat::fmtDateTime(ilFormat::unixtimestamp2datetime($row["tstamp"]), $this->lng->txt("lang_dateformat"), $this->lng->txt("lang_timeformat"), "datetime", FALSE) . "</td>";
                $data .= "</tr>\n";
            }
            $data .= "</tbody></table>\n";
            $data .= "</body></html>\n";
            $indexfile = $tempdir . "/index.html";
            $fh = fopen($indexfile, 'w');
            fwrite($fh, $data);
            fclose($fh);
        }
        ilUtil::zip($tempdir, $zipfile);
        ilUtil::delDir($tempdir);
        ilUtil::deliverFile($zipfile, ilUtil::getASCIIFilename($this->getTitle() . ".zip"), "application/zip", false, true);
    }
Exemplo n.º 23
0
 public function downloadFolder()
 {
     global $lng, $rbacsystem, $ilAccess;
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     include_once 'Modules/File/classes/class.ilObjFile.php';
     include_once 'Modules/File/classes/class.ilFileException.php';
     if (!$ilAccess->checkAccess("read", "", $this->getRefId())) {
         $this->ilErr->raiseError(get_class($this) . "::downloadFolder(): missing read permission!", $this->ilErr->WARNING);
     }
     if (ilObject::_isInTrash($this->getRefId())) {
         $this->ilErr->raiseError(get_class($this) . "::downloadFolder(): object is trashed!", $this->ilErr->WARNING);
     }
     $zip = PATH_TO_ZIP;
     $tmpdir = ilUtil::ilTempnam();
     ilUtil::makeDir($tmpdir);
     $basename = ilUtil::getAsciiFilename($this->getTitle());
     $deliverFilename = $basename . ".zip";
     $zipbasedir = $tmpdir . DIRECTORY_SEPARATOR . $basename;
     $tmpzipfile = $tmpdir . DIRECTORY_SEPARATOR . $deliverFilename;
     try {
         ilObjFolder::recurseFolder($this->getRefId(), $this->getTitle(), $tmpdir);
         ilUtil::zip($zipbasedir, $tmpzipfile);
         rename($tmpzipfile, $zipfile = ilUtil::ilTempnam());
         ilUtil::delDir($tmpdir);
         ilUtil::deliverFile($zipfile, $deliverFilename, '', false, true);
     } catch (ilFileException $e) {
         ilUtil::sendInfo($e->getMessage(), true);
     }
 }
Exemplo n.º 24
0
 /**
  * Handles the upload of a single file and adds it to the parent object.
  * 
  * @param array $file_upload An array containing the file upload parameters.
  * @return object The response object.
  */
 protected function handleFileUpload($file_upload)
 {
     global $ilUser;
     // file upload params
     $filename = $file_upload["name"];
     $type = $file_upload["type"];
     $size = $file_upload["size"];
     $temp_name = $file_upload["tmp_name"];
     // additional params
     $title = $file_upload["title"];
     $description = $file_upload["description"];
     $extract = $file_upload["extract"];
     $keep_structure = $file_upload["keep_structure"];
     // create answer object
     $response = new stdClass();
     $response->fileName = $filename;
     $response->fileSize = intval($size);
     $response->fileType = $type;
     $response->fileUnzipped = $extract;
     $response->error = null;
     // extract archive?
     if ($extract) {
         $zip_file = $filename;
         $adopt_structure = $keep_structure;
         include_once "Services/Utilities/classes/class.ilFileUtils.php";
         // Create unzip-directory
         $newDir = ilUtil::ilTempnam();
         ilUtil::makeDir($newDir);
         // Check if permission is granted for creation of object, if necessary
         if ($this->id_type != self::WORKSPACE_NODE_ID) {
             $type = ilObject::_lookupType((int) $this->parent_id, true);
         } else {
             $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
         }
         $tree = $access_handler = null;
         switch ($type) {
             // workspace structure
             case 'wfld':
             case 'wsrt':
                 $permission = $this->checkPermissionBool("create", "", "wfld");
                 $containerType = "WorkspaceFolder";
                 $tree = $this->tree;
                 $access_handler = $this->getAccessHandler();
                 break;
                 // use categories as structure
             // use categories as structure
             case 'cat':
             case 'root':
                 $permission = $this->checkPermissionBool("create", "", "cat");
                 $containerType = "Category";
                 break;
                 // use folders as structure (in courses)
             // use folders as structure (in courses)
             default:
                 $permission = $this->checkPermissionBool("create", "", "fold");
                 $containerType = "Folder";
                 break;
         }
         try {
             // 	processZipFile (
             //		Dir to unzip,
             //		Path to uploaded file,
             //		should a structure be created (+ permission check)?
             //		ref_id of parent
             //		object that contains files (folder or category)
             //		should sendInfo be persistent?)
             ilFileUtils::processZipFile($newDir, $temp_name, $adopt_structure && $permission, $this->parent_id, $containerType, $tree, $access_handler);
         } catch (ilFileUtilsException $e) {
             $response->error = $e->getMessage();
         } catch (Exception $ex) {
             $response->error = $ex->getMessage();
         }
         ilUtil::delDir($newDir);
         // #15404
         if ($this->id_type != self::WORKSPACE_NODE_ID) {
             foreach (ilFileUtils::getNewObjects() as $parent_ref_id => $objects) {
                 if ($parent_ref_id != $this->parent_id) {
                     continue;
                 }
                 foreach ($objects as $object) {
                     $this->after_creation_callback_objects[] = $object;
                 }
             }
         }
     } else {
         if (trim($title) == "") {
             $title = $filename;
         } else {
             // BEGIN WebDAV: Ensure that object title ends with the filename extension
             $fileExtension = ilObjFileAccess::_getFileExtension($filename);
             $titleExtension = ilObjFileAccess::_getFileExtension($title);
             if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) {
                 $title .= '.' . $fileExtension;
             }
             // END WebDAV: Ensure that object title ends with the filename extension
         }
         // create and insert file in grp_tree
         include_once "./Modules/File/classes/class.ilObjFile.php";
         $fileObj = new ilObjFile();
         $fileObj->setTitle($title);
         $fileObj->setDescription($description);
         $fileObj->setFileName($filename);
         include_once "./Services/Utilities/classes/class.ilMimeTypeUtil.php";
         $fileObj->setFileType(ilMimeTypeUtil::getMimeType("", $filename, $type));
         $fileObj->setFileSize($size);
         $this->object_id = $fileObj->create();
         $this->putObjectInTree($fileObj, $this->parent_id);
         // see uploadFiles()
         if (is_array($this->after_creation_callback_objects)) {
             $this->after_creation_callback_objects[] = $fileObj;
         }
         // upload file to filesystem
         $fileObj->createDirectory();
         $fileObj->raiseUploadError(false);
         $fileObj->getUploadFile($temp_name, $filename);
         $this->handleAutoRating($fileObj);
         // BEGIN ChangeEvent: Record write event.
         require_once './Services/Tracking/classes/class.ilChangeEvent.php';
         ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
         // END ChangeEvent: Record write event.
     }
     return $response;
 }
Exemplo n.º 25
0
 /**
  * Exports the evaluation data to the Microsoft Excel file format
  *
  * @param bool    $deliver
  * @param string  $filterby
  * @param string  $filtertext Filter text for the user data
  * @param boolean $passedonly TRUE if only passed user datasets should be exported, FALSE otherwise
  *
  * @return string
  */
 public function exportToExcel($deliver = TRUE, $filterby = "", $filtertext = "", $passedonly = FALSE)
 {
     if (strcmp($this->mode, "aggregated") == 0) {
         return $this->aggregatedResultsToExcel($deliver);
     }
     require_once './Services/Excel/classes/class.ilExcelWriterAdapter.php';
     $excelfile = ilUtil::ilTempnam();
     $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
     $testname = $this->test_obj->getTitle();
     switch ($this->mode) {
         case 'results':
             $testname .= '_results';
             break;
     }
     $testname = ilUtil::getASCIIFilename(preg_replace("/\\s/", "_", $testname)) . ".xls";
     $workbook = $adapter->getWorkbook();
     $workbook->setVersion(8);
     // Use Excel97/2000 Format
     // Creating a worksheet
     $format_bold =& $workbook->addFormat();
     $format_bold->setBold();
     $format_percent =& $workbook->addFormat();
     $format_percent->setNumFormat("0.00%");
     $format_datetime =& $workbook->addFormat();
     $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
     $format_title =& $workbook->addFormat();
     $format_title->setBold();
     $format_title->setColor('black');
     $format_title->setPattern(1);
     $format_title->setFgColor('silver');
     require_once './Services/Excel/classes/class.ilExcelUtils.php';
     $worksheet =& $workbook->addWorksheet(ilExcelUtils::_convert_text($this->lng->txt("tst_results")));
     $additionalFields = $this->test_obj->getEvaluationAdditionalFields();
     $row = 0;
     $col = 0;
     if ($this->test_obj->getAnonymity()) {
         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("counter")), $format_title);
     } else {
         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("name")), $format_title);
         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("login")), $format_title);
     }
     if (count($additionalFields)) {
         foreach ($additionalFields as $fieldname) {
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt($fieldname)), $format_title);
         }
     }
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_resultspoints")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("maximum_points")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_resultsmarks")), $format_title);
     if ($this->test_obj->getECTSOutput()) {
         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("ects_grade")), $format_title);
     }
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_qworkedthrough")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_qmax")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_pworkedthrough")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_timeofwork")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_atimeofwork")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_firstvisit")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_lastvisit")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_mark_median")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_rank_participant")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_rank_median")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_total_participants")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("tst_stat_result_median")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("scored_pass")), $format_title);
     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("pass")), $format_title);
     $counter = 1;
     $data =& $this->test_obj->getCompleteEvaluationData(TRUE, $filterby, $filtertext);
     $firstrowwritten = false;
     foreach ($data->getParticipants() as $active_id => $userdata) {
         $remove = FALSE;
         if ($passedonly) {
             if ($data->getParticipant($active_id)->getPassed() == FALSE) {
                 $remove = TRUE;
             }
         }
         if (!$remove) {
             $row++;
             if ($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions()) {
                 $row++;
             }
             $col = 0;
             if ($this->test_obj->getAnonymity()) {
                 $worksheet->write($row, $col++, ilExcelUtils::_convert_text($counter));
             } else {
                 $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getName()));
                 $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getLogin()));
             }
             if (count($additionalFields)) {
                 $userfields = ilObjUser::_lookupFields($userdata->getUserID());
                 foreach ($additionalFields as $fieldname) {
                     if (strcmp($fieldname, "gender") == 0) {
                         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt("gender_" . $userfields[$fieldname])));
                     } else {
                         $worksheet->write($row, $col++, ilExcelUtils::_convert_text($userfields[$fieldname]));
                     }
                 }
             }
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getReached()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getMaxpoints()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getMark()));
             if ($this->test_obj->getECTSOutput()) {
                 $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getECTSMark()));
             }
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getQuestionsWorkedThrough()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getParticipant($active_id)->getNumberOfQuestions()));
             $worksheet->write($row, $col++, $data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() / 100.0, $format_percent);
             $time = $data->getParticipant($active_id)->getTimeOfWork();
             $time_seconds = $time;
             $time_hours = floor($time_seconds / 3600);
             $time_seconds -= $time_hours * 3600;
             $time_minutes = floor($time_seconds / 60);
             $time_seconds -= $time_minutes * 60;
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text(sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds)));
             $time = $data->getParticipant($active_id)->getQuestionsWorkedThrough() ? $data->getParticipant($active_id)->getTimeOfWork() / $data->getParticipant($active_id)->getQuestionsWorkedThrough() : 0;
             $time_seconds = $time;
             $time_hours = floor($time_seconds / 3600);
             $time_seconds -= $time_hours * 3600;
             $time_minutes = floor($time_seconds / 60);
             $time_seconds -= $time_minutes * 60;
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text(sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds)));
             $fv = getdate($data->getParticipant($active_id)->getFirstVisit());
             $firstvisit = ilUtil::excelTime($fv["year"], $fv["mon"], $fv["mday"], $fv["hours"], $fv["minutes"], $fv["seconds"]);
             $worksheet->write($row, $col++, $firstvisit, $format_datetime);
             $lv = getdate($data->getParticipant($active_id)->getLastVisit());
             $lastvisit = ilUtil::excelTime($lv["year"], $lv["mon"], $lv["mday"], $lv["hours"], $lv["minutes"], $lv["seconds"]);
             $worksheet->write($row, $col++, $lastvisit, $format_datetime);
             $median = $data->getStatistics()->getStatistics()->median();
             $pct = $data->getParticipant($active_id)->getMaxpoints() ? $median / $data->getParticipant($active_id)->getMaxpoints() * 100.0 : 0;
             $mark = $this->test_obj->mark_schema->getMatchingMark($pct);
             $mark_short_name = "";
             if (is_object($mark)) {
                 $mark_short_name = $mark->getShortName();
             }
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($mark_short_name));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getStatistics()->getStatistics()->rank($data->getParticipant($active_id)->getReached())));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getStatistics()->getStatistics()->rank_median()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($data->getStatistics()->getStatistics()->count()));
             $worksheet->write($row, $col++, ilExcelUtils::_convert_text($median));
             if ($this->test_obj->getPassScoring() == SCORE_BEST_PASS) {
                 $worksheet->write($row, $col++, $data->getParticipant($active_id)->getBestPass() + 1);
             } else {
                 $worksheet->write($row, $col++, $data->getParticipant($active_id)->getLastPass() + 1);
             }
             $startcol = $col;
             for ($pass = 0; $pass <= $data->getParticipant($active_id)->getLastPass(); $pass++) {
                 $col = $startcol;
                 $finishdate = $this->test_obj->getPassFinishDate($active_id, $pass);
                 if ($finishdate > 0) {
                     if ($pass > 0) {
                         $row++;
                         if ($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions()) {
                             $row++;
                         }
                     }
                     $worksheet->write($row, $col++, ilExcelUtils::_convert_text($pass + 1));
                     if (is_object($data->getParticipant($active_id)) && is_array($data->getParticipant($active_id)->getQuestions($pass))) {
                         foreach ($data->getParticipant($active_id)->getQuestions($pass) as $question) {
                             $question_data = $data->getParticipant($active_id)->getPass($pass)->getAnsweredQuestionByQuestionId($question["id"]);
                             $worksheet->write($row, $col, ilExcelUtils::_convert_text($question_data["reached"]));
                             if ($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions()) {
                                 $worksheet->write($row - 1, $col, ilExcelUtils::_convert_text(preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"]))), $format_title);
                             } else {
                                 if ($pass == 0 && !$firstrowwritten) {
                                     $worksheet->write(0, $col, ilExcelUtils::_convert_text(preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"]))), $format_title);
                                 }
                             }
                             $col++;
                         }
                         $firstrowwritten = true;
                     }
                 }
             }
             $counter++;
         }
     }
     if ($this->test_obj->getExportSettingsSingleChoiceShort() && !$this->test_obj->isRandomTest() && $this->test_obj->hasSingleChoiceQuestions()) {
         // special tab for single choice tests
         $titles =& $this->test_obj->getQuestionTitlesAndIndexes();
         $positions = array();
         $pos = 0;
         $row = 0;
         foreach ($titles as $id => $title) {
             $positions[$id] = $pos;
             $pos++;
         }
         $usernames = array();
         $participantcount = count($data->getParticipants());
         $allusersheet = false;
         $pages = 0;
         $resultsheet =& $workbook->addWorksheet($this->lng->txt("eval_all_users"));
         $col = 0;
         $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('name')), $format_title);
         $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('login')), $format_title);
         if (count($additionalFields)) {
             foreach ($additionalFields as $fieldname) {
                 if (strcmp($fieldname, "matriculation") == 0) {
                     $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('matriculation')), $format_title);
                 }
             }
         }
         $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('test')), $format_title);
         foreach ($titles as $title) {
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($title), $format_title);
         }
         $row++;
         foreach ($data->getParticipants() as $active_id => $userdata) {
             $username = !is_null($userdata) && ilExcelUtils::_convert_text($userdata->getName()) ? ilExcelUtils::_convert_text($userdata->getName()) : "ID {$active_id}";
             if (array_key_exists($username, $usernames)) {
                 $usernames[$username]++;
                 $username .= " ({$i})";
             } else {
                 $usernames[$username] = 1;
             }
             $col = 0;
             $resultsheet->write($row, $col++, $username);
             $resultsheet->write($row, $col++, $userdata->getLogin());
             if (count($additionalFields)) {
                 $userfields = ilObjUser::_lookupFields($userdata->getUserID());
                 foreach ($additionalFields as $fieldname) {
                     if (strcmp($fieldname, "matriculation") == 0) {
                         if (strlen($userfields[$fieldname])) {
                             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($userfields[$fieldname]));
                         } else {
                             $col++;
                         }
                     }
                 }
             }
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->test_obj->getTitle()));
             $pass = $userdata->getScoredPass();
             if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
                 foreach ($userdata->getQuestions($pass) as $question) {
                     $objQuestion =& $this->test_obj->_instanciateQuestion($question["aid"]);
                     if (is_object($objQuestion) && strcmp($objQuestion->getQuestionType(), 'assSingleChoice') == 0) {
                         $solution = $objQuestion->getSolutionValues($active_id, $pass);
                         $pos = $positions[$question["aid"]];
                         $selectedanswer = "x";
                         foreach ($objQuestion->getAnswers() as $id => $answer) {
                             if (strlen($solution[0]["value1"]) && $id == $solution[0]["value1"]) {
                                 $selectedanswer = $answer->getAnswertext();
                             }
                         }
                         $resultsheet->write($row, $col + $pos, ilExcelUtils::_convert_text($selectedanswer));
                     }
                 }
             }
             $row++;
         }
         if ($this->test_obj->isSingleChoiceTestWithoutShuffle()) {
             // special tab for single choice tests without shuffle option
             $pos = 0;
             $row = 0;
             $usernames = array();
             $allusersheet = false;
             $pages = 0;
             $resultsheet =& $workbook->addWorksheet($this->lng->txt("eval_all_users") . " (2)");
             $col = 0;
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('name')), $format_title);
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('login')), $format_title);
             if (count($additionalFields)) {
                 foreach ($additionalFields as $fieldname) {
                     if (strcmp($fieldname, "matriculation") == 0) {
                         $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('matriculation')), $format_title);
                     }
                 }
             }
             $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('test')), $format_title);
             foreach ($titles as $title) {
                 $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($title), $format_title);
             }
             $row++;
             foreach ($data->getParticipants() as $active_id => $userdata) {
                 $username = !is_null($userdata) && ilExcelUtils::_convert_text($userdata->getName()) ? ilExcelUtils::_convert_text($userdata->getName()) : "ID {$active_id}";
                 if (array_key_exists($username, $usernames)) {
                     $usernames[$username]++;
                     $username .= " ({$i})";
                 } else {
                     $usernames[$username] = 1;
                 }
                 $col = 0;
                 $resultsheet->write($row, $col++, $username);
                 $resultsheet->write($row, $col++, $userdata->getLogin());
                 if (count($additionalFields)) {
                     $userfields = ilObjUser::_lookupFields($userdata->getUserID());
                     foreach ($additionalFields as $fieldname) {
                         if (strcmp($fieldname, "matriculation") == 0) {
                             if (strlen($userfields[$fieldname])) {
                                 $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($userfields[$fieldname]));
                             } else {
                                 $col++;
                             }
                         }
                     }
                 }
                 $resultsheet->write($row, $col++, ilExcelUtils::_convert_text($this->test_obj->getTitle()));
                 $pass = $userdata->getScoredPass();
                 if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
                     foreach ($userdata->getQuestions($pass) as $question) {
                         $objQuestion =& $this->test_obj->_instanciateQuestion($question["aid"]);
                         if (is_object($objQuestion) && strcmp($objQuestion->getQuestionType(), 'assSingleChoice') == 0) {
                             $solution = $objQuestion->getSolutionValues($active_id, $pass);
                             $pos = $positions[$question["aid"]];
                             $selectedanswer = chr(65 + $solution[0]["value1"]);
                             $resultsheet->write($row, $col + $pos, ilExcelUtils::_convert_text($selectedanswer));
                         }
                     }
                 }
                 $row++;
             }
         }
     } else {
         // test participant result export
         $usernames = array();
         $participantcount = count($data->getParticipants());
         $allusersheet = false;
         $pages = 0;
         $i = 0;
         foreach ($data->getParticipants() as $active_id => $userdata) {
             $i++;
             $username = !is_null($userdata) && ilExcelUtils::_convert_text($userdata->getName()) ? ilExcelUtils::_convert_text($userdata->getName()) : "ID {$active_id}";
             if (array_key_exists($username, $usernames)) {
                 $usernames[$username]++;
                 $username .= " ({$i})";
             } else {
                 $usernames[$username] = 1;
             }
             if ($participantcount > 250) {
                 if (!$allusersheet || $pages - 1 < floor($row / 64000)) {
                     $resultsheet =& $workbook->addWorksheet($this->lng->txt("eval_all_users") . ($pages > 0 ? " (" . ($pages + 1) . ")" : ""));
                     $allusersheet = true;
                     $row = 0;
                     $pages++;
                 }
             } else {
                 $resultsheet =& $workbook->addWorksheet($username);
             }
             if (method_exists($resultsheet, "writeString")) {
                 $pass = $userdata->getScoredPass();
                 $row = $allusersheet ? $row : 0;
                 $resultsheet->writeString($row, 0, ilExcelUtils::_convert_text(sprintf($this->lng->txt("tst_result_user_name_pass"), $pass + 1, $userdata->getName())), $format_bold);
                 $row += 2;
                 if (is_object($userdata) && is_array($userdata->getQuestions($pass))) {
                     foreach ($userdata->getQuestions($pass) as $question) {
                         require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
                         $question = assQuestion::_instanciateQuestion($question["id"]);
                         if (is_object($question)) {
                             $row = $question->setExportDetailsXLS($resultsheet, $row, $active_id, $pass, $format_title, $format_bold);
                         }
                     }
                 }
             }
         }
     }
     $workbook->close();
     if ($deliver) {
         ilUtil::deliverFile($excelfile, $testname, "application/vnd.ms-excel", false, true);
         exit;
     } else {
         return $excelfile;
     }
 }
 /**
  * Exports grades as excel
  */
 function exportGradesExcel()
 {
     include_once "./Modules/Exercise/classes/class.ilExAssignment.php";
     $ass_data = ilExAssignment::getAssignmentDataOfExercise($this->getId());
     include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
     $excelfile = ilUtil::ilTempnam();
     $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
     $workbook = $adapter->getWorkbook();
     $workbook->setVersion(8);
     // Use Excel97/2000 Format
     include_once "./Services/Excel/classes/class.ilExcelUtils.php";
     //
     // status
     //
     $mainworksheet = $workbook->addWorksheet();
     // header row
     $mainworksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("name")));
     $cnt = 1;
     foreach ($ass_data as $ass) {
         $mainworksheet->writeString(0, $cnt, $cnt);
         $cnt++;
     }
     $mainworksheet->writeString(0, $cnt, ilExcelUtils::_convert_text($this->lng->txt("exc_total_exc")));
     // data rows
     $this->mem_obj = new ilExerciseMembers($this);
     $getmems = $this->mem_obj->getMembers();
     $mems = array();
     foreach ($getmems as $user_id) {
         $mems[$user_id] = ilObjUser::_lookupName($user_id);
     }
     $mems = ilUtil::sortArray($mems, "lastname", "asc", false, true);
     $data = array();
     $row_cnt = 1;
     foreach ($mems as $user_id => $d) {
         $col_cnt = 1;
         // name
         $mainworksheet->writeString($row_cnt, 0, ilExcelUtils::_convert_text($d["lastname"] . ", " . $d["firstname"] . " [" . $d["login"] . "]"));
         reset($ass_data);
         foreach ($ass_data as $ass) {
             $status = ilExAssignment::lookupStatusOfUser($ass["id"], $user_id);
             $mainworksheet->writeString($row_cnt, $col_cnt, ilExcelUtils::_convert_text($this->lng->txt("exc_" . $status)));
             $col_cnt++;
         }
         // total status
         $status = ilExerciseMembers::_lookupStatus($this->getId(), $user_id);
         $mainworksheet->writeString($row_cnt, $col_cnt, ilExcelUtils::_convert_text($this->lng->txt("exc_" . $status)));
         $row_cnt++;
     }
     //
     // mark
     //
     $worksheet2 = $workbook->addWorksheet();
     // header row
     $worksheet2->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("name")));
     $cnt = 1;
     foreach ($ass_data as $ass) {
         $worksheet2->writeString(0, $cnt, $cnt);
         $cnt++;
     }
     $worksheet2->writeString(0, $cnt, ilExcelUtils::_convert_text($this->lng->txt("exc_total_exc")));
     // data rows
     $data = array();
     $row_cnt = 1;
     reset($mems);
     foreach ($mems as $user_id => $d) {
         $col_cnt = 1;
         $d = ilObjUser::_lookupName($user_id);
         // name
         $worksheet2->writeString($row_cnt, 0, ilExcelUtils::_convert_text($d["lastname"] . ", " . $d["firstname"] . " [" . $d["login"] . "]"));
         reset($ass_data);
         foreach ($ass_data as $ass) {
             $worksheet2->writeString($row_cnt, $col_cnt, ilExcelUtils::_convert_text(ilExAssignment::lookupMarkOfUser($ass["id"], $user_id)));
             $col_cnt++;
         }
         // total mark
         include_once 'Services/Tracking/classes/class.ilLPMarks.php';
         $worksheet2->writeString($row_cnt, $col_cnt, ilExcelUtils::_convert_text(ilLPMarks::_lookupMark($user_id, $this->getId())));
         $row_cnt++;
     }
     $workbook->close();
     $exc_name = ilUtil::getASCIIFilename(preg_replace("/\\s/", "_", $this->getTitle()));
     ilUtil::deliverFile($excelfile, $exc_name . ".xls", "application/vnd.ms-excel");
 }
 /**
  * Upload appointments
  */
 protected function uploadAppointments()
 {
     // @todo permission check
     $form = $this->initImportForm();
     if ($form->checkInput()) {
         $file = $form->getInput('file');
         $tmp = ilUtil::ilTempnam();
         ilUtil::moveUploadedFile($file['tmp_name'], $file['name'], $tmp);
         $num = $this->doImportFile($tmp, (int) $_REQUEST['category_id']);
         ilUtil::sendSuccess(sprintf($this->lng->txt('cal_imported_success'), (int) $num), true);
         $this->ctrl->redirect($this, 'manage');
     }
     ilUtil::sendFailure($this->lng->txt('cal_err_file_upload'), true);
     $this->initImportForm($form);
 }
 /**
  * Import template
  */
 protected function importTemplate()
 {
     global $ilCtrl;
     $form = $this->createImportForm();
     if (!$form->checkInput()) {
         ilUtil::sendFailure($this->lng->txt('err_check_input'));
         $form->setValuesByPost();
         return $this->showImportForm($form);
     }
     // Do import
     include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateImport.php';
     $import = new ilDidacticTemplateImport(ilDidacticTemplateImport::IMPORT_FILE);
     $file = $form->getInput('file');
     $tmp = ilUtil::ilTempnam();
     // move uploaded file
     ilUtil::moveUploadedFile($file['tmp_name'], $file['name'], $tmp);
     $import->setInputFile($tmp);
     $GLOBALS['ilLog']->write(__METHOD__ . ': Using ' . $tmp);
     try {
         $import->import();
     } catch (ilDidacticTemplateImportException $e) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Import failed with message: ' . $e->getMessage());
         ilUtil::sendFailure($this->lng->txt('didactic_import_failed') . ': ' . $e->getMessage());
     }
     ilUtil::sendSuccess($this->lng->txt('didactic_import_success'), TRUE);
     $ilCtrl->redirect($this, 'overview');
 }