FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
admin-folder-create.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2008-2011 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  ***********************************************************/
19 
20 class folder_create extends FO_Plugin
21 {
22  function __construct()
23  {
24  $this->Name = "folder_create";
25  $this->Title = _("Create a new Fossology folder");
26  $this->MenuList = "Organize::Folders::Create";
27  $this->Dependency = array ();
28  $this->DBaccess = PLUGIN_DB_WRITE;
29  parent::__construct();
30  }
31 
44  public function create($parentId, $newFolder, $desc)
45  {
46  $folderName = trim($newFolder);
47  if (empty($folderName)) {
48  return (0);
49  }
50 
51  /* @var $folderDao FolderDao*/
52  $folderDao = $GLOBALS['container']->get('dao.folder');
53 
54  $parentExists = $folderDao->getFolder($parentId);
55  if (! $parentExists) {
56  return (0);
57  }
58 
59  $folderWithSameNameUnderParent = $folderDao->getFolderId($folderName, $parentId);
60  if (! empty($folderWithSameNameUnderParent)) {
61  return 4;
62  }
63 
64  $folderDao->createFolder($folderName, $desc, $parentId);
65  return (1);
66  }
67 
71  public function Output()
72  {
73  /* If this is a POST, then process the request. */
74  $ParentId = GetParm('parentid', PARM_INTEGER);
75  $NewFolder = GetParm('newname', PARM_TEXT);
76  $Desc = GetParm('description', PARM_TEXT);
77  if (! empty($ParentId) && ! empty($NewFolder)) {
78  $rc = $this->create($ParentId, $NewFolder, $Desc);
79  if ($rc == 1) {
80  /* Need to refresh the screen */
81  $text = _("Folder");
82  $text1 = _("Created");
83  $this->vars['message'] = "$text " . htmlentities($NewFolder) . " $text1";
84  } else if ($rc == 4) {
85  $text = _("Folder");
86  $text1 = _("Exists");
87  $this->vars['message'] = "$text " . htmlentities($NewFolder) . " $text1";
88  }
89  }
90 
91  $root_folder_pk = GetUserRootFolder();
92  $formVars["folderOptions"] = FolderListOption($root_folder_pk, 0);
93 
94  return $this->renderString("admin-folder-create-form.html.twig",$formVars);
95  }
96 }
97 
98 $NewPlugin = new folder_create();
99 $NewPlugin->Initialize();
Output()
Generate the text for this plugin.
const PARM_TEXT
Definition: common-parm.php:31
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
create($parentId, $newFolder, $desc)
Given a parent folder ID, a name and description, create the named folder under the parent...
GetUserRootFolder()
Get the top-of-tree folder_pk for the current user. Fail if there is no user session.
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
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695