FOSSology  4.7.1
Open Source License Compliance by Open Source Software
admin-folder-edit.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008-2012 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
10 
11 define("TITLE_FOLDER_PROPERTIES", _("Edit Folder Properties"));
12 
14 {
15 
17  private $dbManager;
18 
19  function __construct()
20  {
21  $this->Name = "folder_properties";
22  $this->Title = TITLE_FOLDER_PROPERTIES;
23  $this->MenuList = "Organize::Folders::Edit Properties";
24  $this->Dependency = array();
25  $this->DBaccess = PLUGIN_DB_WRITE;
26  parent::__construct();
27  $this->dbManager = $GLOBALS['container']->get('db.manager');
28  }
29 
36  function Edit($FolderId, $NewName, $NewDesc)
37  {
38  $sql = 'SELECT * FROM folder where folder_pk = $1;';
39  $Row = $this->dbManager->getSingleRow($sql,array($FolderId),__METHOD__."Get");
40  /* If the folder does not exist. */
41  if ($Row['folder_pk'] != $FolderId) {
42  return (0);
43  }
44  $NewName = trim($NewName);
45  if (! empty($FolderId)) {
46  // Reuse the old name if no new name was given
47  if (empty($NewName)) {
48  $NewName = $Row['folder_name'];
49  }
50  // Reuse the old description if no new description was given
51  if (empty($NewDesc)) {
52  $NewDesc = $Row['folder_desc'];
53  }
54  } else {
55  return (0); // $FolderId is empty
56  }
57  /* @var $folderDao FolderDao */
58  $folderDao = $GLOBALS['container']->get('dao.folder');
59  $parentId = $folderDao->getFolderParentId($FolderId);
60  if (! empty($parentId)) {
61  $folderWithSameNameUnderParent = $folderDao->getFolderId($NewName, $parentId);
62  if (! empty($folderWithSameNameUnderParent) &&
63  $folderWithSameNameUnderParent != $FolderId) {
64  return 4;
65  }
66  }
67  /* Change the properties */
68  $sql = 'UPDATE folder SET folder_name = $1, folder_desc = $2 WHERE folder_pk = $3;';
69  $this->dbManager->getSingleRow($sql,array($NewName, $NewDesc, $FolderId),__METHOD__."Set");
70  return (1);
71  }
72 
76  public function Output()
77  {
78  /* If this is a POST, then process the request. */
79  $FolderSelectId = GetParm('selectfolderid', PARM_INTEGER);
80  if (empty($FolderSelectId)) {
81  $FolderSelectId = FolderGetTop();
82  }
83  $FolderId = GetParm('oldfolderid', PARM_INTEGER);
84  $NewName = GetParm('newname', PARM_TEXT);
85  $NewDesc = GetParm('newdesc', PARM_TEXT);
86  if (! empty($FolderId)) {
87  $FolderSelectId = $FolderId;
88  $rc = $this->Edit($FolderId, $NewName, $NewDesc);
89  if ($rc == 1) {
90  /* Need to refresh the screen */
91  $text = _("Folder Properties changed");
92  $this->vars["message"] = $text;
93  } else if ($rc == 4) {
94  $text = _("Folder");
95  $text1 = _("Exists");
96  $this->vars["message"] = "$text " . htmlentities(trim($NewName)) . " $text1";
97  }
98  }
99  /* Get the folder info */
100  $sql = 'SELECT * FROM folder WHERE folder_pk = $1;';
101  $Folder = $this->dbManager->getSingleRow($sql,array($FolderSelectId),__METHOD__."getFolderRow");
102 
103  /* Display the form */
104  $formVars["onchangeURI"] = Traceback_uri() . "?mod=" . $this->Name . "&selectfolderid=";
105  $formVars["folderListOption"] = FolderListOption(-1, 0, 1, $FolderSelectId);
106  $formVars["folder_name"] = $Folder['folder_name'];
107  $formVars["folder_desc"] = $Folder['folder_desc'];
108  return $this->renderString("admin-folder-edit-form.html.twig",$formVars);
109  }
110 }
111 $NewPlugin = new folder_properties;
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
renderString($templateName, $vars=null)
Definition: FO_Plugin.php:414
Output()
Generate the text for this plugin.
Edit($FolderId, $NewName, $NewDesc)
Given a folder's ID and a name, alter the folder properties. Includes idiot checking since the input ...
__construct()
base constructor. Most plugins will just use this
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.
Traceback_uri()
Get the URI without query to this location.
Definition: common-parm.php:97
const PARM_TEXT
Definition: common-parm.php:20
const PARM_INTEGER
Definition: common-parm.php:14
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:38
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16