FOSSology  4.4.0
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 
9 
10 define("TITLE_FOLDER_PROPERTIES", _("Edit Folder Properties"));
11 
13 {
14 
16  private $dbManager;
17 
18  function __construct()
19  {
20  $this->Name = "folder_properties";
21  $this->Title = TITLE_FOLDER_PROPERTIES;
22  $this->MenuList = "Organize::Folders::Edit Properties";
23  $this->Dependency = array();
24  $this->DBaccess = PLUGIN_DB_WRITE;
25  parent::__construct();
26  $this->dbManager = $GLOBALS['container']->get('db.manager');
27  }
28 
35  function Edit($FolderId, $NewName, $NewDesc)
36  {
37  $sql = 'SELECT * FROM folder where folder_pk = $1;';
38  $Row = $this->dbManager->getSingleRow($sql,array($FolderId),__METHOD__."Get");
39  /* If the folder does not exist. */
40  if ($Row['folder_pk'] != $FolderId) {
41  return (0);
42  }
43  $NewName = trim($NewName);
44  if (! empty($FolderId)) {
45  // Reuse the old name if no new name was given
46  if (empty($NewName)) {
47  $NewName = $Row['folder_name'];
48  }
49  // Reuse the old description if no new description was given
50  if (empty($NewDesc)) {
51  $NewDesc = $Row['folder_desc'];
52  }
53  } else {
54  return (0); // $FolderId is empty
55  }
56  /* Change the properties */
57  $sql = 'UPDATE folder SET folder_name = $1, folder_desc = $2 WHERE folder_pk = $3;';
58  $this->dbManager->getSingleRow($sql,array($NewName, $NewDesc, $FolderId),__METHOD__."Set");
59  return (1);
60  }
61 
65  public function Output()
66  {
67  /* If this is a POST, then process the request. */
68  $FolderSelectId = GetParm('selectfolderid', PARM_INTEGER);
69  if (empty($FolderSelectId)) {
70  $FolderSelectId = FolderGetTop();
71  }
72  $FolderId = GetParm('oldfolderid', PARM_INTEGER);
73  $NewName = GetParm('newname', PARM_TEXT);
74  $NewDesc = GetParm('newdesc', PARM_TEXT);
75  if (! empty($FolderId)) {
76  $FolderSelectId = $FolderId;
77  $rc = $this->Edit($FolderId, $NewName, $NewDesc);
78  if ($rc == 1) {
79  /* Need to refresh the screen */
80  $text = _("Folder Properties changed");
81  $this->vars["message"] = $text;
82  }
83  }
84  /* Get the folder info */
85  $sql = 'SELECT * FROM folder WHERE folder_pk = $1;';
86  $Folder = $this->dbManager->getSingleRow($sql,array($FolderSelectId),__METHOD__."getFolderRow");
87 
88  /* Display the form */
89  $formVars["onchangeURI"] = Traceback_uri() . "?mod=" . $this->Name . "&selectfolderid=";
90  $formVars["folderListOption"] = FolderListOption(-1, 0, 1, $FolderSelectId);
91  $formVars["folder_name"] = $Folder['folder_name'];
92  $formVars["folder_desc"] = $Folder['folder_desc'];
93  return $this->renderString("admin-folder-edit-form.html.twig",$formVars);
94  }
95 }
96 $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