CMS  Version 3.9
DocumentManager Class Reference

The DocumentManager class provides the core API and management functions for uploading documents and managing document libraries. More...

+ Inheritance diagram for DocumentManager:

Public Member Functions

 DocumentManager ($library)
 Creates a new DocumentManager for the specified library. More...
 
 folderPermission ($folder)
 
 writeScript ()
 
 drawView ()
 
 drawButtons ()
 
 uploadFile ($field, $folder)
 Upload a file from the specified form field to the specified folder within the current document library. More...
 
 deleteDocument ($document)
 Delete the specified document (assuming the user has permission). More...
 
 deleteFolder ($folder)
 
 drawSelectView ($selectionChanged="", $doubleClick="", $width=700, $height=400)
 
 deleteDocumentLibrary ()
 
 formatLinkPickerTitle ($document)
 
 rescan ()
 
 scanFiles ($path)
 
 importMetaData ($file)
 

Static Public Member Functions

static deleteUser ($user)
 Respond to fired event DeleteUser. More...
 
static enumerateItems ($items)
 Enumerate the Document objects. More...
 
static displayLibrary ($identifier, &$continue)
 
static createLibraryObj ()
 
static createLibrary ($form)
 
static deleteRole ($del_role)
 
static documentLibraryTabs ($key)
 
static buildDocumentLibraryForm ($library)
 
static formatDocumentLink ($document)
 
static getStyles ()
 
static zipLibrary ($library_id, $process=null)
 Generate a ZIP archive of all the documents in the specified library. More...
 
static getRoleOptions ()
 
static getRoleList ()
 
static getMaxUploadBytes ()
 Calculate the maximum allowed file upload size in bytes. More...
 
static getMaxUploadSize ()
 Returns the maximum allowed file upload size in human-readable format. More...
 
static registerSearchables ($searchables)
 
static registerSolrAdapter ()
 
static upgradeComponent ($version)
 
static registerCommentAdapter ()
 
static registerTaxonomyClasses ($classes)
 
static registerSerializationHandler ()
 
static setDefaults ()
 

Public Attributes

 $library
 
 $docs
 
 $documents
 
 $width = 700
 
 $height = 400
 

Detailed Description

The DocumentManager class provides the core API and management functions for uploading documents and managing document libraries.

Author
Andy Green

Definition at line 70 of file document_manager.inc.

Member Function Documentation

◆ buildDocumentLibraryForm()

static DocumentManager::buildDocumentLibraryForm (   $library)
static

Definition at line 691 of file document_manager.inc.

692  {
693  $form = new AutoForm($library);
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).");
697 
698  $form->allowDelete = true;
699  $form->onDelete = deleteDocumentLibary;
700 
701  return $form;
702  }
$form
deleteDocumentLibary($library)

◆ createLibrary()

static DocumentManager::createLibrary (   $form)
static

Definition at line 632 of file document_manager.inc.

633  {
634  $d = $form->data->getLibraryDirectory();
635  }
if(!checkRole($library->allow_access) &&! $library->allowAccess()) if(!checkRole($document->allow_access)) $d
Definition: download.inc:66

◆ createLibraryObj()

static DocumentManager::createLibraryObj ( )
static

Definition at line 608 of file document_manager.inc.

609  {
610  global $user;
611 
612  $library = new DocumentLibrary();
613  $library->owner_id = $user->user_id;
614  $library->create_date = now();
615  $defaultRole = DocumentLibrary::getDefaultRole();
616  if($defaultRole)
617  {
618  $library->allow_access = $defaultRole;
619  $library->manage_folders = $defaultRole;
620  $library->upload_files = $defaultRole;
621  $library->delete_files = $defaultRole;
622  }
623 
624 
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");
628 
629  return $library;
630  }
static getDefaultRole($fileshare=false)
global $user

◆ deleteDocument()

DocumentManager::deleteDocument (   $document)

Delete the specified document (assuming the user has permission).

