8 namespace Fossology\UI\Page;
13 use Symfony\Component\HttpFoundation\Request;
14 use Symfony\Component\HttpFoundation\Response;
23 const NAME =
'group_edit';
25 function __construct()
27 parent::__construct(self::NAME, array(
28 self::TITLE => _(
"Edit Group"),
29 self::MENU_LIST =>
"Admin::Groups::Edit Group",
31 self::REQUIRES_LOGIN => TRUE
39 protected function handle(Request $request)
46 $groupMap = $userDao->getDeletableAdminGroupMap($userId,
49 if (empty($groupMap)) {
50 $vars[
'content'] = _(
"You have no groups you can edit.");
51 return $this->
render(
'include/base.html.twig', $this->mergeWithDefault($vars));
54 $groupId = $request->get(
'grouppk');
55 $newGroupName =
trim($request->get(
'newgroupname'));
56 if (! empty($groupId) && ! empty($newGroupName)) {
58 if (empty($validateGroup)) {
60 $escapedGroupName = htmlspecialchars(strip_tags($newGroupName), ENT_QUOTES,
'UTF-8');
61 $userDao->editGroup($groupId, $escapedGroupName);
62 $vars[
'message'] = _(
"Group") .
' ' . $groupMap[$groupId] .
' ' . _(
"edited to ".$escapedGroupName ) .
'.';
63 $groupMap[$groupId] = $escapedGroupName;
64 }
catch (\Exception $e) {
65 $vars[
'message'] = $e->getMessage();
68 $vars[
'message'] = $validateGroup;
72 $vars[
'groupMap'] = $groupMap;
74 return $this->
render(
'admin_group_edit.html.twig', $this->mergeWithDefault($vars));
85 if (empty($groupName)) {
86 return _(
"Invalid: Group name cannot be whitespace only");
87 }
else if (preg_match(
'/^[\s\w_-]$/', $groupName) !== 1) {
88 return _(
"Invalid: Group name can only contain letters, numbers, hyphens and underscores");
89 }
else if (is_numeric($groupName)) {
90 return _(
"Invalid: Group name cannot be numeric-only");
97 register_plugin(
new AdminGroupEdit());
Contains the constants and helpers for authentication of user.
static getUserId()
Get the current user's id.
render($templateName, $vars=null, $headers=null)
validateGroupName($groupName)
validateGroupName. verify if the group is empty or numeric
Traceback_uri()
Get the URI without query to this location.
char * trim(char *ptext)
Trimming whitespace.