/** * @author Matthew McNaney <mcnaney at gmail dot com> * @version $Id$ */ function filecabinet_document($file_type = null, $file_id = null) { if (empty($file_type) || empty($file_id)) { return null; } if ($file_type == 'doc') { PHPWS_Core::initModClass('filecabinet', 'Document.php'); $document = new PHPWS_Document((int) $file_id); if (empty($document->id)) { $document->logErrors(); return NULL; } return $document->getViewLink(TRUE); } elseif ($file_type == 'image') { PHPWS_Core::initModClass('filecabinet', 'Image.php'); $image = new PHPWS_Image((int) $file_id); if (empty($image->id)) { $image->logErrors(); return NULL; } return $image->getTag(); } elseif ($file_type == 'mm' || $file_type == 'media') { PHPWS_Core::initModClass('filecabinet', 'Multimedia.php'); $multimedia = new PHPWS_Multimedia((int) $file_id); if (empty($multimedia->id)) { $multimedia->logErrors(); return NULL; } return $multimedia->getTag(); } }
/** * Delete row from database that matches this object's $id. * Also, delete the associated document in filecabinet. */ public function delete() { \PHPWS_Core::initModClass('filecabinet', 'Document.php'); \PHPWS_DB::begin(); $db = self::getDb(); $db->addWhere('id', $this->id); $result = $db->delete(); if (\PHPWS_Error::logIfError($result)) { \PHPWS_DB::rollback(); return FALSE; } $doc = new \PHPWS_Document($this->document_fc_id); $result = $doc->delete(); if (\PHPWS_Error::logIfError($result)) { \PHPWS_DB::rollback(); return FALSE; } \PHPWS_DB::commit(); return TRUE; }
public function download($document_id) { require_once 'HTTP/Download.php'; PHPWS_Core::initModClass('filecabinet', 'Document.php'); $document = new PHPWS_Document($document_id); if (empty($document->id)) { $message = 'Document id:' . $document_id; if (!empty($_SERVER['HTTP_REFERER'])) { $message .= ' request from ' . $_SERVER['HTTP_REFERER']; } PHPWS_Error::log(FC_DOCUMENT_NOT_FOUND, 'filecabinet', 'Cabinet_Action::download', $message); Error::errorPage('404'); } $folder = new Folder($document->folder_id); if (!$folder->allow()) { $content = dgettext('filecabinet', 'Sorry, the file you requested is off limits.'); Layout::add($content); return; } $file_path = $document->getPath(); if (!is_file($file_path)) { $message = $file_path; if (!empty($_SERVER['HTTP_REFERER'])) { $message .= ' request from ' . $_SERVER['HTTP_REFERER']; } PHPWS_Error::log(FC_DOCUMENT_NOT_FOUND, 'filecabinet', 'Cabinet_Action::download', $message); Error::errorPage('404'); } $file_name = preg_replace('/[^\\w]/', '-', $document->getTitle()); $file_name = preg_replace('/-{2,}/', '-', $file_name); $file_name = preg_replace('/-$/', '', $file_name); $file_name .= '.' . $document->getExtension(); $document->downloaded++; $document->save(); $dl = new HTTP_Download(); $dl->setFile($file_path); $dl->setCache(true); $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $file_name); $dl->setContentType($document->file_type); $dl->send(); exit; }
private function saveFile(\Request $request) { switch ($request->getVar('ftype')) { case DOCUMENT_FOLDER: PHPWS_Core::initModClass('filecabinet', 'Document.php'); $doc = new PHPWS_Document($request->getVar('file_id')); $doc->setTitle($request->getVar('title')); $doc->save(false); break; case IMAGE_FOLDER: PHPWS_Core::initModClass('filecabinet', 'Image.php'); $img = new PHPWS_Image($request->getVar('file_id')); $img->setTitle($request->getVar('title')); $img->save(false, false, false); break; case MULTIMEDIA_FOLDER: PHPWS_Core::initModClass('filecabinet', 'Multimedia.php'); $mm = new PHPWS_Multimedia($request->getVar('file_id')); $mm->setTitle($request->getVar('title')); $mm->save(false, false); break; } }
public function allowDocumentType($type) { $document = new PHPWS_Document(); return $document->allowType($type); }