Parameters
Document$documentthe document object to be deleted
Returns
boolean true if the document was successfully deleted, false otherwise

Definition at line 485 of file document_manager.inc.

486  {
487  $fullPath = $this->library->getLibraryDirectory() . DIRECTORY_SEPARATOR . $document->file;
488  if (file_exists($fullPath))
489  {
490  unlink($fullPath);
491  }
492 
493  $document->delete();
494  return true;
495  }
if(! $document_id) $document
Definition: delete.inc:43

◆ deleteDocumentLibrary()

DocumentManager::deleteDocumentLibrary ( )

Definition at line 637 of file document_manager.inc.

638  {
639  $documents = $this->library->Documents();
640  if(count($documents) > 0)
641  {
642  foreach($documents as $document)
643  $this->deleteDocument($document);
644  }
645 
646  $folders = $this->library->Folders();
647  if(count($folders) > 0)
648  {
649  foreach($folders as $folder)
650  {
651  $this->deleteFolder($folder);
652  }
653  }
654 
655  $fileshareUsers = $this->library->FileshareUsers();
656  if(count($fileshareUsers) > 0)
657  {
658  foreach($fileshareUsers as $f_user)
659  $f_user->delete();
660  }
661 
662  $this->library->delete();
663  }
$folder
Definition: templates.inc:41
deleteDocument($document)
Delete the specified document (assuming the user has permission).

◆ deleteFolder()

DocumentManager::deleteFolder (   $folder)

Definition at line 500 of file document_manager.inc.

501  {
502  $folder = sanitizePath($folder);
503  $path = $this->library->getLibraryDirectory() . DIRECTORY_SEPARATOR . $folder;
504 
505  if (file_exists($path))
506  rmdir($path);
507  $folder->delete();
508  }
if(! $page) $path
Definition: page.inc:57

◆ deleteRole()

static DocumentManager::deleteRole (   $del_role)
static

Definition at line 666 of file document_manager.inc.

667  {
668  $constraint = "WHERE role like '%$del_role%'";
669 
670  $roleFields = array("upload_files", "delete_files", "manage_folders", "allow_access");
671  foreach($roleFields as $field)
672  {
673  $libraries = Query::create(DocumentLibrary, "WHERE $field like '%$del_role%'")->execute();
675  }
676 
677  return $del_role;
678  }
$constraint
static deleteRoleFromString(&$items, $del_role, $field="")

◆ deleteUser()

static DocumentManager::deleteUser (   $user)
static

Respond to fired event DeleteUser.

Delete any records in this component that have dependencies on user object.

Parameters
obj$user- class SiteUser or custom user class

Definition at line 382 of file document_manager.inc.

383  {
384  $pk = $user->getPrimaryKey();
385  $user_id = $user->$pk;
386 
387  trace("Component document is deleting objects dependent on user_id {$user_id}", 3);
388 
389  $tx = new DataTransaction();
390 
391  try
392  {
393  $libraries = Query::create(DocumentLibrary, "WHERE owner_id=:owner_id")
394  ->bind(":owner_id", $user_id)
395  ->execute();
396 
397  if(count($libraries))
398  {
399  foreach($libraries as $library)
400  {
401  $library->joinTransaction($tx);
403  $mgr->deleteDocumentLibrary();
404  }
405  }
406 
407  $document = new Document();
408  $document->joinTransaction($tx);
409  $document->delete("WHERE owner_id={$user_id}");
410 
411  $download = new DocumentDownload();
412  $download->joinTransaction($tx);
413  $download->delete("WHERE user_id={$user_id}");
414 
415  $tx->commit();
416  }
417  catch(Exception $e)
418  {
419  $tx->rollback();
420  throw $e;
421  }
422 
423  return $user;
424  }
$user_id
This class maps the publication table.
Definition: document.inc:43
DocumentManager($library)
Creates a new DocumentManager for the specified library.

