/** * private functions which iterates through all folders and files * and create an according file structure in a temporary directory. This function works recursive. * * @param integer $refid reference it * @param tmpdictory $tmpdir * @return returns first created directory */ private static function recurseFolder($refid, $title, $tmpdir) { global $rbacsystem, $tree, $ilAccess; $tmpdir = $tmpdir . DIRECTORY_SEPARATOR . ilUtil::getASCIIFilename($title); ilUtil::makeDir($tmpdir); $subtree = $tree->getChildsByTypeFilter($refid, array("fold", "file")); foreach ($subtree as $child) { if (!$ilAccess->checkAccess("read", "", $child["ref_id"])) { continue; } if (ilObject::_isInTrash($child["ref_id"])) { continue; } if ($child["type"] == "fold") { ilObjFolder::recurseFolder($child["ref_id"], $child["title"], $tmpdir); } else { $newFilename = $tmpdir . DIRECTORY_SEPARATOR . ilUtil::getASCIIFilename($child["title"]); // copy to temporal directory $oldFilename = ilObjFile::_lookupAbsolutePath($child["obj_id"]); if (!copy($oldFilename, $newFilename)) { throw new ilFileException("Could not copy " . $oldFilename . " to " . $newFilename); } touch($newFilename, filectime($oldFilename)); } } }
/** * Imports rooms and bookings from a given daVinci file * * @param type $file daVinci text file from file upload form * @param boolean $import_rooms true to import rooms * @param boolean $import_bookings true to import bookings * @param int $default_cap sets the default room capacity */ public function importBookingsFromDaVinciFile($file, $import_rooms, $import_bookings, $default_cap) { $this->count_Bookings_without_Room = 0; $this->count_Rooms_created = 0; $this->count_Bookings_created = 0; $file_name = ilUtil::getASCIIFilename($file["name"]); $file_name_mod = str_replace(" ", "_", $file_name); $file_path = "templates" . "/" . $file_name_mod; // construct file path ilUtil::moveUploadedFile($file["tmp_name"], $file_name_mod, $file_path); $fileAsString = file_get_contents($file_path); ilUtil::sendInfo($this->lng->txt("rep_robj_xrs_daVinci_import_message_start"), true); foreach (preg_split("/((\r?\n)|(\r\n?))/", $fileAsString) as $line) { $this->checkForKey($line); } ilUtil::sendInfo($this->createInfoMessage($import_rooms, $import_bookings), true); if ($import_rooms === "1") { foreach ($this->rooms as $room) { if (!($this->ilRoomSharingDatabase->getRoomWithName($room['name']) !== array())) { if ($room['cap'] == 0) { $room['cap'] = (int) $default_cap; } //$a_name, $a_type, $a_min_alloc, $a_max_alloc, $a_file_id, $a_building_id $this->ilRoomSharingDatabase->insertRoom($room['name'], $room['type'], 1, $room['cap'], array(), array()); $this->count_Rooms_created++; } } } if ($import_bookings === "1") { foreach ($this->appointments as $booking) { if ($booking['day'] != 0) { $usedWeek = clone $this->startingDate; for ($i = 0; $i < strlen($this->activeWeeks); $i++) { if ($booking['week'] != NULL) { if ($booking['week'][$i] === 'X') { $this->addDaVinciBooking($booking['day'], $booking['start'], $booking['end'], $booking['room'], $booking['prof'], $booking['subject'], $booking['classes'], $usedWeek); } } else { if ($this->activeWeeks[$i] === 'X') { $this->addDaVinciBooking($booking['day'], $booking['start'], $booking['end'], $booking['room'], $booking['prof'], $booking['subject'], $booking['classes'], $usedWeek); } } $usedWeek->add(new DateInterval('P7D')); } } } } $this->displayInfo(); }
/** * 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); }
/** * Fix filename of uploaded file * * @param string $a_name upload file name * @return string fixed file name */ static function fixFilename($a_name) { $a_name = ilUtil::getASCIIFilename($a_name); $rchars = array("`", "=", "\$", "{", "}", "'", ";", " ", "(", ")"); $a_name = str_replace($rchars, "_", $a_name); $a_name = str_replace("__", "_", $a_name); return $a_name; }
/** * update media item from form * * @param IlObjectMediaObject $mob * @param IlMediaItem $mediaItem * @return string file */ private function updateMediaItem($mob, &$mediaItem) { $purpose = $mediaItem->getPurpose(); $url_gui = $this->form_gui->getInput("url_" . $purpose); $file_gui = $this->form_gui->getInput("file_" . $purpose); if ($url_gui) { // http $file = $this->form_gui->getInput("url_" . $purpose); $title = basename($file); $location = $this->form_gui->getInput("url_" . $purpose); $locationType = "Reference"; } elseif ($file_gui["size"] > 0) { // lokal // determine and create mob directory, move uploaded file to directory $mob_dir = ilObjMediaObject::_getDirectory($mob->getId()); if (!is_dir($mob_dir)) { $mob->createDirectory(); } $file_name = ilUtil::getASCIIFilename($_FILES['file_' . $purpose]['name']); $file_name = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name; $title = $file_name; $locationType = "LocalFile"; $location = $title; ilUtil::moveUploadedFile($_FILES['file_' . $purpose]['tmp_name'], $file_name, $file); ilUtil::renameExecutables($mob_dir); } // check if not automatic mimetype detection if ($_POST["mimetype_" . $purpose] != "") { $mediaItem->setFormat($_POST["mimetype_" . $purpose]); } elseif ($mediaItem->getLocation() != "") { $format = ilObjMediaObject::getMimeType($mediaItem->getLocation()); $mediaItem->setFormat($format); } if (isset($file)) { // get mime type, if not already set! if (!isset($format)) { $format = ilObjMediaObject::getMimeType($file); } // set real meta and object data $mediaItem->setFormat($format); $mediaItem->setLocation($location); $mediaItem->setLocationType($locationType); $mediaItem->setHAlign("Left"); $mediaItem->setHeight(self::isAudio($format) ? 0 : 180); } if ($purpose == "Standard") { if (isset($title)) { $mob->setTitle($title); } if (isset($format)) { $mob->setDescription($format); } } return $file; }
/** * Uploads a new rooms agreement by using the ILIAS MediaObject Service. * If the old file id is given, the old file will be deleted. * * @param array $a_newfile an array containing the input values of the form * @param string $a_oldFileId to delete trash * * @return string uploaded file id */ public function uploadRoomsAgreement($a_newfile, $a_oldFileId = "0") { if (!empty($a_oldFileId) && $a_oldFileId != "0") { $agreementFile = new ilObjMediaObject($a_oldFileId); $agreementFile->delete(); } $mediaObj = new ilObjMediaObject(); $mediaObj->setTitle("RoomSharingRoomsAgreement"); $mediaObj->setDescription("RoomSharingRoomsAgreement"); $mediaObj->create(); $mob_dir = ilObjMediaObject::_getDirectory($mediaObj->getId()); if (!is_dir($mob_dir)) { $mediaObj->createDirectory(); } $file_name = ilUtil::getASCIIFilename($a_newfile["name"]); $file_name_mod = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name_mod; ilUtil::moveUploadedFile($a_newfile["tmp_name"], $file_name_mod, $file); ilUtil::renameExecutables($mob_dir); $format = ilObjMediaObject::getMimeType($file); $media_item = new ilMediaItem(); $mediaObj->addMediaItem($media_item); $media_item->setPurpose("Standard"); $media_item->setFormat($format); $media_item->setLocation($file_name_mod); $media_item->setLocationType("LocalFile"); $mediaObj->update(); return $mediaObj->getId(); }
/** * Configures the file for the updateFloorPlanInfosWithFile and addFloorPlan function. * * @param ilObjMediaObject $a_mediaObj * @param array $a_newfile * * @return array with format and filename */ private function configureFile($a_mediaObj, $a_newfile = NULL) { if ($this->mobjMock) { return $a_newfile; } $mob_dir = ilObjMediaObject::_getDirectory($a_mediaObj->getId()); if (!is_dir($mob_dir)) { $a_mediaObj->createDirectory(); } $file_name = ilUtil::getASCIIFilename($a_newfile["name"]); $file_name_mod = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name_mod; // construct file path ilUtil::moveUploadedFile($a_newfile["tmp_name"], $file_name_mod, $file); ilUtil::renameExecutables($mob_dir); $format = ilObjMediaObject::getMimeType($file); return array("format" => $format, "filename" => $file_name_mod); }
public function downloadFolderObject() { global $ilAccess, $ilErr, $lng; if (!$ilAccess->checkAccess("read", "", $this->ref_id)) { $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"), $this->ilias->error_obj->MESSAGE); } $filename = $this->object->downloadFolder(); ilUtil::deliverFile($filename, ilUtil::getASCIIFilename($this->object->getTitle() . ".zip")); }
/** * 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); */ }
/** * deliver file for download via browser. * @param $mime Mime of the file * @param $isInline Set this to true, if the file shall be shown in browser * @static * */ public static function deliverFile($a_file, $a_filename, $a_mime = '', $isInline = false, $removeAfterDelivery = false, $a_exit_after = true) { // should we fail silently? if (!file_exists($a_file)) { return false; } if ($isInline) { $disposition = "inline"; // "inline" to view file in browser } else { $disposition = "attachment"; // "attachment" to download to hard disk //$a_mime = "application/octet-stream"; // override mime type to ensure that no browser tries to show the file anyway. } // END WebDAV: Show file in browser or provide it as attachment if (strlen($a_mime)) { $mime = $a_mime; } else { $mime = "application/octet-stream"; // or whatever the mime type is } // BEGIN WebDAV: Removed broken HTTPS code. // END WebDAV: Removed broken HTTPS code. if ($disposition == "attachment") { header("Cache-control: private"); } else { header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); } $ascii_filename = ilUtil::getASCIIFilename($a_filename); header("Content-Type: {$mime}"); header("Content-Disposition:{$disposition}; filename=\"" . $ascii_filename . "\""); header("Content-Description: " . $ascii_filename); // #7271: if notice gets thrown download will fail in IE $filesize = @filesize($a_file); if ($filesize) { header("Content-Length: " . (string) $filesize); } include_once './Services/Http/classes/class.ilHTTPS.php'; #if($_SERVER['HTTPS']) if (ilHTTPS::getInstance()->isDetected()) { header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } header("Connection: close"); ilUtil::readFile($a_file); if ($removeAfterDelivery) { unlink($a_file); } if ($a_exit_after) { exit; } }
/** * Exports all survey codes */ public function exportAllCodesObject() { $export = $this->object->getSurveyCodesForExport(); ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".csv")); }
private static function copyFile($obj_id, $title, $tmpdir) { $newFilename = $tmpdir . DIRECTORY_SEPARATOR . ilUtil::getASCIIFilename($title); // copy to temporary directory $oldFilename = ilObjFile::_lookupAbsolutePath($obj_id); if (!copy($oldFilename, $newFilename)) { throw new ilFileException("Could not copy " . $oldFilename . " to " . $newFilename); } touch($newFilename, filectime($oldFilename)); }
public function getOfflineFilename() { return ilUtil::getASCIIFilename($this->getTitle()) . ".pdf"; }
/** * Exports the user results as PDF certificates using * XSL-FO via XML:RPC calls * * @access public */ public function exportCertificate() { global $ilUser; include_once "./Services/Utilities/classes/class.ilUtil.php"; include_once "./Services/Certificate/classes/class.ilCertificate.php"; include_once "./Modules/Test/classes/class.ilTestCertificateAdapter.php"; $certificate = new ilCertificate(new ilTestCertificateAdapter($this->object)); $archive_dir = $certificate->createArchiveDirectory(); $total_users = array(); $total_users =& $this->object->evalTotalPersonsArray(); if (count($total_users)) { foreach ($total_users as $active_id => $name) { $user_id = $this->object->_getUserIdFromActiveId($active_id); $pdf = $certificate->outCertificate(array("active_id" => $active_id, "userfilter" => $userfilter, "passedonly" => $passedonly), FALSE); if (strlen($pdf)) { $certificate->addPDFtoArchiveDirectory($pdf, $archive_dir, $user_id . "_" . str_replace(" ", "_", ilUtil::getASCIIFilename($name)) . ".pdf"); } } $zipArchive = $certificate->zipCertificatesInArchiveDirectory($archive_dir, TRUE); } }
/** * 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); }
/** * 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; } }
/** * Function to parse incoming data from form input value $value. returns the strin/number/etc. to store in the database. * @param $value * @param ilDataCollectionRecordField $record_field * @return int|string */ public function parseValue($value, ilDataCollectionRecordField $record_field) { $return = false; if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_FILE) { $file = $value; if ($file['tmp_name']) { $file_obj = new ilObjFile(); $file_obj->setType("file"); $file_obj->setTitle($file["name"]); $file_obj->setFileName($file["name"]); $file_obj->setFileType(ilMimeTypeUtil::getMimeType("", $file["name"], $file["type"])); $file_obj->setFileSize($file["size"]); $file_obj->setMode("object"); $file_obj->create(); $file_obj->getUploadFile($file["tmp_name"], $file["name"]); $file_id = $file_obj->getId(); $return = $file_id; } else { $return = $record_field->getValue(); } } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_MOB) { if ($value == -1) { //marked for deletion. return 0; } $media = $value; if ($media['tmp_name']) { $mob = new ilObjMediaObject(); $mob->setTitle($media['name']); $mob->create(); $mob_dir = ilObjMediaObject::_getDirectory($mob->getId()); if (!is_dir($mob_dir)) { $mob->createDirectory(); } $media_item = new ilMediaItem(); $mob->addMediaItem($media_item); $media_item->setPurpose("Standard"); $file_name = ilUtil::getASCIIFilename($media['name']); $file_name = str_replace(" ", "_", $file_name); $file = $mob_dir . "/" . $file_name; $title = $file_name; ilUtil::moveUploadedFile($media['tmp_name'], $file_name, $file); ilUtil::renameExecutables($mob_dir); list($width, $height, $type, $attr) = getimagesize($file); $arr_properties = $record_field->getField()->getProperties(); $new_width = $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH]; $new_height = $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]; if ($new_width || $new_height) { //only resize if it is bigger, not if it is smaller if ($new_height < $height && $new_width < $width) { //resize proportional if (!$new_height || !$new_width) { $format = ilObjMediaObject::getMimeType($file); $wh = ilObjMediaObject::_determineWidthHeight("", "", $format, "File", $file, "", true, false, $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH], (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]); } else { $wh['width'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH]; $wh['height'] = (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT]; } } $location = ilObjMediaObject::_resizeImage($file, $wh['width'], $wh['height'], false); } else { $location = $title; } ilObjMediaObject::_saveUsage($mob->getId(), "dcl:html", $record_field->getRecord()->getTable()->getCollectionObject()->getId()); $format = ilObjMediaObject::getMimeType($file); $media_item->setFormat($format); $media_item->setLocation($location); $media_item->setLocationType("LocalFile"); $mob->update(); $return = $mob->getId(); } else { $return = $record_field->getValue(); } } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) { return $value["date"] . " " . $value["time"]; } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) { $return = $value ? 1 : 0; } elseif ($this->id == ilDataCollectionDatatype::INPUTFORMAT_TEXT) { $arr_properties = $record_field->getField()->getProperties(); if ($arr_properties[ilDataCollectionField::PROPERTYID_TEXTAREA]) { $return = nl2br($value); } else { $return = $value; } } else { if ($this->id == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) { $return = $value == '' ? null : $value; //SW, Ilias Mantis #0011799: Return null otherwise '' is casted to 0 in DB } else { $return = $value; } } return $return; }
/** * Export file from path */ function exportHTMLFileDirect($a_file_id, $a_source_file, $a_file_name) { $file_dir = $this->files_dir . "/file_" . $a_file_id; ilUtil::makeDir($file_dir); if (is_file($a_source_file)) { copy($a_source_file, $file_dir . "/" . ilUtil::getASCIIFilename($a_file_name)); } }
/** * 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); }
/** * Exports the evaluation data to the CSV file format * * Exports the evaluation data to the CSV file format * * @param string $filtertext Filter text for the user data * @param boolean $passedonly TRUE if only passed user datasets should be exported, FALSE otherwise * @access public */ function exportToCSV($deliver = TRUE, $filterby = "", $filtertext = "", $passedonly = FALSE) { global $ilLog; if (strcmp($this->mode, "aggregated") == 0) { return $this->aggregatedResultsToCSV($deliver); } $rows = array(); $datarow = array(); $col = 1; if ($this->test_obj->getAnonymity()) { array_push($datarow, $this->lng->txt("counter")); $col++; } else { array_push($datarow, $this->lng->txt("name")); $col++; array_push($datarow, $this->lng->txt("login")); $col++; } $additionalFields = $this->test_obj->getEvaluationAdditionalFields(); if (count($additionalFields)) { foreach ($additionalFields as $fieldname) { array_push($datarow, $this->lng->txt($fieldname)); $col++; } } array_push($datarow, $this->lng->txt("tst_stat_result_resultspoints")); $col++; array_push($datarow, $this->lng->txt("maximum_points")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_resultsmarks")); $col++; if ($this->test_obj->getECTSOutput()) { array_push($datarow, $this->lng->txt("ects_grade")); $col++; } array_push($datarow, $this->lng->txt("tst_stat_result_qworkedthrough")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_qmax")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_pworkedthrough")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_timeofwork")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_atimeofwork")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_firstvisit")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_lastvisit")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_mark_median")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_rank_participant")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_rank_median")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_total_participants")); $col++; array_push($datarow, $this->lng->txt("tst_stat_result_median")); $col++; array_push($datarow, $this->lng->txt("scored_pass")); $col++; array_push($datarow, $this->lng->txt("pass")); $col++; $data =& $this->test_obj->getCompleteEvaluationData(TRUE, $filterby, $filtertext); $headerrow = $datarow; $counter = 1; foreach ($data->getParticipants() as $active_id => $userdata) { $datarow = $headerrow; $remove = FALSE; if ($passedonly) { if ($data->getParticipant($active_id)->getPassed() == FALSE) { $remove = TRUE; } } if (!$remove) { $datarow2 = array(); if ($this->test_obj->getAnonymity()) { array_push($datarow2, $counter); } else { array_push($datarow2, $data->getParticipant($active_id)->getName()); array_push($datarow2, $data->getParticipant($active_id)->getLogin()); } if (count($additionalFields)) { $userfields = ilObjUser::_lookupFields($userdata->getUserID()); foreach ($additionalFields as $fieldname) { if (strcmp($fieldname, "gender") == 0) { array_push($datarow2, $this->lng->txt("gender_" . $userfields[$fieldname])); } else { array_push($datarow2, $userfields[$fieldname]); } } } array_push($datarow2, $data->getParticipant($active_id)->getReached()); array_push($datarow2, $data->getParticipant($active_id)->getMaxpoints()); array_push($datarow2, $data->getParticipant($active_id)->getMark()); if ($this->test_obj->getECTSOutput()) { array_push($datarow2, $data->getParticipant($active_id)->getECTSMark()); } array_push($datarow2, $data->getParticipant($active_id)->getQuestionsWorkedThrough()); array_push($datarow2, $data->getParticipant($active_id)->getNumberOfQuestions()); array_push($datarow2, $data->getParticipant($active_id)->getQuestionsWorkedThroughInPercent() / 100.0); $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; array_push($datarow2, 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; array_push($datarow2, sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds)); $fv = $data->getParticipant($active_id)->getFirstVisit(); $lv = $data->getParticipant($active_id)->getLastVisit(); foreach (array($fv, $lv) as $ts) { if ($ts) { $visit = ilFormat::formatDate(date('Y-m-d H:i:s', $ts), "datetime", false, false); array_push($datarow2, $visit); } else { array_push($datarow2, ""); } } $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(); } array_push($datarow2, $mark_short_name); array_push($datarow2, $data->getStatistics()->getStatistics()->rank($data->getParticipant($active_id)->getReached())); array_push($datarow2, $data->getStatistics()->getStatistics()->rank_median()); array_push($datarow2, $data->getStatistics()->getStatistics()->count()); array_push($datarow2, $median); if ($this->test_obj->getPassScoring() == SCORE_BEST_PASS) { array_push($datarow2, $data->getParticipant($active_id)->getBestPass() + 1); } else { array_push($datarow2, $data->getParticipant($active_id)->getLastPass() + 1); } for ($pass = 0; $pass <= $data->getParticipant($active_id)->getLastPass(); $pass++) { $finishdate = $this->test_obj->getPassFinishDate($active_id, $pass); if ($finishdate > 0) { if ($pass > 0) { for ($i = 1; $i < $col - 1; $i++) { array_push($datarow2, ""); array_push($datarow, ""); } array_push($datarow, ""); } array_push($datarow2, $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"]); array_push($datarow2, $question_data["reached"]); array_push($datarow, preg_replace("/<.*?>/", "", $data->getQuestionTitle($question["id"]))); } } if ($this->test_obj->isRandomTest() || $this->test_obj->getShuffleQuestions() || $counter == 1 && $pass == 0) { array_push($rows, $datarow); } $datarow = array(); array_push($rows, $datarow2); $datarow2 = array(); } } $counter++; } } $csv = ""; $separator = ";"; foreach ($rows as $evalrow) { $csvrow =& $this->test_obj->processCSVRow($evalrow, TRUE, $separator); $csv .= join($csvrow, $separator) . "\n"; } if ($deliver) { ilUtil::deliverData($csv, ilUtil::getASCIIFilename($this->test_obj->getTitle() . "_results.csv")); exit; } else { return $csv; } }
/** * 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"); }