FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
common-users.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with this library; if not, write to the Free Software Foundation, Inc.0
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  ***********************************************************/
18 
44 function add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify,
45  $agentList, $Folder, $default_bucketpool_fk='')
46 {
47  global $container;
48  $dbManager = $container->get('db.manager');
49 
50  if (empty($default_bucketpool_fk)) {
51  $default_bucketpool_fk = null;
52  }
53 
54  $dbManager->prepare($stmt='users.insert',$sql="INSERT INTO users
55  (user_name,user_desc,user_seed,user_pass,user_perm,user_email,
56  email_notify,user_agent_list,root_folder_fk) VALUES ($1,$2,$3,$4,$5,$6, $7,$8,$9)");
57  $dbManager->execute($stmt,array ($User,$Desc,$Seed,$Hash,$Perm,$Email, $Email_notify,$agentList,$Folder));
58 
59  /* Make sure it was added */
60  $row = $dbManager->getSingleRow("SELECT * FROM users WHERE user_name = $1",array($User),$stmt='users.get');
61  if (empty($row['user_name'])) {
62  $text = _("Failed to insert user.");
63  return ($text);
64  }
65 
66  /* The user was added, so create their group and make them the admin */
67  $user_name = $row['user_name'];
68  $user_pk = $row['user_pk'];
69  // Add user group
70  $dbManager->prepare($stmt='group.get', $sql = "select group_pk from groups where LOWER(group_name)=LOWER($1)");
71  $verg = $dbManager->execute('group.get',array($user_name));
72  $GroupRow = $dbManager->fetchArray($verg);
73  if (false === $GroupRow) {
74  $dbManager->getSingleRow('insert into groups(group_name) values ($1)',
75  array($user_name));
76  $GroupRow = $dbManager->fetchArray(
77  $dbManager->execute('group.get', array($user_name)));
78  }
79 
80  $group_pk = $GroupRow['group_pk'];
81  // make user a member of their own group
82  $dbManager->getSingleRow($sql="insert into group_user_member (group_fk, user_fk, group_perm) values ($1,$2,$3)",
83  $param=array($group_pk, $user_pk, 1),$stmt='groupmember.insert');
84  // set active group = own group
85  $dbManager->prepare($stmt='users.update', $sql = "update users SET group_fk=$1, default_bucketpool_fk=$3 WHERE user_pk=$2");
86  $dbManager->execute($stmt,array($group_pk,$user_pk,$default_bucketpool_fk));
87  return ('');
88 }
add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.