50 $xml =
"\n<DocumentMap>";
53 $xml .=
"</DocumentMap>";
58 function import($doc,
$tx)
85 if ($this->library->document_library_id)
87 $this->documents =
$library->Documents(
"ORDER BY title");
91 $this->documents = array();
101 if (strpos(
$folder,
"Board Members Only") !== FALSE && (!checkRole(
"board,admin,super") && !$this->library->allowManageFiles()))
106 trace(
"folderPermission: $folder ($permission)", 3);
117 <div
class=
"dialog" id=
"documentManagerDlg" style=
"width: 760px">
118 <div
class=
"dialog_header" id=
"documentManagerDlgHeader">
119 <div
style=
"padding: 4px;">
120 <div
style=
"float: right">&
nbsp;<a
id=
'closeDocumentManagerDlg' href=
"javascript:docManagerDlg.hide();">Close ×</a></div>
121 <span
style=
"font-weight: bold" id=
"documentManagerTitle">
Document Manager</span>
124 <div
id=
"documentManagerDlgBody" class=
"dialog_body">
128 $dialogs .= ob_get_contents();
133 <script type=
"text/javascript">
135 window.addEvent(
'domready',
function()
137 docManagerDlg =
new ModalDialog(document.id(
'documentManagerDlg'), {handle: document.id(
'documentManagerDlgHeader'), draggable: true, body: document.id(
'documentManagerDlgBody')});
140 function downloadFile()
142 id = document.id(
'files_value').value;
143 go(
"/action/document/download?document_id=" +
id);
148 id = document.id(
'files_value').value;
149 docManagerDlg.show(
function() {},
"/action/document/edit?document_id=" +
id);
152 function editResult(result)
156 docManagerDlg.hide();
160 document.id(
'Document_form__error').set({
'text': result,
'display':
'table-cell'});
167 id = document.id(
'files_value').value;
168 docManagerDlg.show(
function() {},
"/action/document/upload?document_library_id=<?echo $this->library->document_library_id?>");
171 function uploadResult(responseText)
173 if (responseText ==
"1")
175 window.location.reload();
183 function deleteFile()
185 if (confirm(
"Are you sure you want to delete this file?"))
187 id = document.id(
'files_value').value;
189 var request =
new Request({
'url':
'/action/document/delete?document_id=' +
id,
191 'onSuccess':
function(responseText)
193 if (responseText ==
"1")
195 window.location.reload();
202 'onFailure':
function() { alert(
"Failed to communicate with server");}});
208 function selectionChanged()
210 var
id = document.id(
'files_value').value;
214 document.id(
'download').removeProperty(
"disabled");
215 if(document.id(
'edit')) document.id(
'edit').removeProperty(
"disabled");
216 document.id(
'deleteButton').removeProperty(
"disabled");
221 document.id(
'download').addProperty(
"disabled",
"disabled");
222 if(document.id(
'edit')) document.id(
'edit').addProperty(
"disabled",
"disabled");
223 document.id(
'deleteButton').addProperty(
"disabled",
"disabled");
227 function rescanLibrary()
229 result = httpRequest(
"/action/document/rescan?document_library_id=<?echo $this->library->document_library_id?>");
232 window.location.reload();
241 if (checkRole($this->library->manage_folders) || $this->library->allowManageFiles())
244 function createFolder()
246 docManagerDlg.show(
function() {},
"/action/document/create_folder?document_library_id=<?echo $this->library->document_library_id?>");
249 function createFolderResult(result)
253 window.location.reload();
263 docManagerDlg.show(
function() {},
"/action/document/delete_folder?document_library_id=<?echo $this->library->document_library_id?>");
266 function deleteFolderResult(result)
270 window.location.reload();
292 $tree =
new DirectoryTreeControl(
"files");
295 $tree->onSelectionChanged =
"selectionChanged";
296 $tree->onDoubleClick =
"downloadFile";
298 $tree->selectMode =
"file";
301 $root = $this->library->getLibraryDirectory();
305 foreach($this->documents as $doc)
308 if (!checkRole($doc->allow_access))
continue;
310 $file = str_replace(
"/", DIRECTORY_SEPARATOR, $doc->file);
311 $file = str_replace(
"\\", DIRECTORY_SEPARATOR,
$file);
314 $folderNode =
$tree->findFolder(dirname(
$file));
316 if ($folderNode !=
null)
318 trace(
"Found Folder {$folderNode->id}", 4);
319 $id = str_replace(DIRECTORY_SEPARATOR,
"_",
$file);
321 $folderNode->add(
new FileNode(
$id, basename(
$file), $doc->document_id));
325 trace(
"*** NODE NOT FOUND - $file", 3);
329 $tree->children[
"documents"]->open =
true;
331 $page->page_title =
"Documents";
342 <button
id=
"download" class=
"button" disabled=
"disabled" onclick=
"downloadFile()"> Download File </button>&
nbsp;&
nbsp;
344 if (checkRole($this->library->upload_files))
347 <button
id=
"edit" class=
"button" disabled=
"disabled" onclick=
"editFile()">Edit Details...</button>&
nbsp;&
nbsp;
348 <button
id=
"upload" class=
"button" onclick=
"uploadFile()">Upload a File...</button>
352 if (checkRole($this->library->delete_files))
355 <button
id=
"deleteButton" class=
"button" disabled=
"disabled" onclick=
"deleteFile()">Delete File</button>&
nbsp;&
nbsp;
359 if (checkRole($this->library->manage_folders))
362 &
nbsp;&
nbsp;<button
id=
"createFolder" class=
"button" onclick=
"createFolder()">Create Folder...</button>&
nbsp;&
nbsp;
363 <button
id=
"deleteFolder" class=
"button" onclick=
"deleteFolder()">Delete Folder</button>&
nbsp;&
nbsp;
367 if (checkRole(
"admin"))
370 <button
id=
"rescan" class=
"button" onclick=
"rescanLibrary()">Rescan</button>
387 trace(
"Component document is deleting objects dependent on user_id {$user_id}", 3);
389 $tx =
new DataTransaction();
403 $mgr->deleteDocumentLibrary();
409 $document->delete(
"WHERE owner_id={$user_id}");
412 $download->joinTransaction(
$tx);
413 $download->delete(
"WHERE user_id={$user_id}");
440 if ($_FILES[
$field][
"name"]==
"")
454 $base = $this->library->getLibraryDirectory();
456 $fullpath =
$dir . DIRECTORY_SEPARATOR .
$name;
458 trace(
"Upload Directory: {$dir}", 3);
460 trace(
"Uploading file to $fullpath", 3);
462 if (!file_exists(
$dir))
468 if (file_exists($fullpath))
474 move_uploaded_file($_FILES[
$field][
"tmp_name"], $fullpath);
475 chmod($fullpath, 0755);
477 return str_replace(DIRECTORY_SEPARATOR,
"/",
$filepath);
487 $fullPath = $this->library->getLibraryDirectory() . DIRECTORY_SEPARATOR .
$document->file;
488 if (file_exists($fullPath))
503 $path = $this->library->getLibraryDirectory() . DIRECTORY_SEPARATOR .
$folder;
505 if (file_exists(
$path))
514 $tree =
new DirectoryTreeControl(
"files");
517 $tree->onSelectionChanged = $selectionChanged;
518 $tree->onDoubleClick = $doubleClick;
520 $tree->selectMode =
"file";
523 if ($this->documents)
525 $root = $this->library->getLibraryDirectory();
529 foreach($this->documents as $doc)
531 $file = str_replace(
"/", DIRECTORY_SEPARATOR, $doc->file);
532 $file = str_replace(
"\\", DIRECTORY_SEPARATOR,
$file);
535 $folderNode =
$tree->findFolder(dirname(
$file));
537 if ($folderNode !=
null)
539 trace(
"Found Folder {$folderNode->id} for document {$doc->document_id}", 4);
540 $id = str_replace(DIRECTORY_SEPARATOR,
"_",
$file);
541 $fileNode =
new FileNode(
$id, basename(
$file), $doc->document_id);
543 $folderNode->add($fileNode);
547 trace(
"*** NODE NOT FOUND - $file", 3);
551 $tree->children[
"documents"]->open =
true;
557 <div
style=
"width: <?echo $width?>px;height:<?echo $height?>px;border: solid 1px #000;">&
nbsp;</div>
589 if (!checkRole(
$page->role))
595 echo $pageView->drawView();
599 catch(DataNotFoundException $e)
618 $library->allow_access = $defaultRole;
619 $library->manage_folders = $defaultRole;
620 $library->upload_files = $defaultRole;
621 $library->delete_files = $defaultRole;
625 $library->filter =
new InclusionFilter(
"document_library_id",
"name",
626 "identifier",
"description",
"owner_id",
"last_modified",
627 "allow_access",
"manage_folders",
"upload_files",
"delete_files",
"create_date");
634 $d =
$form->data->getLibraryDirectory();
646 $folders = $this->library->Folders();
647 if(count($folders) > 0)
655 $fileshareUsers = $this->library->FileshareUsers();
656 if(count($fileshareUsers) > 0)
658 foreach($fileshareUsers as $f_user)
662 $this->library->delete();
670 $roleFields = array(
"upload_files",
"delete_files",
"manage_folders",
"allow_access");
671 foreach($roleFields as
$field)
683 "Details" =>
"document_library_form",
684 "Files" =>
"document_library_files"
687 $qs = ($key) ?
"document_library_id=$key" :
"";
688 return new TabBar(
"tabs",
$tabs,
$qs);
694 $form->hide(
"owner_id",
"allow_access",
"manage_folders",
"upload_files",
"delete_files",
"create_date");
695 $form->required(
"name",
"identifier");
696 $form->annotate(
"allow_comments",
"Allow users to comment on documents from the document details page (if commenting is enabled).");
698 $form->allowDelete =
true;
715 $size =
"($file_size)";
718 return $document->format(
"<a style='display: inline' id='document_id_{document_id}' href='#' ondblclick=\"new LinkPicker().documentPickerInsertLink({document_id})\" onclick=\"new LinkPicker().toggleDocumentSelected(this, {document_id}); return false;\">{title}</a> <img style='display:inline; vertical-align: middle' src='$icon' alt='$type'/> $size");
725 $img = DocumentHandler::getDocIcon(
$document->file);
727 return "<img src='$img' alt='' style='display: inline-block; vertical-align: middle'> ".
728 "<a href='/action/document/download?document_id={$document->document_id}'>{$document->title}</a> $size";
733 $styles .=
"<link href=\"/fakoli/css/tabs.css\" rel=\"stylesheet\"/>\n";
740 $this->indexedDocuments = reindexList($this->documents,
"file");
741 $this->indexedFolders = IndexedQuery::create(
DocumentFolder,
"WHERE document_library_id=:id",
"path")
742 ->bind(
":id", $this->library->document_library_id)
752 $base = sanitizePath($this->library->getLibraryDirectory() . DIRECTORY_SEPARATOR .
$path);
754 $files = scandir(
$base);
755 foreach($files as
$file)
761 if (is_dir(
$base . DIRECTORY_SEPARATOR .
$file))
767 if ($this->indexedDocuments[
$f])
continue;
775 $doc->document_library_id = $this->library->document_library_id;
776 $doc->owner_id =
$user->get(
$user->getPrimaryKey());
784 $this->indexedDocuments = reindexList($this->documents,
"file");
786 $fp = fopen(
$file,
"r");
788 $fields = fgetcsv($fp);
792 foreach($fields as
$field)
808 while($values = fgetcsv($fp))
810 $files = explode(
";", $values[$fileIdx]);
811 foreach($files as
$f)
817 foreach($this->indexedDocuments as
$path => $doc)
823 foreach($fields as
$field)
831 $doc->set(
$field, $values[$i]);
855 $process->setProgress(
"Running",
"Scanning files", 0);
858 $files =
$library->Documents(
"ORDER BY file");
860 $libraryFileName =
$library->format(
"library_{document_library_id}.zip");
861 $libraryDir =
$library->getLibraryDirectory();
862 $libraryZipFile =
$config[
'uploadbase'] . DIRECTORY_SEPARATOR . $libraryFileName;
863 if (file_exists($libraryZipFile))
865 unlink($libraryZipFile);
869 $zip =
new ZipArchive();
872 if ($zip->open($libraryZipFile, ZIPARCHIVE::CREATE) !== TRUE)
876 $process->setProgress(
"Error",
"Could not create ZIP archive");
881 $max = count($files);
884 foreach($files as
$file)
886 $fullPath = $libraryDir . DIRECTORY_SEPARATOR .
$file->file;
887 $zip->addFile($fullPath,
$file->file);
891 $process->setProgress(
"Running",
"Added $c of $max ".pluralize(
"file",
$max), number_format(100 *
$c /
$max, 0));
899 $process->setProgress(
"Completed",
"Zip archive created", 100);
910 $roles[
"visitor"] =
"Visitor";
917 return implode(
",", array_keys(
$roles));
925 $max = ini_get(
"upload_max_filesize");
927 if (endsWith(
$max,
"M"))
931 else if (endsWith(
$max,
"K"))
935 else if (endsWidth(
$max,
"G"))
937 $max *= 1024 * 1024 * 1024;
940 $postMax = ini_get(
"post_max_size");
942 if (endsWith($postMax,
"M"))
944 $postMax *= 1024 * 1024;
946 else if (endsWith($postMax,
"K"))
950 else if (endsWidth($postMax,
"G"))
952 $postMax *= 1024 * 1024 * 1024;
955 return min(
$max, $postMax);
968 trace(
"DocumentManager registerSearchables", 3);
971 $searchables[
"document"] = array(
Document);
984 $mgr->upgrade($version);
1006 Settings::setDefaultValue(
"document",
"show_upload_details",
true, Boolean,
"Include upload details on the document library view");
1007 Settings::setDefaultValue(
"document",
"link_to_details",
false, Boolean,
"Link to the document details page for each document from the library view");
1008 Settings::setDefaultValue(
"document",
"show_table_filter",
false, Boolean,
"Show the generic column filter controls for the document table view");
1009 Settings::setDefaultValue(
"document",
"always_display_PDFs_in_browser",
false, Boolean,
"When downloading PDF documents, have them display in the browser in a new tab, rather than as a file download");
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
This class maps the publication table.
static findByIdentifier($identifier)
static getDefaultRole($fileshare=false)
The DocumentManager class provides the core API and management functions for uploading documents and ...
static upgradeComponent($version)
static registerSerializationHandler()
static registerCommentAdapter()
static createLibraryObj()
static enumerateItems($items)
Enumerate the Document objects.
static documentLibraryTabs($key)
static registerTaxonomyClasses($classes)
static registerSearchables($searchables)
static registerSolrAdapter()
DocumentManager($library)
Creates a new DocumentManager for the specified library.
deleteDocument($document)
Delete the specified document (assuming the user has permission).
uploadFile($field, $folder)
Upload a file from the specified form field to the specified folder within the current document libra...
folderPermission($folder)
static formatDocumentLink($document)
formatLinkPickerTitle($document)
static getMaxUploadBytes()
Calculate the maximum allowed file upload size in bytes.
static buildDocumentLibraryForm($library)
static deleteRole($del_role)
static createLibrary($form)
static zipLibrary($library_id, $process=null)
Generate a ZIP archive of all the documents in the specified library.
static displayLibrary($identifier, &$continue)
static deleteUser($user)
Respond to fired event DeleteUser.
drawSelectView($selectionChanged="", $doubleClick="", $width=700, $height=400)
static getMaxUploadSize()
Returns the maximum allowed file upload size in human-readable format.
DocumentSerializationHandler()
FakoliException is the base exception class for all Fakoli errors.
static usingFile()
Uses the specified framework file(s) from the framework directory.
static assertRole($role, $redirect="", $message="")
Assert that the user has one of the specified roles.
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
static deleteRoleFromString(&$items, $del_role, $field="")
static serialize($class, $constraint="")
Serializes the specified DataItems to XML.
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
static unserialize($class, $doc, $tx, $save=true)
Instantiates DataItems from the supplied XML document and stores them in the database.
static getValue($component, $name)
Retrieve the value of the specified Setting.
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
static getRolesArray()
Retrieves the array of roles and their names for the current site for use in a CMS form.
if(!checkRole("admin")) $c
if(! $document_id) $document
if(!checkRole($library->allow_access) &&! $library->allowAccess()) if(!checkRole($document->allow_access)) $d