예제 #1
0
 /**
  * Processes data via HTTP POST. Reads php://input and creates a temporary image out of it.
  */
 public function uploadCam()
 {
     $tempFile = tempnam("/tmp", "PWC") . ".jpg";
     $result = file_put_contents($tempFile, file_get_contents('php://input'));
     $image = new TempUploadedFile();
     $image->replace($tempFile);
     $image->setOriginalFilename(sprintf(PartKeepr::i18n("Cam photo of %s"), date("Y-m-d H:i:s")) . ".jpg");
     PartKeepr::getEM()->persist($image);
     PartKeepr::getEM()->flush();
     return array("id" => $image->getId(), "extension" => $image->getExtension(), "size" => $image->getSize(), "originalFilename" => $image->getOriginalFilename());
 }
예제 #2
0
 /**
  * Prints the selected storage locations to a dedicated file
  * and returns the url to this file.
  */
 public function startExport()
 {
     $this->requireParameter("ids");
     $this->requireParameter("configuration");
     $this->requireParameter("objectType");
     $ids = explode(',', $this->getParameter("ids"));
     $configurationId = $this->getParameter("configuration");
     $objectType = $this->getParameter("objectType");
     $printerUser = null;
     if ($this->hasParameter("target") && $this->getParameter("target") != "") {
         $printerUser = UserManager::getInstance()->getUser($this->getParameter("target"));
     }
     // check object type for valid object types for security reasons.
     // See Select query below and be aware of SQL injection!
     if (!array_key_exists($objectType, $this->availableObjectTypes)) {
         throw new RendererNotFoundException("Object type is forbidden!", $objectType, array_keys($this->availableObjectTypes));
     }
     $configuration = PrintingJobConfigurationManager::getInstance()->getEntity($configurationId);
     $query = PartKeepr::getEM()->createQuery("SELECT s FROM {$objectType} s WHERE s.id IN (?1)");
     $query->setParameter(1, $ids);
     $dataToRender = $query->getResult();
     $renderingObjects = array();
     if ($configuration->getPageLayout() !== null) {
         $renderingObjects[] = $configuration->getPageLayout();
     }
     $renderer = RendererFactoryRegistry::getInstance()->getRendererFactory($configuration->getExportRenderer())->createInstance($renderingObjects, $configuration->getRendererConfiguration());
     $renderer->passRenderingData($dataToRender);
     $tempFile = tempnam("/tmp", "PWC");
     $renderer->storeResult($tempFile);
     $tmpFile = new TempUploadedFile();
     $tmpFile->replace($tempFile);
     $tmpFile->setOriginalFilename("generatedFile." . $renderer->getSuggestedExtension());
     PartKeepr::getEM()->persist($tmpFile);
     PartKeepr::getEM()->flush();
     //Create a job if we have a valid printer target
     if ($printerUser !== null) {
         $job = new PrintingJob();
         $job->setData($tmpFile);
         $job->setTarget($printerUser);
         PartKeepr::getEM()->persist($job);
         PartKeepr::getEM()->flush();
     }
     return array("fileid" => $tmpFile->getId());
 }
 /**
  * (non-PHPdoc)
  * @see PartKeepr\Service.RestfulService::create()
  */
 public function create()
 {
     $this->requireParameter("tmp_id");
     $this->requireParameter("project_id");
     $tmpImage = TempUploadedFile::loadById($this->getParameter("tmp_id"));
     $file = new ProjectAttachment();
     $project = Project::loadById($this->getParameter("project_id"));
     $file->setProject($project);
     $file->replace($tmpImage->getFilename());
     $file->setOriginalFilename($tmpImage->getOriginalFilename());
     $file->setDescription($this->getParameter("description"));
     PartKeepr::getEM()->persist($file);
     PartKeepr::getEM()->flush();
     return $file->serialize();
 }
예제 #4
0
            case "Print":
                $file = TempUploadedFile::loadById($id);
                break;
            default:
                $file = null;
                // Add default image?
        }
    } catch (\Exception $e) {
        $file = null;
        // Something bad happened
    }
}
if ($file == null) {
    // Could not find the image, but maybe we want a temporary image?
    if (array_key_exists("tmpId", $_REQUEST)) {
        $file = TempUploadedFile::loadById($_REQUEST["tmpId"]);
    }
}
if (is_object($file)) {
    header("Content-Type: " . $file->getMimeType());
    if (array_key_exists("download", $_REQUEST) && $_REQUEST["download"] == "true") {
        header("Content-Description: File Transfer");
        header('Content-Disposition: attachment; filename="' . basename($file->getOriginalFilename()) . '"');
    } else {
        header('Content-Disposition: inline; filename="' . basename($file->getOriginalFilename()) . '"');
    }
    $fp = fopen($file->getFilename(), "rb");
    fpassthru($fp);
    fclose($fp);
} else {
    echo "404 not found";
예제 #5
0
 private function processAttachmentChanges(Part $part, array $data)
 {
     if (array_key_exists("updates", $data)) {
         foreach ($data["updates"] as $record) {
             foreach ($part->getAttachments() as $partAttachment) {
                 if ($partAttachment->getId() == $record["id"]) {
                     $partAttachment->setDescription($record["description"]);
                     break;
                 }
             }
         }
     }
     if (array_key_exists("removals", $data)) {
         foreach ($data["removals"] as $record) {
             foreach ($part->getAttachments() as $partAttachment) {
                 if ($partAttachment->getId() == $record["id"]) {
                     PartKeepr::getEM()->remove($partAttachment);
                     $part->getAttachments()->removeElement($partAttachment);
                     break;
                 }
             }
         }
     }
     if (array_key_exists("inserts", $data)) {
         foreach ($data["inserts"] as $record) {
             $attachment = new PartAttachment();
             $attachment->setPart($part);
             $attachment->setDescription($record["description"]);
             $file = TempUploadedFile::loadById($record["tmp_id"]);
             $attachment->replace($file->getFilename());
             $attachment->setOriginalFilename($file->getOriginalFilename());
             $part->getAttachments()->add($attachment);
         }
     }
 }
예제 #6
0
 /**
  * Replaces the file with a given temporary file.
  * @param string $id The temporary id (prefixed with TMP:)
  */
 public function replaceFromTemporaryFile($id)
 {
     if (substr($id, 0, 4) === "TMP:") {
         $tmpFileId = str_replace("TMP:", "", $id);
         $tmpFile = TempUploadedFile::loadById($tmpFileId);
         $this->replace($tmpFile->getFilename());
         $this->setOriginalFilename($tmpFile->getOriginalFilename());
     }
 }