FOSSology  4.4.0
Open Source License Compliance by Open Source Software
admin-folder-delete.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008-2013 Hewlett-Packard Development Company, L.P.
4  SPDX-FileCopyrightText: © 2015-2017 Siemens AG
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
11 
12 define("TITLE_ADMIN_FOLDER_DELETE", _("Delete Folder"));
13 
19 {
20 
22  private $dbManager;
23 
24  function __construct()
25  {
26  $this->Name = "admin_folder_delete";
27  $this->Title = TITLE_ADMIN_FOLDER_DELETE;
28  $this->MenuList = "Organize::Folders::Delete Folder";
29  $this->Dependency = array();
30  $this->DBaccess = PLUGIN_DB_WRITE;
31  parent::__construct();
32  $this->dbManager = $GLOBALS['container']->get('db.manager');
33  $this->folderDao = $GLOBALS['container']->get('dao.folder');
34  }
35 
42  function Delete($folderpk, $userId)
43  {
44  $splitFolder = explode(" ",$folderpk);
45  if (! $this->folderDao->isFolderAccessible($splitFolder[1], $userId)) {
46  $text = _("No access to delete this folder");
47  return ($text);
48  }
49  /* Can't remove top folder */
50  if ($splitFolder[1] == FolderGetTop()) {
51  $text = _("Can Not Delete Root Folder");
52  return ($text);
53  }
54  /* Get the folder's name */
55  $FolderName = FolderGetName($splitFolder[1]);
56  /* Prepare the job: job "Delete" */
57  $groupId = Auth::getGroupId();
58  $jobpk = JobAddJob($userId, $groupId, "Delete Folder: $FolderName");
59  if (empty($jobpk) || ($jobpk < 0)) {
60  $text = _("Failed to create job record");
61  return ($text);
62  }
63  /* Add job: job "Delete" has jobqueue item "delagent" */
64  $jqargs = "DELETE FOLDER $folderpk";
65  $jobqueuepk = JobQueueAdd($jobpk, "delagent", $jqargs, NULL, NULL);
66  if (empty($jobqueuepk)) {
67  $text = _("Failed to place delete in job queue");
68  return ($text);
69  }
70 
71  /* Tell the scheduler to check the queue. */
72  $success = fo_communicate_with_scheduler("database", $output, $error_msg);
73  if (! $success) {
74  return $error_msg . "\n" . $output;
75  }
76 
77  return (null);
78  } // Delete()
79 
84  public function Output()
85  {
86  /* If this is a POST, then process the request. */
87  $folder = GetParm('folder', PARM_RAW);
88  $splitFolder = explode(" ",$folder);
89  if (!empty($folder)) {
90  $userId = Auth::getUserId();
91  $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;";
92  $Folder = $this->dbManager->getSingleRow($sql,array($splitFolder[1],$userId),__METHOD__."GetRowWithFolderName");
93  if (!empty($Folder['folder_name'])) {
94  $rc = $this->Delete($folder, $userId);
95  if (empty($rc)) {
96  /* Need to refresh the screen */
97  $text = _("Deletion of folder ");
98  $text1 = _(" added to job queue");
99  $this->vars['message'] = $text . $Folder['folder_name'] . $text1;
100  } else {
101  $text = _("Deletion of ");
102  $text1 = _(" failed: ");
103  $this->vars['message'] = $text . $Folder['folder_name'] . $text1 . $rc;
104  }
105  } else {
106  $text = _("Cannot delete this folder :: Permission denied");
107  $this->vars['message'] = $text;
108  }
109  }
110 
111  $V= "<form method='post'>\n"; // no url = this url
112  $text = _("Select the folder to");
113  $text1 = _("delete");
114  $V.= "$text <em>$text1</em>.\n";
115  $V.= "<ul>\n";
116  $text = _("This will");
117  $text1 = _("delete");
118  $text2 = _("the folder, all subfolders, and all uploaded files stored within the folder!");
119  $V.= "<li>$text <em>$text1</em> $text2\n";
120  $text = _("Be very careful with your selection since you can delete a lot of work!");
121  $V.= "<li>$text\n";
122  $text = _("All analysis only associated with the deleted uploads will also be deleted.");
123  $V.= "<li>$text\n";
124  $text = _("THERE IS NO UNDELETE. When you select something to delete, it will be removed from the database and file repository.");
125  $V.= "<li>$text\n";
126  $V.= "</ul>\n";
127  $text = _("Select the folder to delete: ");
128  $V.= "<P>$text\n";
129  $V.= "<select name='folder' class='ui-render-select2'>\n";
130  $text = _("select folder");
131  $V.= "<option value='' disabled selected>[$text]</option>\n";
132  $V.= FolderListOption(-1, 0, 1, -1, true);
133  $V.= "</select><P />\n";
134  $text = _("Delete");
135  $V.= "<input type='submit' value='$text'>\n";
136  $V.= "</form>\n";
137  return $V;
138  }
139 }
140 
141 $NewPlugin = new admin_folder_delete();
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
UI plugin to delete folders.
Delete($folderpk, $userId)
Creates a job to detele the folder.
__construct()
base constructor. Most plugins will just use this
Output()
This function is called when user output is requested. This function is responsible for content....
FolderGetName($FolderPk, $Top=-1)
Given a folder_pk, return the full path to this folder.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
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:157
const PARM_RAW
Definition: common-parm.php:22
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
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:38
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16