CMS  Version 3.9
delete_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("template");
35 Fakoli::usingFeature("validation");
36 Fakoli::assertRole("admin");
37 
38 $mgr = new TemplateManager($config['homedir'], 'templates');
39 
40 $validator = new ValidationEngine();
41 $validator->id = "folder_form";
42 $validator->add(new RequiredValidator("folder_value", "Folder"));
43 
44 if ($method == "POST")
45 {
46  $errors = $validator->validate();
47  if ($errors)
48  {
49  // Throw the validation error back to the calling AJAX script
50  die($errors);
51  }
52 
53  $folder = sanitizePath($_POST["folder_value"]);
54 
55  $path = $config['homedir'] . DIRECTORY_SEPARATOR . $folder;
56 
57  if (!file_exists($path))
58  {
59  die("1"); // Already deleted - why worry the user?
60  }
61 
62  $handle = opendir($path);
63  while(($f = readdir($handle)) !== FALSE)
64  {
65  if ($f != "." && $f != "..")
66  {
67  $nonempty = true;
68  break;
69  }
70  }
71 
72  closedir($handle);
73 
74  if ($nonempty)
75  {
76  die("The folder cannot be deleted because it is not empty");
77  }
78  else
79  {
80  rmdir($path);
81  die("1");
82  }
83 }
84 else
85 {
86  $tree = new DirectoryTreeControl("folder");
87  $tree->width = 320;
88  $tree->height = 150;
89  $tree->permissionCallback = array($mgr, excludeVersionControl);
90 
91  $tree->buildFolderTree("templates", $config['homedir']);
92 
93 ?>
94 <script type="text/javascript">
95 <? echo $validator->writeScript(); ?>
96 
97 document.id('folder_form').iFrameFormRequest({'onRequest': function() { return validate_folder_form(document.id('folder_form')); }, 'onComplete': deleteFolderResult, 'onFailure': function() { alert("Failed to communicate with server"); }});
98 
99 </script>
100 <form name="folder_form" id="folder_form" method="POST" action="/action/template/delete_folder">
101 <p>Choose the folder you wish to delete using the tree below.<br/>
102 Please note that only empty folders can be deleted <br/>
103 (i.e. those which do not contain files or sub-folders).</p>
104 <table class="form">
105  <tr>
106  <td style="vertical-align: top"><label>Folder</label></td>
107  <td>
108  <? $tree->writeHTML(); ?>
109  </td>
110  </tr>
111  <tr>
112  <td colspan="2"><input type="submit" class="button" value="Delete Folder"/></td>
113  </tr>
114 </table>
115 </form>
116 <?
117 }
118 ?>
$_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
$folder
Definition: templates.inc:41
$form action
Definition: edit.inc:67
$f
Definition: download.inc:46
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 assertRole($role, $redirect="", $message="")
Assert that the user has one of the specified roles.
Definition: core.inc:297
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$validator
$forumRequest to
$topicList colspan
Definition: group_form.inc:54
global $config
Definition: import.inc:4
$mgr
read only
Definition: edit.inc:62