FOSSology  4.4.0
Open Source License Compliance by Open Source Software
group-add.php
1 <?php
2 
4 /*
5  SPDX-FileCopyrightText: © 2013 Hewlett-Packard Development Company, L.P.
6  SPDX-FileCopyrightText: © 2015 Siemens AG
7 
8  SPDX-License-Identifier: GPL-2.0-only
9 */
10 
11 define("TITLE_ADD_GROUP", _("Add Group"));
12 
17 class group_add extends FO_Plugin
18 {
19  function __construct()
20  {
21  $this->Name = "group_add";
22  $this->Title = TITLE_ADD_GROUP;
23  $this->MenuList = "Admin::Groups::Add Group";
24  $this->DBaccess = PLUGIN_DB_WRITE;
25  $this->LoginFlag = 1; /* Don't allow Default User to add a group */
26  parent::__construct();
27  }
28 
29 
30  public function Output()
31  {
32  $V = "";
33  /* If this is a POST, then process the request. */
34  $groupname = GetParm('groupname', PARM_TEXT);
35  if (! empty($groupname)) {
36  try {
37  /* @var $userDao UserDao */
38  $userDao = $GLOBALS['container']->get('dao.user');
39  $groupId = $userDao->addGroup($groupname);
40  $userDao->addGroupMembership($groupId, Auth::getUserId());
41  $text = _("Group");
42  $text1 = _("added");
43  $this->vars['message'] = "$text $groupname $text1.";
44  } catch (Exception $e) {
45  $this->vars['message'] = $e->getMessage();
46  }
47  }
48 
49  /* Build HTML form */
50  $text = _("Add a Group");
51  $V.= "<h4>$text</h4>\n";
52  $V.= "<form name='formy' method='POST' action=" . Traceback_uri() ."?mod=group_add>\n";
53  $Val = htmlentities(GetParm('groupname', PARM_TEXT), ENT_QUOTES);
54  $text = _("Enter the groupname:");
55  $V.= "$text\n";
56  $V.= "<input type='text' value='$Val' name='groupname' size=20>\n";
57  $text = _("Add");
58  $V.= "<input type='submit' value='$text'>\n";
59  $V.= "</form>\n";
60 
61  return $V;
62  }
63 }
64 $NewPlugin = new group_add;
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:57
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
add a new group
Definition: group-add.php:18
__construct()
base constructor. Most plugins will just use this
Definition: group-add.php:19
Output()
This function is called when user output is requested. This function is responsible for content....
Definition: group-add.php:30
Traceback_uri()
Get the URI without query to this location.
Definition: common-parm.php:97
const PARM_TEXT
Definition: common-parm.php:20
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:46
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:38