CMS  Version 3.9
upload.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 Fakoli::using("document", "taxonomy");
35 Fakoli::usingFile("framework/auto_form.inc");
36 
37 $document_library_id = checkNumeric($_GET["document_library_id"]);
38 $folder_select = checkNumeric($_GET["folder_select"]);
39 
40 
42 {
43  Fakoli::end("Invalid Parameter");
44 }
45 
46 global $library;
47 
49 
50 if (!checkRole($library->allow_access) && !$library->allowAccess())
51 {
52  Fakoli::end("Access Denied");
53 }
54 
56 
57 $document->filter = new InclusionFilter("document_id", "title", "notes", "keywords", "file", "author", "publication_date", "document_library_id", "owner_id", "allow_access");
58 
59 $form = new AutoForm($document, "POST", "/action/document/upload?document_library_id=$document_library_id");
60 $form->ajaxSubmit("function(result) {uploadResult(result);}", "function() {document.id('{$form->id}_error').set('text','Failed to communicate with server'); }");
61 $form->hide("document_library_id", "owner_id");
62 $form->required("title");
63 $form->validator->add(new RequiredFileValidator("file", "File", "You must select a file to upload."));
64 $form->annotate("keywords", "Separate keywords with a comma");
65 $form->getRenderer("title")->autocomplete = false;
66 
67 $form->annotate("file", "The maximum allowed file size is ".DocumentManager::getMaxUploadSize());
68 
69 $notes = $form->getRenderer("notes");
70 $notes->colspan = 1;
71 $notes->columns = 38;
72 
74 
76 {
77  $folderSelect = new FolderSelectFieldRenderer($form, "folder", "Folder", $library);
78 }
79 $fileUpload = new FileUploadFieldRenderer($form, "file", "File", uploadLibraryFile);
80 $allowAccessList = new CheckListFieldRenderer($form, "allow_access", "Allow Access", DocumentManager::getRoleOptions());
81 
82 if ($method == "POST")
83 {
84  if (!$_POST["publication_date"]) $_POST["publication_date"] = date("m/d/Y");
85  $_POST["owner_id"] = $user->get($user->getPrimaryKey());
86  $_POST["document_library_id"] = $document_library_id;
87 
88  if ($form->save())
89  {
90  Fakoli::end("1");
91  }
92  else
93  {
94  Fakoli::end($form->msg);
95  }
96 }
97 
98 echo $form->writeScript();
99 $form->drawForm();
100 
102 {
103  global $library;
104  global $form;
105 
107  $document->file = $mgr->uploadFile($field, $_POST["folder_value"]);
108 }
109 ?>
$_POST["owner_id"]
Definition: blog_form.inc:54
This class maps the publication table.
Definition: document.inc:43
The DocumentManager class provides the core API and management functions for uploading documents and ...
static getMaxUploadSize()
Returns the maximum allowed file upload size in human-readable format.
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
static usingFile()
Uses the specified framework file(s) from the framework directory.
Definition: core.inc:369
Constructs a folder selection tree for the specified document library.
static addTaxonomyFieldRenderers($form, $showSelectAll=true, $group=null, $limitTo=null)
global $user
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$folder_select
Definition: upload.inc:38
uploadLibraryFile($field, $document)
Definition: upload.inc:101
$form
Definition: upload.inc:59
$notes
Definition: upload.inc:69
$allowAccessList
Definition: upload.inc:80
if(!checkRole($library->allow_access) &&! $library->allowAccess()) $document
Definition: upload.inc:55
if($folder_select) $fileUpload
Definition: upload.inc:79
$document_library_id
Definition: upload.inc:37
if(! $document_library_id) global $library
Definition: upload.inc:41
$mgr
Definition: upload.inc:39