FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
group-add.php
1 <?php
2 
4 /***********************************************************
5  Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
6  Copyright (C) 205 Siemens AG
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  version 2 as published by the Free Software Foundation.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  ***********************************************************/
21 
22 define("TITLE_ADD_GROUP", _("Add Group"));
23 
28 class group_add extends FO_Plugin
29 {
30  function __construct()
31  {
32  $this->Name = "group_add";
33  $this->Title = TITLE_ADD_GROUP;
34  $this->MenuList = "Admin::Groups::Add Group";
35  $this->DBaccess = PLUGIN_DB_WRITE;
36  $this->LoginFlag = 1; /* Don't allow Default User to add a group */
37  parent::__construct();
38  }
39 
40 
41  public function Output()
42  {
43  $V = "";
44  /* If this is a POST, then process the request. */
45  $groupname = GetParm('groupname', PARM_TEXT);
46  if (! empty($groupname)) {
47  try {
48  /* @var $userDao UserDao */
49  $userDao = $GLOBALS['container']->get('dao.user');
50  $groupId = $userDao->addGroup($groupname);
51  $userDao->addGroupMembership($groupId, Auth::getUserId());
52  $text = _("Group");
53  $text1 = _("added");
54  $this->vars['message'] = "$text $groupname $text1.";
55  } catch (Exception $e) {
56  $this->vars['message'] = $e->getMessage();
57  }
58  }
59 
60  /* Build HTML form */
61  $text = _("Add a Group");
62  $V.= "<h4>$text</h4>\n";
63  $V.= "<form name='formy' method='POST' action=" . Traceback_uri() ."?mod=group_add>\n";
64  $Val = htmlentities(GetParm('groupname', PARM_TEXT), ENT_QUOTES);
65  $text = _("Enter the groupname:");
66  $V.= "$text\n";
67  $V.= "<input type='text' value='$Val' name='groupname' size=20>\n";
68  $text = _("Add");
69  $V.= "<input type='submit' value='$text'>\n";
70  $V.= "</form>\n";
71 
72  return $V;
73  }
74 }
75 $NewPlugin = new group_add;
Traceback_uri()
Get the URI without query to this location.
const PARM_TEXT
Definition: common-parm.php:31
add a new group
Definition: group-add.php:28
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
Definition: libfossology.h:50
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67