◆ displayLibrary()

static DocumentManager::displayLibrary (   $identifier,
$continue 
)
static

Definition at line 576 of file document_manager.inc.

577  {
578  try
579  {
581  $page = ComponentPage::findByIdentifier("document_library", "WHERE enabled=1");
582 
583  $_GET["library"] = $identifier;
584 
585  $pageView = new ComponentPageView($page, "{$page->template}.tpl");
586 
587  $page_role = $page->role;
588 
589  if (!checkRole($page->role))
590  {
592  redirect("/login");
593  }
594 
595  echo $pageView->drawView();
596 
597  $continue = false;
598  }
599  catch(DataNotFoundException $e)
600  {
601 
602  }
603 
604  return $identifier;
605  }
$page
Definition: help.inc:39
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
static findByIdentifier($identifier)
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
Definition: login.inc:493
$identifier
Definition: rss.inc:37

◆ documentLibraryTabs()

static DocumentManager::documentLibraryTabs (   $key)
static

Definition at line 680 of file document_manager.inc.

681  {
682  $tabs = array(
683  "Details" => "document_library_form",
684  "Files" => "document_library_files"
685  );
686 
687  $qs = ($key) ? "document_library_id=$key" : "";
688  return new TabBar("tabs", $tabs, $qs);
689  }
$tabs

◆ DocumentManager()

DocumentManager::DocumentManager (   $library)

Creates a new DocumentManager for the specified library.

Parameters
DocumentLibrary$librarythe library to be managed

Definition at line 82 of file document_manager.inc.

83  {
84  $this->library = $library;
85  if ($this->library->document_library_id)
86  {
87  $this->documents = $library->Documents("ORDER BY title");
88  }
89  else
90  {
91  $this->documents = array();
92  }
93  }

◆ drawButtons()

DocumentManager::drawButtons ( )

Definition at line 338 of file document_manager.inc.

339  {
340 ?>
341  <br/>
342  <button id="download" class="button" disabled="disabled" onclick="downloadFile()"> Download File </button>&nbsp;&nbsp;
343  <?
344  if (checkRole($this->library->upload_files))
345  {
346 ?>
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>
349 <?
350  }
351 
352  if (checkRole($this->library->delete_files))
353  {
354 ?>
355  <button id="deleteButton" class="button" disabled="disabled" onclick="deleteFile()">Delete File</button>&nbsp;&nbsp;
356 <?
357  }
358 
359  if (checkRole($this->library->manage_folders))
360  {
361 ?>
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;
364 <?php
365  }
366 
367  if (checkRole("admin"))
368  {
369 ?>
370  <button id="rescan" class="button" onclick="rescanLibrary()">Rescan</button>
371 <?
372  }
373  }
& nbsp
Definition: index.inc:49

◆ drawSelectView()

DocumentManager::drawSelectView (   $selectionChanged = "",
  $doubleClick = "",
  $width = 700,
  $height = 400 
)

Definition at line 510 of file document_manager.inc.

511  {
512  global $config;
513 
514  $tree = new DirectoryTreeControl("files");
515  $tree->width = $width;
516  $tree->height = $height;
517  $tree->onSelectionChanged = $selectionChanged;
518  $tree->onDoubleClick = $doubleClick;
519 
520  $tree->selectMode = "file";
521  $tree->permissionCallback = array($this, folderPermission);
522 
523  if ($this->documents)
524  {
525  $root = $this->library->getLibraryDirectory();
526 
527  $tree->buildFolderTree($config["uploaddir"], $root);
528 
529  foreach($this->documents as $doc)
530  {
531  $file = str_replace("/", DIRECTORY_SEPARATOR, $doc->file);
532  $file = str_replace("\\", DIRECTORY_SEPARATOR, $file);
533 
534  trace($file, 4);
535  $folderNode = $tree->findFolder(dirname($file));
536 
537  if ($folderNode != null)
538  {
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);
542 
543  $folderNode->add($fileNode);
544  }
545  else
546  {
547  trace("*** NODE NOT FOUND - $file", 3);
548  }
549  }
550 
551  $tree->children["documents"]->open = true;
552  $tree->writeHTML();
553  }
554  else
555  {
556 ?>
557  <div style="width: <?echo $width?>px;height:<?echo $height?>px;border: solid 1px #000;">&nbsp;</div>
558 <?
559 
560  }
561  }
$helpTree style
Definition: tree.inc:46
$file
Definition: delete.inc:47
folderPermission($folder)
$root
global $config
Definition: import.inc:4

