1 | <?php |
---|
2 | /***********************************************************************************\ |
---|
3 | * Expresso Administraᅵᅵo * |
---|
4 | * by Valmir André de Sena (valmirse@gmail.com, valmir.sena@ati.pe.gov.br |
---|
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 | include_once('class.functions.inc.php'); |
---|
13 | include_once('class.ldap_functions.inc.php'); |
---|
14 | include_once('class.imap_functions.inc.php'); |
---|
15 | include_once('class.db_functions.inc.php'); |
---|
16 | |
---|
17 | class shared_accounts |
---|
18 | { |
---|
19 | var $functions; |
---|
20 | var $ldap_functions; |
---|
21 | var $imap_functions; |
---|
22 | var $db_functions; |
---|
23 | |
---|
24 | function shared_accounts() |
---|
25 | { |
---|
26 | |
---|
27 | $this->ldap_functions = new ldap_functions; |
---|
28 | $this->imap_functions = new imap_functions; |
---|
29 | $this->functions = new functions; |
---|
30 | $this->db_functions = new db_functions(); |
---|
31 | |
---|
32 | } |
---|
33 | function create($params) |
---|
34 | { |
---|
35 | $params['uid'] = $this->get_shared_mail2uid($params); |
---|
36 | $return = $this->ldap_functions->create_shared_accounts($params); |
---|
37 | |
---|
38 | if( $return['status'] ){ |
---|
39 | //Create mailbox |
---|
40 | $mailquota = 10; |
---|
41 | $return = $this->imap_functions->create($params['uid'], $params['mailquota']); |
---|
42 | $owners_acl_new = unserialize($params['owners_acl']); |
---|
43 | //add new users e set permissions |
---|
44 | foreach($owners_acl_new as $user => $acl){ |
---|
45 | $result &= $this->imap_functions->setaclfrombox($user,$acl,$params['uid']); |
---|
46 | } |
---|
47 | $owners_calendar_acl_new = unserialize($params['owners_calendar_acl']); |
---|
48 | $owner = $this->ldap_functions->uid2uidnumber($params['uid']); |
---|
49 | foreach($owners_calendar_acl_new as $user => $acl){ |
---|
50 | $result &= $this->db_functions->save_calendar_acls($this->ldap_functions->uid2uidnumber($user),$acl,$owner); |
---|
51 | } |
---|
52 | $this->db_functions->write_log('Create Shared account',$params['uid']); |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | return $return; |
---|
57 | } |
---|
58 | |
---|
59 | function save($params) |
---|
60 | { |
---|
61 | |
---|
62 | $params['uid'] = $this->get_shared_mail2uid($params); |
---|
63 | $params['old_uid'] = $this->get_shared_dn2uid($params['anchor']); |
---|
64 | $result = $this->ldap_functions->save_shared_accounts($params); |
---|
65 | |
---|
66 | if( $result['status']){ |
---|
67 | $result = $this->imap_functions->save_shared_account($params); |
---|
68 | $owners_calendar_acl_new = unserialize($params['owners_calendar_acl']); |
---|
69 | |
---|
70 | $owner = $params['uidnumber']; |
---|
71 | foreach($owners_calendar_acl_new as $user => $acl){ |
---|
72 | $this->db_functions->save_calendar_acls($this->ldap_functions->uid2uidnumber($user),$acl,$owner); |
---|
73 | } |
---|
74 | |
---|
75 | $this->db_functions->write_log('Update Shared account','Old UID:'.$params['old_uid'].' New UID '.$params['uid']); |
---|
76 | } |
---|
77 | |
---|
78 | return $result; |
---|
79 | } |
---|
80 | |
---|
81 | function get($params) |
---|
82 | { |
---|
83 | if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'list_institutional_accounts')) |
---|
84 | { |
---|
85 | $return['status'] = false; |
---|
86 | $return['msg'] = $this->functions->lang('You do not have right to list institutional accounts') . "."; |
---|
87 | return $return; |
---|
88 | } |
---|
89 | |
---|
90 | $input = $params['input']; |
---|
91 | $justthese = array("cn", "mail", "uid"); |
---|
92 | $trs = array(); |
---|
93 | |
---|
94 | foreach ($this->manager_contexts as $idx=>$context) |
---|
95 | { |
---|
96 | $shared_accounts = ldap_search($this->ldap, $context, ("(&(phpgwAccountType=s)(|(mail=$input*)(cn=*$input*)))"), $justthese); |
---|
97 | $entries = ldap_get_entries($this->ldap, $shared_accounts); |
---|
98 | |
---|
99 | for ($i=0; $i<$entries['count']; ++$i) |
---|
100 | { |
---|
101 | $tr = "<tr class='normal' onMouseOver=this.className='selected' onMouseOut=this.className='normal'><td onClick=edit_shared_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['cn'][0] . "</td><td onClick=edit_shared_account('".$entries[$i]['uid'][0]."')>" . $entries[$i]['mail'][0] . "</td><td align='center' onClick=delete_shared_accounts('".$entries[$i]['uid'][0]."')><img HEIGHT='16' WIDTH='16' src=./expressoAdmin1_2/templates/default/images/delete.png></td></tr>"; |
---|
102 | $trs[$tr] = $entries[$i]['cn'][0]; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | $trs_string = ''; |
---|
107 | if (count($trs)) |
---|
108 | { |
---|
109 | natcasesort($trs); |
---|
110 | foreach ($trs as $tr=>$cn) |
---|
111 | { |
---|
112 | $trs_string .= $tr; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | $return['status'] = 'true'; |
---|
117 | $return['trs'] = $trs_string; |
---|
118 | return $return; |
---|
119 | } |
---|
120 | |
---|
121 | function get_data($params) |
---|
122 | { |
---|
123 | $return = $this->ldap_functions->get_shared_account_data($params); |
---|
124 | $owners_acl = $this->imap_functions->getaclfrombox($params); |
---|
125 | $uid = $params['uid']; |
---|
126 | $quota = $this->imap_functions->get_user_info($params['uid']); |
---|
127 | $owner = $this->ldap_functions->uid2uidnumber($params['uid']); |
---|
128 | $calendarAcls = $this->db_functions->get_calendar_acls($owner); |
---|
129 | |
---|
130 | $return['uidnumber'] = $owner; |
---|
131 | $return['mailquota'] = $quota['mailquota']; |
---|
132 | $return['display_empty_inbox'] = $this->functions->check_acl($_SESSION['phpgw_session']['session_lid'],'empty_shared_accounts_inbox') ? 'block' : 'none'; |
---|
133 | $return['allow_edit_shared_account_acl'] = $this->functions->check_acl($_SESSION['phpgw_session']['session_lid'],'edit_shared_accounts_acl'); |
---|
134 | $return['mailquota_used'] = $quota['mailquota_used']; |
---|
135 | $i = 0; |
---|
136 | if( is_array($owners_acl) ){ |
---|
137 | foreach($owners_acl as $key => $value) |
---|
138 | { |
---|
139 | $cn = $this->ldap_functions->uid2cn($key); |
---|
140 | $uidnumber = $this->ldap_functions->uid2uidnumber($key); |
---|
141 | |
---|
142 | if( $uid ) |
---|
143 | $cn .= '(' . $key . ')'; |
---|
144 | |
---|
145 | $return['owners_options'] .= '<option value='. $key .'>' . $cn . '</option>'; |
---|
146 | $return['owners'][$i] .= $key; |
---|
147 | $return['owners_acl'][$i] .= $value; |
---|
148 | $return['owners_calendar_acl'][$i] .= $calendarAcls[$key]; |
---|
149 | ++$i; |
---|
150 | } |
---|
151 | } else { |
---|
152 | $return['owners_options'] = false; |
---|
153 | $return['owners'] = false; |
---|
154 | $return['owners_acl'] = false; |
---|
155 | $return['owners_calendar_acl'] == false; |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | return $return; |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | function delete($params){ |
---|
164 | $result = $this->ldap_functions->delete_shared_account_data($params); |
---|
165 | if( $result['status'] ) |
---|
166 | { |
---|
167 | $result = $this->imap_functions->delete_mailbox($params['uid']); |
---|
168 | $this->db_functions->write_log('Removed Shared account',$params['uid']); |
---|
169 | } |
---|
170 | return $result; |
---|
171 | } |
---|
172 | //Get the shared uid from mail |
---|
173 | function get_shared_mail2uid($params){ |
---|
174 | list($uid) = explode("@",$params['mail']); |
---|
175 | return $uid; |
---|
176 | } |
---|
177 | function get_shared_dn2uid($dn){ |
---|
178 | $uid = ""; |
---|
179 | list($uid) = explode(",", str_replace("uid=","", $dn)); |
---|
180 | return $uid; |
---|
181 | } |
---|
182 | function empty_inbox($params){ |
---|
183 | $params['uid'] = $this->get_shared_dn2uid($params['uid']); |
---|
184 | return $this->imap_functions->empty_shared_account_inbox($params); |
---|
185 | } |
---|
186 | |
---|
187 | } |
---|
188 | ?> |
---|