FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
AdminGroupDelete.php
1 <?php
2 /***********************************************************
3  * Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
4  * Copyright (C) 2014-2015, Siemens AG
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***********************************************************/
19 
20 namespace Fossology\UI\Page;
21 
27 
33 {
34 
35  const NAME = 'group_delete';
36 
37  function __construct()
38  {
39  parent::__construct(self::NAME, array(
40  self::TITLE => _("Delete Group"),
41  self::MENU_LIST => "Admin::Groups::Delete Group",
42  self::PERMISSION => Auth::PERM_WRITE,
43  self::REQUIRES_LOGIN => TRUE
44  ));
45  }
46 
51  protected function handle(Request $request)
52  {
53  $userId = Auth::getUserId();
54  $vars = array();
55 
57  $userDao = $this->getObject('dao.user');
58  $groupMap = $userDao->getDeletableAdminGroupMap($userId,
59  $_SESSION[Auth::USER_LEVEL]);
60 
61  $groupId = $request->get('grouppk');
62  if (! empty($groupId)) {
63  try {
64  $userDao->deleteGroup($groupId);
65  $vars['message'] = _("Group") . ' ' . $groupMap[$groupId] . ' ' . _("deleted") . '.';
66  unset($groupMap[$groupId]);
67  } catch (\Exception $e) {
68  $vars['message'] = $e->getMessage();
69  }
70  }
71 
72  if (empty($groupMap)) {
73  $vars['content'] = _("You have no groups you can delete.");
74  return $this->render('include/base.html.twig', $this->mergeWithDefault($vars));
75  }
76  $vars['groupMap'] = $groupMap;
77  $vars['uri'] = Traceback_uri() . "?mod=group_delete";
78  $vars['groupMap'] = $groupMap;
79  return $this->render('admin_group_delete.html.twig', $this->mergeWithDefault($vars));
80  }
81 }
82 
83 register_plugin(new AdminGroupDelete());
Traceback_uri()
Get the URI without query to this location.
static getUserId()
Get the current user&#39;s id.
Definition: Auth.php:69
render($templateName, $vars=null, $headers=null)