◆ drawView()

DocumentManager::drawView ( )

Definition at line 288 of file document_manager.inc.

289  {
290  global $config;
291 
292  $tree = new DirectoryTreeControl("files");
293  $tree->width = $this->width;
294  $tree->height = $this->height;
295  $tree->onSelectionChanged = "selectionChanged";
296  $tree->onDoubleClick = "downloadFile";
297 
298  $tree->selectMode = "file";
299  $tree->permissionCallback = array($this, folderPermission);
300 
301  $root = $this->library->getLibraryDirectory();
302 
303  $tree->buildFolderTree($config["uploaddir"], $root);
304 
305  foreach($this->documents as $doc)
306  {
307  // Do not list files to which the user does not have access
308  if (!checkRole($doc->allow_access)) continue;
309 
310  $file = str_replace("/", DIRECTORY_SEPARATOR, $doc->file);
311  $file = str_replace("\\", DIRECTORY_SEPARATOR, $file);
312 
313  trace($file, 4);
314  $folderNode = $tree->findFolder(dirname($file));
315 
316  if ($folderNode != null)
317  {
318  trace("Found Folder {$folderNode->id}", 4);
319  $id = str_replace(DIRECTORY_SEPARATOR, "_", $file);
320 
321  $folderNode->add(new FileNode($id, basename($file), $doc->document_id));
322  }
323  else
324  {
325  trace("*** NODE NOT FOUND - $file", 3);
326  }
327  }
328 
329  $tree->children["documents"]->open = true;
330 
331  $page->page_title = "Documents";
332 
333  $tree->writeHTML();
334 
335  $this->drawButtons();
336  }

◆ enumerateItems()

static DocumentManager::enumerateItems (   $items)
static

Enumerate the Document objects.

Parameters
$itemscollection that the Document items are returned in

Definition at line 568 of file document_manager.inc.

569  {
570  $documents = Query::create(DocumentLibrary, "ORDER BY name")->execute();
571 
572  $items["Document Libraries"] = $documents;
573  return $items;
574  }

◆ folderPermission()

DocumentManager::folderPermission (   $folder)

Definition at line 95 of file document_manager.inc.

96  {
97  global $user;
98 
99  $permission = true;
100 
101  if (strpos($folder, "Board Members Only") !== FALSE && (!checkRole("board,admin,super") && !$this->library->allowManageFiles()))
102  {
103  $permission = false;
104  }
105 
106  trace("folderPermission: $folder ($permission)", 3);
107 
108  return $permission;
109  }

◆ formatDocumentLink()

static DocumentManager::formatDocumentLink (   $document)
static

Definition at line 721 of file document_manager.inc.

722  {
723  $library = $document->DocumentLibrary();
724  $size = $library->getFileSize($document);
725  $img = DocumentHandler::getDocIcon($document->file);
726 
727  return "<img src='$img' alt='' style='display: inline-block; vertical-align: middle'>&nbsp;".
728  "<a href='/action/document/download?document_id={$document->document_id}'>{$document->title}</a>&nbsp;$size";
729  }
$size
Definition: download.inc:47

◆ formatLinkPickerTitle()

DocumentManager::formatLinkPickerTitle (   $document)

Definition at line 704 of file document_manager.inc.

