CMS  Version 3.9
create_folder.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");
35 Fakoli::usingFeature("validation");
36 
37 $document_library_id = checkNumeric($_GET["document_library_id"]);
39 {
40  Fakoli::end("Invalid Parameter");
41 }
42 
43 global $library;
44 
46 
48 
49 $validator = new ValidationEngine();
50 $validator->id = "folder_form";
51 $validator->add(new RequiredValidator("parent_folder_value", "Parent Folder"));
52 $validator->add(new RequiredValidator("folder_name", "Folder Name"));
53 $validator->add(new RegularExpressionValidator("folder_name", "Folder Name", "^[A-Za-z0-9_\-]+$", "Please supply a valid folder name, with only alphanumeric characters, underscore, or dash"));
54 
55 if (!checkRole($library->allow_access) && !$library->allowManageFiles())
56 {
57  Fakoli::end("Access Denied");
58 }
59 
60 if ($method == "POST")
61 {
62  $errors = $validator->validate();
63  if ($errors)
64  {
65  // Throw the validation error back to the calling AJAX script
67  }
68 
69  $parent_folder = sanitizePath($_POST["parent_folder_value"]);
70  $folder_name = sanitizePath($_POST["folder_name"]);
71  if (!$parent_folder) $parent_folder = $config['uploaddir'];
72 
73  $path = $library->getLibraryDirectory() . DIRECTORY_SEPARATOR . $parent_folder . DIRECTORY_SEPARATOR . $folder_name;
74 
75  if (file_exists($path))
76  {
77  Fakoli::end("A file or directory already exists with that name");
78  }
79 
80  mkdir($path);
81  chmod($path, 0755);
82  Fakoli::end("1");
83 }
84 else
85 {
86  $tree = new DirectoryTreeControl("parent_folder");
87  $tree->width = 320;
88  $tree->height = 150;
89  $tree->permissionCallback = array($docMgr, folderPermission);
90  $root = $library->getLibraryDirectory();
91 
92  $tree->buildFolderTree($config["uploaddir"], $root);
93 
94 ?>
95 <script type="text/javascript">
96 <? echo $validator->writeScript(); ?>
97 
98 document.id('folder_form').iFrameFormRequest({'onRequest': function() { return validate_folder_form(document.id('folder_form')); }, 'onComplete': createFolderResult, 'onFailure': function() { alert("Failed to communicate with server"); }});
99 
100 </script>
101 <form name="folder_form" id="folder_form" method="POST" action="/action/document/create_folder?document_library_id=<?echo $document_library_id?>">
102 <table class="form">
103  <tr>
104  <td style="vertical-align: top"><label>Parent Folder</label></td>
105  <td>
106  <? $tree->writeHTML(); ?>
107  </td>
108  </tr>
109  <tr>
110  <td><label>Folder Name</label></td>
111  <td><input type="text" name="folder_name" value="" style="width: 320px"/></td>
112  </tr>
113  <tr>
114  <td colspan="2"><input type="submit" class="button" value="Create Folder"/></td>
115  </tr>
116 </table>
117 </form>
118 <?
119 }
120 ?>
$_POST["owner_id"]
Definition: blog_form.inc:54
$errors
Definition: error_log.inc:15
if(! $page) $path
Definition: page.inc:57
$helpTree style
Definition: tree.inc:46
$form action
Definition: edit.inc:67
The DocumentManager class provides the core API and management functions for uploading documents and ...
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
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
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$validator
$docMgr
$root
$document_library_id
if(! $document_library_id) global $library
$topicList colspan
Definition: group_form.inc:54
global $config
Definition: import.inc:4