1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare - account administration * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * -------------------------------------------- * |
---|
6 | * This program is free software; you can redistribute it and/or modify it * |
---|
7 | * under the terms of the GNU General Public License as published by the * |
---|
8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
9 | * option) any later version. * |
---|
10 | \**************************************************************************/ |
---|
11 | |
---|
12 | |
---|
13 | class soaccounts |
---|
14 | { |
---|
15 | function soaccounts() |
---|
16 | { |
---|
17 | } |
---|
18 | |
---|
19 | function add_user($userData) |
---|
20 | { |
---|
21 | $userData['account_expires'] = $userData['expires']; |
---|
22 | |
---|
23 | |
---|
24 | if($userData['email'] != "") |
---|
25 | { |
---|
26 | $userData['account_email'] = $userData['email']; |
---|
27 | } |
---|
28 | |
---|
29 | $GLOBALS['phpgw']->db->lock( |
---|
30 | Array( |
---|
31 | 'phpgw_accounts', |
---|
32 | 'phpgw_nextid', |
---|
33 | 'phpgw_preferences', |
---|
34 | 'phpgw_sessions', |
---|
35 | 'phpgw_acl', |
---|
36 | 'phpgw_applications', |
---|
37 | 'phpgw_app_sessions', |
---|
38 | 'phpgw_hooks' |
---|
39 | ) |
---|
40 | ); |
---|
41 | |
---|
42 | $GLOBALS['phpgw']->accounts->create($userData); |
---|
43 | |
---|
44 | $userData['account_id'] = $GLOBALS['phpgw']->accounts->name2id($userData['account_lid']); |
---|
45 | |
---|
46 | $apps = CreateObject('phpgwapi.applications',$userData['account_id']); |
---|
47 | $apps->read_installed_apps(); |
---|
48 | // Read Group Apps |
---|
49 | if ($userData['account_groups']) |
---|
50 | { |
---|
51 | $apps->account_type = 'g'; |
---|
52 | reset($userData['account_groups']); |
---|
53 | while($groups = each($userData['account_groups'])) |
---|
54 | { |
---|
55 | $apps->account_id = $groups[0]; |
---|
56 | $old_app_groups = $apps->read_account_specific(); |
---|
57 | @reset($old_app_groups); |
---|
58 | while($old_group_app = each($old_app_groups)) |
---|
59 | { |
---|
60 | if (!$apps_after[$old_group_app[0]]) |
---|
61 | { |
---|
62 | $apps_after[$old_group_app[0]] = $old_app_groups[$old_group_app[0]]; |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | $apps->account_type = 'u'; |
---|
69 | $apps->account_id = $userData['account_id']; |
---|
70 | $apps->data = Array(Array()); |
---|
71 | |
---|
72 | if ($userData['account_permissions']) |
---|
73 | { |
---|
74 | @reset($userData['account_permissions']); |
---|
75 | while (list($app,$turned_on) = each($userData['account_permissions'])) |
---|
76 | { |
---|
77 | if ($turned_on) |
---|
78 | { |
---|
79 | $apps->add($app); |
---|
80 | if (!$apps_after[$app]) |
---|
81 | { |
---|
82 | $apps_after[] = $app; |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | $apps->save_repository(); |
---|
88 | |
---|
89 | if ($userData['changepassword']) |
---|
90 | { |
---|
91 | $GLOBALS['phpgw']->acl->add_repository('preferences','changepassword',$userData['account_id'],1); |
---|
92 | } |
---|
93 | // Assign user to groups |
---|
94 | if ($userData['account_groups']) |
---|
95 | { |
---|
96 | $c_acct_groups = count($userData['account_groups']); |
---|
97 | for ($i=0;$i<$c_acct_groups;+$i) |
---|
98 | { |
---|
99 | $GLOBALS['phpgw']->acl->add_repository('phpgw_group',$userData['account_groups'][$i],$userData['account_id'],1); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | $apps->account_apps = array(array()); |
---|
104 | $apps_after = array(array()); |
---|
105 | |
---|
106 | $GLOBALS['phpgw']->db->unlock(); |
---|
107 | |
---|
108 | return $userData['account_id']; |
---|
109 | } |
---|
110 | } |
---|
111 | ?> |
---|