705  {
706  $file = $document->file;
707 
708  $type = getDocType($file);
709  $icon = getDocIcon($file);
710 
711  $library = $document->DocumentLibrary();
712  $file_size = $library->getFileSize($document);
713  if($file_size)
714  {
715  $size = "($file_size)";
716  }
717 
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>&nbsp;<img style='display:inline; vertical-align: middle' src='$icon' alt='$type'/>&nbsp;$size");
719  }
$icon
Definition: upload.inc:92

◆ getMaxUploadBytes()

static DocumentManager::getMaxUploadBytes ( )
static

Calculate the maximum allowed file upload size in bytes.

Definition at line 923 of file document_manager.inc.

924  {
925  $max = ini_get("upload_max_filesize");
926 
927  if (endsWith($max, "M"))
928  {
929  $max *= 1024 * 1024;
930  }
931  else if (endsWith($max, "K"))
932  {
933  $max *= 1024;
934  }
935  else if (endsWidth($max, "G"))
936  {
937  $max *= 1024 * 1024 * 1024;
938  }
939 
940  $postMax = ini_get("post_max_size");
941 
942  if (endsWith($postMax, "M"))
943  {
944  $postMax *= 1024 * 1024;
945  }
946  else if (endsWith($postMax, "K"))
947  {
948  $postMax *= 1024;
949  }
950  else if (endsWidth($postMax, "G"))
951  {
952  $postMax *= 1024 * 1024 * 1024;
953  }
954 
955  return min($max, $postMax);
956  }
$max

◆ getMaxUploadSize()

static DocumentManager::getMaxUploadSize ( )
static

Returns the maximum allowed file upload size in human-readable format.

Definition at line 961 of file document_manager.inc.

962  {
963  return getScaledSize(DocumentManager::getMaxUploadBytes(), 0);
964  }
static getMaxUploadBytes()
Calculate the maximum allowed file upload size in bytes.

◆ getRoleList()

static DocumentManager::getRoleList ( )
static

Definition at line 914 of file document_manager.inc.

915  {
917  return implode(",", array_keys($roles));
918  }

◆ getRoleOptions()

static DocumentManager::getRoleOptions ( )
static

Definition at line 907 of file document_manager.inc.

908  {
910  $roles["visitor"] = "Visitor";
911  return $roles;
912  }
static getRolesArray()
Retrieves the array of roles and their names for the current site for use in a CMS form.
Definition: role.inc:75

◆ getStyles()

static DocumentManager::getStyles ( )
static

Definition at line 731 of file document_manager.inc.

732  {
733  $styles .= "<link href=\"/fakoli/css/tabs.css\" rel=\"stylesheet\"/>\n";
734 
735  return $styles;
736  }
$styles

◆ importMetaData()

DocumentManager::importMetaData (   $file)

Definition at line 782 of file document_manager.inc.

783  {
784  $this->indexedDocuments = reindexList($this->documents, "file");
785 
786  $fp = fopen($file, "r");
787 
788  $fields = fgetcsv($fp);
789 
790  $fileIdx = -1;
791 
792  foreach($fields as $field)
793  {
794  if ($field == "file")
795  {
796  $fileIdx = $i;
797  break;
798  }
799 
800  $i++;
801  }
802 
803  if ($fileIdx < 0)
804  {
805  throw new FakoliException("'field' column not present");
806  }
807 
808  while($values = fgetcsv($fp))
809  {
810  $files = explode(";", $values[$fileIdx]);
811  foreach($files as $f)
812  {
813  $f = trim($f);
814 
815  trace($path, 3);
816 
817  foreach($this->indexedDocuments as $path => $doc)
818  {
819  if (basename($path) == $f)
820  {
821  $i = 0;
822 
823  foreach($fields as $field)
824  {
825  if ($field == "file")
826  {
827  $i++;
828  break;
829  }
830 
831  $doc->set($field, $values[$i]);
832  $i++;
833  }
834 
835  $doc->save();
836  }
837  }
838  }
839  }
840  }
$f
Definition: download.inc:46
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53

