FOSSology  4.4.0
Open Source License Compliance by Open Source Software
admin-folder-create.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008-2011 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
8 
9 class folder_create extends FO_Plugin
10 {
11  function __construct()
12  {
13  $this->Name = "folder_create";
14  $this->Title = _("Create a new Fossology folder");
15  $this->MenuList = "Organize::Folders::Create";
16  $this->Dependency = array ();
17  $this->DBaccess = PLUGIN_DB_WRITE;
18  parent::__construct();
19  }
20 
33  public function create($parentId, $newFolder, $desc)
34  {
35  $folderName = trim($newFolder);
36  if (empty($folderName)) {
37  return (0);
38  }
39 
40  /* @var $folderDao FolderDao*/
41  $folderDao = $GLOBALS['container']->get('dao.folder');
42 
43  $parentExists = $folderDao->getFolder($parentId);
44  if (! $parentExists) {
45  return (0);
46  }
47 
48  $folderWithSameNameUnderParent = $folderDao->getFolderId($folderName, $parentId);
49  if (! empty($folderWithSameNameUnderParent)) {
50  return 4;
51  }
52 
53  $folderDao->createFolder($folderName, $desc, $parentId);
54  return (1);
55  }
56 
60  public function Output()
61  {
62  /* If this is a POST, then process the request. */
63  $ParentId = GetParm('parentid', PARM_INTEGER);
64  $NewFolder = GetParm('newname', PARM_TEXT);
65  $Desc = GetParm('description', PARM_TEXT);
66  if (! empty($ParentId) && ! empty($NewFolder)) {
67  $rc = $this->create($ParentId, $NewFolder, $Desc);
68  if ($rc == 1) {
69  /* Need to refresh the screen */
70  $text = _("Folder");
71  $text1 = _("Created");
72  $this->vars['message'] = "$text " . htmlentities($NewFolder) . " $text1";
73  } else if ($rc == 4) {
74  $text = _("Folder");
75  $text1 = _("Exists");
76  $this->vars['message'] = "$text " . htmlentities($NewFolder) . " $text1";
77  }
78  }
79 
80  $root_folder_pk = GetUserRootFolder();
81  $formVars["folderOptions"] = FolderListOption($root_folder_pk, 0);
82 
83  return $this->renderString("admin-folder-create-form.html.twig",$formVars);
84  }
85 }
86 
87 $NewPlugin = new folder_create();
88 $NewPlugin->Initialize();
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.
__construct()
base constructor. Most plugins will just use this
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.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
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