FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
admin-folder-delete.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2008-2013 Hewlett-Packard Development Company, L.P.
4  Copyright (C) 2015-2017 Siemens AG
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***********************************************************/
19 
22 
23 define("TITLE_ADMIN_FOLDER_DELETE", _("Delete Folder"));
24 
30 {
31 
33  private $dbManager;
34 
35  function __construct()
36  {
37  $this->Name = "admin_folder_delete";
38  $this->Title = TITLE_ADMIN_FOLDER_DELETE;
39  $this->MenuList = "Organize::Folders::Delete Folder";
40  $this->Dependency = array();
41  $this->DBaccess = PLUGIN_DB_WRITE;
42  parent::__construct();
43  $this->dbManager = $GLOBALS['container']->get('db.manager');
44  $this->folderDao = $GLOBALS['container']->get('dao.folder');
45  }
46 
53  function Delete($folderpk, $userId)
54  {
55  $splitFolder = explode(" ",$folderpk);
56  if (! $this->folderDao->isFolderAccessible($splitFolder[1], $userId)) {
57  $text = _("No access to delete this folder");
58  return ($text);
59  }
60  /* Can't remove top folder */
61  if ($splitFolder[1] == FolderGetTop()) {
62  $text = _("Can Not Delete Root Folder");
63  return ($text);
64  }
65  /* Get the folder's name */
66  $FolderName = FolderGetName($splitFolder[1]);
67  /* Prepare the job: job "Delete" */
68  $groupId = Auth::getGroupId();
69  $jobpk = JobAddJob($userId, $groupId, "Delete Folder: $FolderName");
70  if (empty($jobpk) || ($jobpk < 0)) {
71  $text = _("Failed to create job record");
72  return ($text);
73  }
74  /* Add job: job "Delete" has jobqueue item "delagent" */
75  $jqargs = "DELETE FOLDER $folderpk";
76  $jobqueuepk = JobQueueAdd($jobpk, "delagent", $jqargs, NULL, NULL);
77  if (empty($jobqueuepk)) {
78  $text = _("Failed to place delete in job queue");
79  return ($text);
80  }
81 
82  /* Tell the scheduler to check the queue. */
83  $success = fo_communicate_with_scheduler("database", $output, $error_msg);
84  if (! $success) {
85  return $error_msg . "\n" . $output;
86  }
87 
88  return (null);
89  } // Delete()
90 
95  public function Output()
96  {
97  /* If this is a POST, then process the request. */
98  $folder = GetParm('folder', PARM_RAW);
99  $splitFolder = explode(" ",$folder);
100  if (!empty($folder)) {
101  $userId = Auth::getUserId();
102  $sql = "SELECT folder_name FROM folder join users on (users.user_pk = folder.user_fk or users.user_perm = 10) where folder_pk = $1 and users.user_pk = $2;";
103  $Folder = $this->dbManager->getSingleRow($sql,array($splitFolder[1],$userId),__METHOD__."GetRowWithFolderName");
104  if (!empty($Folder['folder_name'])) {
105  $rc = $this->Delete($folder, $userId);
106  if (empty($rc)) {
107  /* Need to refresh the screen */
108  $text = _("Deletion of folder ");
109  $text1 = _(" added to job queue");
110  $this->vars['message'] = $text . $Folder['folder_name'] . $text1;
111  } else {
112  $text = _("Deletion of ");
113  $text1 = _(" failed: ");
114  $this->vars['message'] = $text . $Folder['folder_name'] . $text1 . $rc;
115  }
116  } else {
117  $text = _("Cannot delete this folder :: Permission denied");
118  $this->vars['message'] = $text;
119  }
120  }
121 
122  $V= "<form method='post'>\n"; // no url = this url
123  $text = _("Select the folder to");
124  $text1 = _("delete");
125  $V.= "$text <em>$text1</em>.\n";
126  $V.= "<ul>\n";
127  $text = _("This will");
128  $text1 = _("delete");
129  $text2 = _("the folder, all subfolders, and all uploaded files stored within the folder!");
130  $V.= "<li>$text <em>$text1</em> $text2\n";
131  $text = _("Be very careful with your selection since you can delete a lot of work!");
132  $V.= "<li>$text\n";
133  $text = _("All analysis only associated with the deleted uploads will also be deleted.");
134  $V.= "<li>$text\n";
135  $text = _("THERE IS NO UNDELETE. When you select something to delete, it will be removed from the database and file repository.");
136  $V.= "<li>$text\n";
137  $V.= "</ul>\n";
138  $text = _("Select the folder to delete: ");
139  $V.= "<P>$text\n";
140  $V.= "<select name='folder' class='ui-render-select2'>\n";
141  $text = _("select folder");
142  $V.= "<option value='' disabled selected>[$text]</option>\n";
143  $V.= FolderListOption(-1, 0, 1, -1, true);
144  $V.= "</select><P />\n";
145  $text = _("Delete");
146  $V.= "<input type='submit' value='$text'>\n";
147  $V.= "</form>\n";
148  return $V;
149  }
150 }
151 
152 $NewPlugin = new admin_folder_delete();
const PARM_RAW
Definition: common-parm.php:33
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
Definition: common-job.php:159
FolderGetName($FolderPk, $Top=-1)
Given a folder_pk, return the full path to this folder.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
UI plugin to delete folders.
Delete($folderpk, $userId)
Creates a job to detele the folder.
Output()
This function is called when user output is requested. This function is responsible for content...
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:50
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67