◆ registerCommentAdapter()

static DocumentManager::registerCommentAdapter ( )
static

Definition at line 987 of file document_manager.inc.

988  {
990  }
static registerAdapter($component, $parentClass, $xrefClass)

◆ registerSearchables()

static DocumentManager::registerSearchables (   $searchables)
static

Definition at line 966 of file document_manager.inc.

967  {
968  trace("DocumentManager registerSearchables", 3);
969  if (!Settings::getValue("solr", "enabled"))
970  {
971  $searchables["document"] = array(Document);
972  }
973  return $searchables;
974  }
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104

◆ registerSerializationHandler()

static DocumentManager::registerSerializationHandler ( )
static

Definition at line 998 of file document_manager.inc.

999  {
1000  SerializationManager::registerHandler("document_libraries", "Document Libraries &amp; Document Records (files need to be transferred manually)", new DocumentSerializationHandler());
1001  return true;
1002  }
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.

◆ registerSolrAdapter()

static DocumentManager::registerSolrAdapter ( )
static

Definition at line 976 of file document_manager.inc.

977  {
978  SolrManager::registerSolrAdapter(Document, new DocumentSolrAdapter());
979  }

◆ registerTaxonomyClasses()

static DocumentManager::registerTaxonomyClasses (   $classes)
static

Definition at line 992 of file document_manager.inc.

993  {
994  $classes[] = Document;
995  return $classes;
996  }

◆ rescan()

DocumentManager::rescan ( )

Definition at line 738 of file document_manager.inc.

739  {
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)
743  ->execute();
744 
745  $this->scanFiles("documents");
746  }

◆ scanFiles()

DocumentManager::scanFiles (   $path)

Definition at line 748 of file document_manager.inc.

749  {
750  global $user;
751 
752  $base = sanitizePath($this->library->getLibraryDirectory() . DIRECTORY_SEPARATOR . $path);
753 
754  $files = scandir($base);
755  foreach($files as $file)
756  {
757  if ($file == "." || $file == "..") continue;
758 
759  $f = $path . DIRECTORY_SEPARATOR . $file;
760 
761  if (is_dir($base . DIRECTORY_SEPARATOR . $file))
762  {
763  $this->scanFiles($f);
764  }
765  else
766  {
767  if ($this->indexedDocuments[$f]) continue;
768 
769  $doc = new Document();
770  $doc->title = $file;
771  $doc->file = $f;
772  $doc->keywords = "";
773  $doc->notes = "";
774  $doc->public = true;
775  $doc->document_library_id = $this->library->document_library_id;
776  $doc->owner_id = $user->get($user->getPrimaryKey());
777  $doc->save();
778  }
779  }
780  }
$base
Definition: delete.inc:45

◆ setDefaults()

static DocumentManager::setDefaults ( )
static

Definition at line 1004 of file document_manager.inc.

1005  {
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");
1010  }
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
Definition: settings.inc:174

◆ upgradeComponent()

static DocumentManager::upgradeComponent (   $version)
static

Definition at line 981 of file document_manager.inc.

982  {
984  $mgr->upgrade($version);
985  }

◆ uploadFile()

DocumentManager::uploadFile (   $field,
  $folder 
)

Upload a file from the specified form field to the specified folder within the current document library.

Parameters
string$fieldthe form field containing the record for uploaded file
string$folderthe folder within the document library to which the file is to be uploaded
Returns
string the path of the uploaded file within the document library.

Definition at line 432 of file document_manager.inc.

