FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
admin-folder-edit.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2008-2012 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
20 
21 define("TITLE_FOLDER_PROPERTIES", _("Edit Folder Properties"));
22 
24 {
25 
27  private $dbManager;
28 
29  function __construct()
30  {
31  $this->Name = "folder_properties";
32  $this->Title = TITLE_FOLDER_PROPERTIES;
33  $this->MenuList = "Organize::Folders::Edit Properties";
34  $this->Dependency = array();
35  $this->DBaccess = PLUGIN_DB_WRITE;
36  parent::__construct();
37  $this->dbManager = $GLOBALS['container']->get('db.manager');
38  }
39 
46  function Edit($FolderId, $NewName, $NewDesc)
47  {
48  $sql = 'SELECT * FROM folder where folder_pk = $1;';
49  $Row = $this->dbManager->getSingleRow($sql,array($FolderId),__METHOD__."Get");
50  /* If the folder does not exist. */
51  if ($Row['folder_pk'] != $FolderId) {
52  return (0);
53  }
54  $NewName = trim($NewName);
55  if (! empty($FolderId)) {
56  // Reuse the old name if no new name was given
57  if (empty($NewName)) {
58  $NewName = $Row['folder_name'];
59  }
60  // Reuse the old description if no new description was given
61  if (empty($NewDesc)) {
62  $NewDesc = $Row['folder_desc'];
63  }
64  } else {
65  return (0); // $FolderId is empty
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  }
94  }
95  /* Get the folder info */
96  $sql = 'SELECT * FROM folder WHERE folder_pk = $1;';
97  $Folder = $this->dbManager->getSingleRow($sql,array($FolderSelectId),__METHOD__."getFolderRow");
98 
99  /* Display the form */
100  $formVars["onchangeURI"] = Traceback_uri() . "?mod=" . $this->Name . "&selectfolderid=";
101  $formVars["folderListOption"] = FolderListOption(-1, 0, 1, $FolderSelectId);
102  $formVars["folder_name"] = $Folder['folder_name'];
103  $formVars["folder_desc"] = $Folder['folder_desc'];
104  return $this->renderString("admin-folder-edit-form.html.twig",$formVars);
105  }
106 }
107 $NewPlugin = new folder_properties;
Traceback_uri()
Get the URI without query to this location.
const PARM_TEXT
Definition: common-parm.php:31
Output()
Generate the text for this plugin.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
Edit($FolderId, $NewName, $NewDesc)
Given a folder&#39;s ID and a name, alter the folder properties. Includes idiot checking since the input ...
FolderGetTop()
DEPRECATED! Find the top-of-tree folder_pk for the current user.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
renderString($templateName, $vars=null)
Definition: FO_Plugin.php:422
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:50
const PARM_INTEGER
Definition: common-parm.php:25
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695