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 | |
---|
16 | class shared_accounts |
---|
17 | { |
---|
18 | var $functions; |
---|
19 | var $ldap_functions; |
---|
20 | var $imap_functions; |
---|
21 | |
---|
22 | function shared_accounts() |
---|
23 | { |
---|
24 | |
---|
25 | $this->ldap_functions = new ldap_functions; |
---|
26 | $this->imap_functions = new imap_functions; |
---|
27 | $this->functions = new functions; |
---|
28 | |
---|
29 | } |
---|
30 | function create($params) |
---|
31 | { |
---|
32 | $params['uid'] = $this->get_shared_mail2uid($params); |
---|
33 | $return = $this->ldap_functions->create_shared_accounts($params); |
---|
34 | |
---|
35 | if( $return['status'] ){ |
---|
36 | //Create mailbox |
---|
37 | $mailquota = 10; |
---|
38 | $return = $this->imap_functions->create($params['uid'], $params['mailquota']); |
---|
39 | $owners_acl_new = unserialize($params['owners_acl']); |
---|
40 | //add new users e set permissions |
---|
41 | foreach($owners_acl_new as $user => $acl){ |
---|
42 | $result &= $this->imap_functions->setaclfrombox($user,$acl,$params['uid']); |
---|
43 | } |
---|
44 | } |
---|
45 | return $return; |
---|
46 | } |
---|
47 | |
---|
48 | function save($params) |
---|
49 | { |
---|
50 | |
---|
51 | $params['uid'] = $this->get_shared_mail2uid($params); |
---|
52 | $params['old_uid'] = $this->get_shared_dn2uid($params['anchor']); |
---|
53 | $result = $this->ldap_functions->save_shared_accounts($params); |
---|
54 | |
---|
55 | if( $result['status']){ |
---|
56 | $result = $this->imap_functions->save_shared_account($params); |
---|
57 | } |
---|
58 | |
---|
59 | return $result; |
---|
60 | } |
---|
61 | |
---|
62 | function get($params) |
---|
63 | { |
---|
64 | if (!$this->functions->check_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid'], 'list_institutional_accounts')) |
---|
65 | { |
---|
66 | $return['status'] = false; |
---|
67 | $return['msg'] = $this->functions->lang('You do not have right to list institutional accounts') . "."; |
---|
68 | return $return; |
---|
69 | } |
---|
70 | |
---|
71 | $input = $params['input']; |
---|
72 | $justthese = array("cn", "mail", "uid"); |
---|
73 | $trs = array(); |
---|
74 | |
---|
75 | foreach ($this->manager_contexts as $idx=>$context) |
---|
76 | { |
---|
77 | $shared_accounts = ldap_search($this->ldap, $context, ("(&(phpgwAccountType=s)(|(mail=$input*)(cn=*$input*)))"), $justthese); |
---|
78 | $entries = ldap_get_entries($this->ldap, $shared_accounts); |
---|
79 | |
---|
80 | for ($i=0; $i<$entries['count']; $i++) |
---|
81 | { |
---|
82 | $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>"; |
---|
83 | $trs[$tr] = $entries[$i]['cn'][0]; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | $trs_string = ''; |
---|
88 | if (count($trs)) |
---|
89 | { |
---|
90 | natcasesort($trs); |
---|
91 | foreach ($trs as $tr=>$cn) |
---|
92 | { |
---|
93 | $trs_string .= $tr; |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | $return['status'] = 'true'; |
---|
98 | $return['trs'] = $trs_string; |
---|
99 | return $return; |
---|
100 | } |
---|
101 | |
---|
102 | function get_data($params) |
---|
103 | { |
---|
104 | $return = $this->ldap_functions->get_shared_account_data($params); |
---|
105 | $owners_acl = $this->imap_functions->getaclfrombox($params); |
---|
106 | $quota = $this->imap_functions->get_user_info($params['uid']); |
---|
107 | $return['mailquota'] = $quota['mailquota']; |
---|
108 | $return['display_empty_inbox'] = $this->functions->check_acl($_SESSION['phpgw_session']['session_lid'],'empty_shared_accounts_inbox') ? 'block' : 'none'; |
---|
109 | $return['allow_edit_shared_account_acl'] = $this->functions->check_acl($_SESSION['phpgw_session']['session_lid'],'edit_shared_accounts_acl'); |
---|
110 | $return['mailquota_used'] = $quota['mailquota_used']; |
---|
111 | $i = 0; |
---|
112 | error_log( var_export( $owners_acl, true ), 3, '/tmp/log' ); |
---|
113 | if( is_array($owners_acl) ){ |
---|
114 | foreach($owners_acl as $key => $value) |
---|
115 | { |
---|
116 | $cn = $this->ldap_functions->uid2cn($key); |
---|
117 | $return['owners_options'] .= '<option value='. $key .'>' . $cn . '</option>'; |
---|
118 | $return['owners'][$i] .= $key; |
---|
119 | $return['owners_acl'][$i] .= $value; |
---|
120 | $i++; |
---|
121 | } |
---|
122 | } else { |
---|
123 | $return['owners_options'] = false; |
---|
124 | $return['owners'] = false; |
---|
125 | $return['owners_acl'] = false; |
---|
126 | } |
---|
127 | error_log( var_export( $return, true ), 3, '/tmp/log' ); |
---|
128 | return json_encode( $return ); |
---|
129 | } |
---|
130 | function delete($params){ |
---|
131 | $result = $this->ldap_functions->delete_shared_account_data($params); |
---|
132 | if( $result['status'] ) $result = $this->imap_functions->delete_mailbox($params['uid']); |
---|
133 | return $result; |
---|
134 | } |
---|
135 | //Get the shared uid from mail |
---|
136 | function get_shared_mail2uid($params){ |
---|
137 | list($uid) = explode("@",$params['mail']); |
---|
138 | if( preg_match("/^(ou|dc)=(\w+),.*/", $params['context'], $match) ){ |
---|
139 | $uid = $uid."_".$match[2]; |
---|
140 | } |
---|
141 | return $uid; |
---|
142 | } |
---|
143 | function get_shared_dn2uid($dn){ |
---|
144 | $uid = ""; |
---|
145 | list($uid) = explode(",", str_replace("uid=","", $dn)); |
---|
146 | return $uid; |
---|
147 | } |
---|
148 | function empty_inbox($params){ |
---|
149 | $params['uid'] = $this->get_shared_dn2uid($params['uid']); |
---|
150 | return $this->imap_functions->empty_shared_account_inbox($params); |
---|
151 | } |
---|
152 | |
---|
153 | } |
---|
154 | ?> |
---|