433  {
434 
435  if (!$_FILES[$field])
436  {
437  throw new FakoliException("No upload record found.");
438  }
439 
440  if ($_FILES[$field]["name"]=="")
441  {
442  throw new FakoliException("Upload name is empty");
443  }
444 
445  /* Copy across the uploaded file */
446  $folder = str_replace("/", DIRECTORY_SEPARATOR, $folder);
447  $folder = str_replace("\\", DIRECTORY_SEPARATOR, $folder);
448 
449  $name = $_FILES[$field]["name"];
450 
451  if (!$folder) $folder = "documents";
452 
453  $filepath = $folder . DIRECTORY_SEPARATOR . $name;
454  $base = $this->library->getLibraryDirectory();
455  $dir = $base . DIRECTORY_SEPARATOR . $folder;
456  $fullpath = $dir . DIRECTORY_SEPARATOR . $name;
457 
458  trace("Upload Directory: {$dir}", 3);
459 
460  trace("Uploading file to $fullpath", 3);
461 
462  if (!file_exists($dir))
463  {
464  // If the directory does not exist, create it
465  mkdir($dir);
466  }
467 
468  if (file_exists($fullpath))
469  {
470  // If a previous copy of the file already exists, remove it
471  unlink($fullpath);
472  }
473 
474  move_uploaded_file($_FILES[$field]["tmp_name"], $fullpath);
475  chmod($fullpath, 0755);
476 
477  return str_replace(DIRECTORY_SEPARATOR, "/", $filepath);
478  }
$dir
Definition: delete.inc:44
$filepath
Definition: download.inc:42
$name
Definition: upload.inc:54

◆ writeScript()

DocumentManager::writeScript ( )

Definition at line 111 of file document_manager.inc.

112  {
113  global $dialogs;
114 
115  ob_start();
116 ?>
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 &times;</a></div>
121  <span style="font-weight: bold" id="documentManagerTitle">Document Manager</span>
122  </div>
123  </div>
124  <div id="documentManagerDlgBody" class="dialog_body">
125  </div>
126 </div>
127 <?
128  $dialogs .= ob_get_contents();
129  ob_end_clean();
130 
131  ob_start();
132 ?>
133 <script type="text/javascript">
134 
135 window.addEvent('domready', function()
136 {
137  docManagerDlg = new ModalDialog(document.id('documentManagerDlg'), {handle: document.id('documentManagerDlgHeader'), draggable: true, body: document.id('documentManagerDlgBody')});
138 });
139 
140 function downloadFile()
141 {
142  id = document.id('files_value').value;
143  go("/action/document/download?document_id=" + id);
144 }
145 
146 function editFile()
147 {
148  id = document.id('files_value').value;
149  docManagerDlg.show(function() {}, "/action/document/edit?document_id=" + id);
150 }
151 
152 function editResult(result)
153 {
154  if (result == "1")
155  {
156  docManagerDlg.hide();
157  }
158  else
159  {
160  document.id('Document_form__error').set({'text': result, 'display': 'table-cell'});
161  }
162 }
163 
164 
165 function uploadFile()
166 {
167  id = document.id('files_value').value;
168  docManagerDlg.show(function() {}, "/action/document/upload?document_library_id=<?echo $this->library->document_library_id?>");
169 }
170 
171 function uploadResult(responseText)
172 {
173  if (responseText == "1")
174  {
175  window.location.reload();
176  }
177  else
178  {
179  alert(responseText);
180  }
181 }
182 
183 function deleteFile()
184 {
185  if (confirm("Are you sure you want to delete this file?"))
186  {
187  id = document.id('files_value').value;
188 
189  var request = new Request({'url': '/action/document/delete?document_id=' + id,
190  'method': 'get',
191  'onSuccess': function(responseText)
192  {
193  if (responseText == "1")
194  {
195  window.location.reload();
196  }
197  else
198  {
199  alert(responseText);
200  }
201  },
202  'onFailure': function() { alert("Failed to communicate with server");}});
203 
204  request.send();
205  }
206 }
207 
208 function selectionChanged()
209 {
210  var id = document.id('files_value').value;
211 
212  if (id > 0)
213  {
214  document.id('download').removeProperty("disabled");
215  if(document.id('edit')) document.id('edit').removeProperty("disabled");
216  document.id('deleteButton').removeProperty("disabled");
217 
218  }
219  else
220  {
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");
224  }
225 }
226 
227 function rescanLibrary()
228 {
229  result = httpRequest("/action/document/rescan?document_library_id=<?echo $this->library->document_library_id?>");
230  if (result == "OK")
231  {
232  window.location.reload();
233  }
234  else
235  {
236  alert(result);
237  }
238 }
239 
240 <?
241  if (checkRole($this->library->manage_folders) || $this->library->allowManageFiles())
242  {
243 ?>
244 function createFolder()
245 {
246  docManagerDlg.show(function() {}, "/action/document/create_folder?document_library_id=<?echo $this->library->document_library_id?>");
247 }
248 
249 function createFolderResult(result)
250 {
251  if (result == 1)
252  {
253  window.location.reload();
254  }
255  else
256  {
257  alert(result);
258  }
259 }
260 
261 function deleteFolder()
262 {
263  docManagerDlg.show(function() {}, "/action/document/delete_folder?document_library_id=<?echo $this->library->document_library_id?>");
264 }
265 
266 function deleteFolderResult(result)
267 {
268  if (result == 1)
269  {
270  window.location.reload();
271  }
272  else
273  {
274  alert(result);
275  }
276 }
277 
278 <?
279  }
280 ?>
281 </script>
282 <?
283  $script .= ob_get_contents();
284  ob_end_clean();
285  return $script;
286  }
uploadFile($field, $folder)
Upload a file from the specified form field to the specified folder within the current document libra...
$validator id

◆ zipLibrary()

static DocumentManager::zipLibrary (   $library_id,
  $process = null 
)
static

Generate a ZIP archive of all the documents in the specified library.

Parameters
integer$library_idthe ID of the library to be zipped

Definition at line 846 of file document_manager.inc.

847  {
848  global $config;
849 
850  Fakoli::assertRole("admin");
851  $library = new DocumentLibrary($library_id);
852 
853  if ($process)
854  {
855  $process->setProgress("Running", "Scanning files", 0);
856  }
857 
858  $files = $library->Documents("ORDER BY file");
859 
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))
864  {
865  unlink($libraryZipFile);
866  }
867 
868 
869  $zip = new ZipArchive();
870 
871  // open archive
872  if ($zip->open($libraryZipFile, ZIPARCHIVE::CREATE) !== TRUE)
873  {
874  if ($process)
875  {
876  $process->setProgress("Error", "Could not create ZIP archive");
877  throw new FakoliException("Could not create ZIP archive");
878  }
879  }
880 
881  $max = count($files);
882  $c = 0;
883 
884  foreach($files as $file)
885  {
886  $fullPath = $libraryDir . DIRECTORY_SEPARATOR . $file->file;
887  $zip->addFile($fullPath, $file->file);
888 
889  if ($process)
890  {
891  $process->setProgress("Running", "Added $c of $max ".pluralize("file", $max), number_format(100 * $c / $max, 0));
892  }
893  }
894 
895  $zip->close();
896 
897  if ($process)
898  {
899  $process->setProgress("Completed", "Zip archive created", 100);
900  }
901  }
static assertRole($role, $redirect="", $message="")
Assert that the user has one of the specified roles.
Definition: core.inc:297
if(!checkRole("admin")) $c
$process
Definition: run.php:54

Member Data Documentation

◆ $docs

DocumentManager::$docs

Definition at line 73 of file document_manager.inc.

◆ $documents

DocumentManager::$documents

Definition at line 74 of file document_manager.inc.

◆ $height

DocumentManager::$height = 400

Definition at line 76 of file document_manager.inc.

◆ $library

DocumentManager::$library

Definition at line 72 of file document_manager.inc.

◆ $width

DocumentManager::$width = 700

Definition at line 75 of file document_manager.inc.


The documentation for this class was generated from the following file: