[2] | 1 | <?php |
---|
[5509] | 2 | /*************************************************************************** |
---|
| 3 | * Expresso Livre * |
---|
| 4 | * http://www.expressolivre.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 | |
---|
[63] | 12 | include_once('class.functions.inc.php'); |
---|
| 13 | |
---|
[2] | 14 | class imap_functions |
---|
| 15 | { |
---|
[63] | 16 | var $functions; |
---|
[2] | 17 | var $imap; |
---|
| 18 | var $imapDelimiter; |
---|
| 19 | var $imap_admin; |
---|
| 20 | var $imap_passwd; |
---|
| 21 | var $imap_server; |
---|
| 22 | var $imap_port; |
---|
[414] | 23 | var $imap_trashfolder; |
---|
| 24 | var $imap_sentfolder; |
---|
| 25 | var $imap_draftsfolder; |
---|
| 26 | var $imap_spamfolder; |
---|
[2] | 27 | |
---|
| 28 | function imap_functions(){ |
---|
[438] | 29 | $this->functions = new functions; |
---|
[2] | 30 | $this->imap_admin = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminUsername']; |
---|
| 31 | $this->imap_passwd = $_SESSION['phpgw_info']['expresso']['email_server']['imapAdminPW']; |
---|
| 32 | $this->imap_server = $_SESSION['phpgw_info']['expresso']['email_server']['imapServer']; |
---|
| 33 | $this->imap_port = $_SESSION['phpgw_info']['expresso']['email_server']['imapPort']; |
---|
[438] | 34 | $this->imap_trashfolder = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultTrashFolder'] ? $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultTrashFolder'] : str_replace("*","", $this->functions->lang("trash")); |
---|
| 35 | $this->imap_sentfolder = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSentFolder'] ? $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSentFolder'] : str_replace("*","", $this->functions->lang("sent")); |
---|
| 36 | $this->imap_draftsfolder = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultDraftsFolder'] ? $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultDraftsFolder'] : str_replace("*","", $this->functions->lang("drafts")); |
---|
| 37 | $this->imap_spamfolder = $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSpamFolder'] ? $_SESSION['phpgw_info']['expresso']['email_server']['imapDefaultSpamFolder'] : str_replace("*","", $this->functions->lang("spam")); |
---|
[2] | 38 | $this->imapDelimiter= $_SESSION['phpgw_info']['expresso']['email_server']['imapDelimiter']; |
---|
| 39 | $this->imap = imap_open('{'.$this->imap_server.':'.$this->imap_port.'/novalidate-cert}', $this->imap_admin, $this->imap_passwd, OP_HALFOPEN); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | function create($uid, $mailquota) |
---|
| 43 | { |
---|
| 44 | if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid)) |
---|
| 45 | { |
---|
| 46 | $error = imap_errors(); |
---|
[414] | 47 | if ($error[0] == 'Mailbox already exists') |
---|
| 48 | { |
---|
| 49 | $result['status'] = true; |
---|
| 50 | } |
---|
| 51 | else |
---|
| 52 | { |
---|
| 53 | $result['status'] = false; |
---|
| 54 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(INBOX) ($uid):" . $error[0]; |
---|
| 55 | } |
---|
[2] | 56 | return $result; |
---|
| 57 | } |
---|
[414] | 58 | if ( (!empty($this->imap_sentfolder)) && (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_sentfolder)) ) |
---|
[2] | 59 | { |
---|
| 60 | $error = imap_errors(); |
---|
| 61 | $result['status'] = false; |
---|
[414] | 62 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_sentfolder."):" . $error[0]; |
---|
[2] | 63 | return $result; |
---|
| 64 | } |
---|
[414] | 65 | if ( (!empty($this->imap_draftsfolder)) && (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_draftsfolder)) ) |
---|
[2] | 66 | { |
---|
| 67 | $error = imap_errors(); |
---|
| 68 | $result['status'] = false; |
---|
[414] | 69 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_draftsfolder."):" . $error[0]; |
---|
[2] | 70 | return $result; |
---|
| 71 | } |
---|
[414] | 72 | if ( (!empty($this->imap_trashfolder)) && (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_trashfolder)) ) |
---|
[2] | 73 | { |
---|
| 74 | $error = imap_errors(); |
---|
| 75 | $result['status'] = false; |
---|
[414] | 76 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_trashfolder."):" . $error[0]; |
---|
[2] | 77 | return $result; |
---|
| 78 | } |
---|
[5133] | 79 | /* Esperando correção do william (prognus) sobre a utilização do DSPAM |
---|
| 80 | if (!empty($this->imap_sentfolder)) |
---|
[414] | 81 | { |
---|
| 82 | if (!imap_createmailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid . $this->imapDelimiter . $this->imap_spamfolder)) |
---|
| 83 | { |
---|
| 84 | $error = imap_errors(); |
---|
| 85 | $result['status'] = false; |
---|
| 86 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(".$this->imap_spamfolder."):" . $error[0]; |
---|
| 87 | return $result; |
---|
[1523] | 88 | } |
---|
| 89 | } |
---|
[5133] | 90 | */ |
---|
[414] | 91 | |
---|
[2] | 92 | if (!imap_set_quota($this->imap,"user" . $this->imapDelimiter . $uid, ($mailquota*1024))) |
---|
| 93 | { |
---|
| 94 | $error = imap_errors(); |
---|
| 95 | $result['status'] = false; |
---|
[414] | 96 | $result['msg'] = $this->functions->lang('Error on function') . " imap_functions->create(imap_set_quota):" . $error[0]; |
---|
[2] | 97 | return $result; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | $result['status'] = true; |
---|
| 101 | return $result; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | function get_user_info($uid) |
---|
| 105 | { |
---|
[5133] | 106 | $get_quota = @imap_get_quotaroot($this->imap,"user" . $this->imapDelimiter . $uid); |
---|
[2] | 107 | |
---|
| 108 | if (count($get_quota) == 0) |
---|
| 109 | { |
---|
| 110 | $quota['mailquota'] = '-1'; |
---|
| 111 | $quota['mailquota_used'] = '-1'; |
---|
| 112 | } |
---|
| 113 | else |
---|
| 114 | { |
---|
[63] | 115 | $quota['mailquota'] = round (($get_quota['limit'] / 1024), 2); |
---|
| 116 | $quota['mailquota_used'] = round (($get_quota['usage'] / 1024), 2); |
---|
[2] | 117 | } |
---|
| 118 | return $quota; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | function change_user_quota($uid, $quota) |
---|
| 122 | { |
---|
[520] | 123 | $result['status'] = true; |
---|
| 124 | |
---|
| 125 | if (!imap_set_quota($this->imap,"user" . $this->imapDelimiter . $uid, ($quota*1024)) ) |
---|
| 126 | { |
---|
| 127 | $result['status'] = false; |
---|
| 128 | $result['msg'] = $this->functions->lang('it was not possible to change users mailbox quota') . ".\n"; |
---|
| 129 | $result['msg'] .= $this->functions->lang('Server returns') . ': ' . imap_last_error(); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | return $result; |
---|
[2] | 133 | } |
---|
| 134 | |
---|
[1913] | 135 | function delete_mailbox($uid) |
---|
[2] | 136 | { |
---|
| 137 | $result['status'] = true; |
---|
| 138 | |
---|
| 139 | //Seta acl imap para poder deletar o user. |
---|
| 140 | // Esta sem tratamento de erro, pois o retorno da funcao deve ter um bug. |
---|
| 141 | imap_setacl($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, 'c'); |
---|
| 142 | |
---|
| 143 | if (!imap_deletemailbox($this->imap, '{'.$this->imap_server.'}' . "user" . $this->imapDelimiter . $uid)) |
---|
| 144 | { |
---|
| 145 | $result['status'] = false; |
---|
[1913] | 146 | $result['msg'] = $this->functions->lang('it was not possible to delete mailbox') . ".\n"; |
---|
[508] | 147 | $result['msg'] .= $this->functions->lang('Server returns') . ': ' . imap_last_error(); |
---|
[2] | 148 | } |
---|
[7552] | 149 | |
---|
[2] | 150 | return $result; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | function rename_mailbox($old_mailbox, $new_mailbox) |
---|
| 154 | { |
---|
[508] | 155 | $result['status'] = true; |
---|
| 156 | |
---|
[5133] | 157 | if (!$quota = @imap_get_quotaroot($this->imap, 'user' . $this->imapDelimiter . $old_mailbox)) |
---|
[508] | 158 | { |
---|
| 159 | $result['status'] = false; |
---|
| 160 | $result['msg'] = $this->functions->lang("Error getting user quota. Process aborted.\n") . $this->functions->lang('Server returns') . ': ' . imap_last_error(); |
---|
| 161 | return $result; |
---|
| 162 | } |
---|
[396] | 163 | $limit = $quota['STORAGE']['limit']; |
---|
[508] | 164 | $usage = $quota['STORAGE']['usage']; |
---|
[396] | 165 | |
---|
[508] | 166 | if ($usage >= $limit) |
---|
| 167 | { |
---|
| 168 | if (! @imap_set_quota($this->imap, 'user' . $this->imapDelimiter . $old_mailbox, (int)($usage+10240)) ) |
---|
| 169 | { |
---|
| 170 | $result['status'] = false; |
---|
| 171 | $result['msg'] = $this->functions->lang("Error increasing user quota. Process aborted.\n") . $this->functions->lang('Server returns') . ': ' . imap_last_error(); |
---|
| 172 | return $result; |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | if (! @imap_renamemailbox($this->imap, |
---|
[2] | 178 | '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox, |
---|
[508] | 179 | '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $new_mailbox) ) |
---|
[2] | 180 | { |
---|
| 181 | $result['status'] = false; |
---|
[508] | 182 | $result['msg'] = $this->functions->lang('Server returns') . ': ' . imap_last_error(); |
---|
| 183 | |
---|
[2] | 184 | } |
---|
[508] | 185 | |
---|
| 186 | |
---|
| 187 | if ($usage >= $limit) |
---|
[396] | 188 | { |
---|
[508] | 189 | if (! @imap_set_quota($this->imap, 'user' . $this->imapDelimiter . $new_mailbox, (int)($limit)) ) |
---|
| 190 | { |
---|
| 191 | $result['status'] = false; |
---|
| 192 | $result['msg'] .= $this->functions->lang("Error returning user quota.\n") . $this->functions->lang('Server returns') . ': ' . imap_last_error(); |
---|
| 193 | |
---|
| 194 | @imap_renamemailbox($this->imap, |
---|
| 195 | '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $new_mailbox, |
---|
| 196 | '{'.$this->imap_server.':'.$this->imap_port.'}user' . $this->imapDelimiter . $old_mailbox); |
---|
| 197 | } |
---|
[396] | 198 | } |
---|
[508] | 199 | |
---|
[2] | 200 | return $result; |
---|
| 201 | } |
---|
[1913] | 202 | function empty_user_inbox($params){ |
---|
| 203 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox')) |
---|
| 204 | { |
---|
| 205 | $result['status'] = false; |
---|
| 206 | $result['msg'] = $this->functions->lang('You do not have access to clean an user inbox'); |
---|
| 207 | return $result; |
---|
| 208 | } else return $this->empty_inbox($params); |
---|
| 209 | |
---|
| 210 | } |
---|
| 211 | function empty_shared_account_inbox($params){ |
---|
| 212 | if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_shared_accounts_inbox')) |
---|
| 213 | { |
---|
| 214 | $result['status'] = false; |
---|
| 215 | $result['msg'] = $this->functions->lang('You do not have right to empty an shared account inbox'); |
---|
| 216 | return $result; |
---|
| 217 | } else return $this->empty_inbox($params); |
---|
| 218 | } |
---|
[63] | 219 | function empty_inbox($params) |
---|
| 220 | { |
---|
| 221 | // Verifica o acesso do gerente |
---|
[1913] | 222 | if (!($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_user_inbox') || |
---|
| 223 | $this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'empty_shared_accounts_inbox') |
---|
| 224 | )) |
---|
[63] | 225 | { |
---|
| 226 | $result['status'] = false; |
---|
[1913] | 227 | $result['msg'] = $this->functions->lang('You do not have access to clean an inbox'); |
---|
[63] | 228 | return $result; |
---|
| 229 | } |
---|
[1913] | 230 | |
---|
| 231 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
[63] | 232 | { |
---|
| 233 | $imap_options = '/tls/novalidate-cert'; |
---|
| 234 | } |
---|
| 235 | else |
---|
| 236 | { |
---|
| 237 | $imap_options = '/notls/novalidate-cert'; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | |
---|
| 241 | $result['status'] = true; |
---|
| 242 | $uid = $params['uid']; |
---|
| 243 | |
---|
| 244 | $return_setacl = imap_setacl($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, 'lrswipcda'); |
---|
| 245 | |
---|
| 246 | if ($return_setacl) |
---|
| 247 | { |
---|
| 248 | $mbox_stream = imap_open('{'.$this->imap_server.':'.$this->imap_port.$imap_options .'}user'. $this->imapDelimiter . $uid, $this->imap_admin, $this->imap_passwd); |
---|
| 249 | |
---|
| 250 | $check = imap_mailboxmsginfo($mbox_stream); |
---|
| 251 | $inbox_size = (string)(round ((($check->Size)/(1024*1024)), 2)); |
---|
| 252 | |
---|
| 253 | $return_imap_delete = imap_delete($mbox_stream,'1:*'); |
---|
| 254 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
| 255 | |
---|
| 256 | imap_setacl ($this->imap, "user" . $this->imapDelimiter . $uid, $this->imap_admin, ''); |
---|
| 257 | |
---|
| 258 | if ($return_imap_delete) |
---|
| 259 | { |
---|
| 260 | $result['inbox_size'] = $inbox_size; |
---|
| 261 | |
---|
[5133] | 262 | $get_user_quota = @imap_get_quotaroot($this->imap,"user" . $this->imapDelimiter . $uid); |
---|
[63] | 263 | $result['mailquota_used'] = (string)(round(($get_user_quota['usage']/1024), 2)); |
---|
| 264 | } |
---|
| 265 | else |
---|
| 266 | { |
---|
| 267 | $result['status'] = false; |
---|
[1913] | 268 | $result['msg'] = $this->functions->lang('It was not possible clean the inbox') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error(); |
---|
[63] | 269 | } |
---|
| 270 | } |
---|
| 271 | else |
---|
| 272 | { |
---|
| 273 | $result['status'] = false; |
---|
[414] | 274 | $result['msg'] = $this->functions->lang('It was not possible to modify the users acl') . ".\n" . $this->functions->lang('Server returns') . ': ' . imap_last_error(); |
---|
[63] | 275 | } |
---|
| 276 | return $result; |
---|
| 277 | } |
---|
[1913] | 278 | function getaclfrombox($params) |
---|
| 279 | { |
---|
| 280 | $boxacl = $params['uid']; |
---|
| 281 | |
---|
| 282 | $return = array(); |
---|
| 283 | |
---|
| 284 | $mbox_acl = imap_getacl($this->imap, "user" . $this->imapDelimiter . $boxacl); |
---|
| 285 | |
---|
| 286 | foreach ($mbox_acl as $user => $acl) |
---|
| 287 | { |
---|
| 288 | if ($user != $boxacl ) |
---|
| 289 | { |
---|
| 290 | $return[$user] = $acl; |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | return $return; |
---|
| 294 | } |
---|
| 295 | function setaclfrombox($user, $acl, $mailbox) |
---|
| 296 | { |
---|
| 297 | $serverString = '{'.$this->imap_server.':'.$this->imap_port.'/novalidate-cert}'; |
---|
| 298 | $mailboxes_list = imap_getmailboxes($this->imap, $serverString, "user".$this->imapDelimiter.$mailbox.$this->imapDelimiter."*"); |
---|
| 299 | $result = Array(); |
---|
| 300 | $result['status'] = true; |
---|
| 301 | if (is_array($mailboxes_list)) |
---|
| 302 | { |
---|
| 303 | $folder = str_replace($serverString, "", imap_utf7_encode("user".$this->imapDelimiter.$mailbox)); |
---|
| 304 | $folder = str_replace("&-", "&", $folder); |
---|
| 305 | |
---|
| 306 | if (imap_setacl ($this->imap, $folder, $user, $acl) ) { |
---|
| 307 | foreach ($mailboxes_list as $key => $val) |
---|
| 308 | { |
---|
| 309 | $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); |
---|
| 310 | $folder = str_replace("&-", "&", $folder); |
---|
| 311 | if (!imap_setacl ($this->imap, $folder, $user, $acl)) |
---|
| 312 | { |
---|
| 313 | $result['status'] = false; |
---|
| 314 | $result['msg'] = $this->functions->lang('Error on function') . ' imap_functions->setaclfrombox: imap_setacl'; |
---|
| 315 | $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . imap_last_error(); |
---|
| 316 | break; |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | } else { |
---|
| 320 | $result['status'] = false; |
---|
| 321 | $result['msg'] = $this->functions->lang('Error on function') . ' imap_functions->setaclfrombox: imap_setacl'; |
---|
| 322 | $result['msg'] .= "\n" . $this->functions->lang('Server return') . ': ' . imap_last_error(); |
---|
[7769] | 323 | // break; |
---|
[1913] | 324 | } |
---|
| 325 | } |
---|
[5133] | 326 | |
---|
| 327 | if( $result['status'] ) |
---|
| 328 | $this->sendACLAdvice( $user, $acl, $mailbox ); |
---|
| 329 | |
---|
[1913] | 330 | return $result; |
---|
| 331 | } |
---|
| 332 | function save_shared_account($params){ |
---|
| 333 | //Rename mailbox |
---|
| 334 | $result = Array(); |
---|
| 335 | $result['status'] = true; |
---|
| 336 | if($params['uid'] != $params['old_uid'] ){ |
---|
| 337 | $result = $this->rename_mailbox($params['old_uid'], $params['uid']); |
---|
| 338 | if(!$result['status']) return $result; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | //Begin edit Quota |
---|
| 342 | $quota = $this->get_user_info($params['uid'] ); |
---|
| 343 | |
---|
| 344 | if ( $quota['mailquota'] != $params['mailquota'] ){ |
---|
| 345 | if(!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_shared_accounts_quote') ) |
---|
| 346 | { |
---|
| 347 | $result['status'] = false; |
---|
| 348 | $result['msg'] = $this->functions->lang('You do not have access to edit an shared account inbox quota'); |
---|
| 349 | return $result; |
---|
| 350 | } else $this->change_user_quota($params['old_uid'], $params['mailquota']); |
---|
| 351 | } |
---|
| 352 | //End Edit Quota |
---|
| 353 | |
---|
| 354 | /* Begin Set ACL */ |
---|
| 355 | //Old users set in the box |
---|
| 356 | $owners_acl_old = $this->getaclfrombox($params); |
---|
| 357 | //new settings |
---|
[1983] | 358 | //necessario devido a um bug do serialize do javascript do connector zera uma string |
---|
| 359 | //serializada "N;", diferente da serializada do php "a:0:{}" |
---|
| 360 | |
---|
| 361 | if( $params['owners_acl'] != "N;" ){ |
---|
| 362 | $owners_acl_new = unserialize($params['owners_acl']); |
---|
| 363 | } else { |
---|
| 364 | $owners_acl_new = Array(); |
---|
| 365 | } |
---|
[1913] | 366 | |
---|
| 367 | $owners_to_remove = array_diff_assoc($owners_acl_old,$owners_acl_new); |
---|
| 368 | $owners_to_add = array_diff_assoc($owners_acl_new,$owners_acl_old); |
---|
[1983] | 369 | |
---|
[1913] | 370 | //Find modified users |
---|
| 371 | $tmp_update = array_diff_assoc($owners_acl_old,$owners_to_remove); |
---|
| 372 | $owners_to_update = Array(); |
---|
| 373 | foreach($tmp_update as $user => $acl){ |
---|
| 374 | if($owners_acl_old[$user] != $acl){ |
---|
| 375 | $owners_to_update[$user] = $acl; |
---|
| 376 | } |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | //Check Modify manage acl |
---|
| 380 | |
---|
| 381 | if( (count($owners_to_remove) > 0 || count($owners_to_add) > 0 || count($owners_to_update) > 0) && !$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'edit_shared_accounts_acl') ){ |
---|
| 382 | $result['status'] = false; |
---|
[1983] | 383 | $result['msg'] = $this->functions->lang('You do not have access to edit an shared account inbox acl'); |
---|
| 384 | return $result; |
---|
[1913] | 385 | } |
---|
[7769] | 386 | |
---|
| 387 | if(count($owners_to_remove) > 0) |
---|
| 388 | { |
---|
| 389 | foreach($owners_to_remove as $user => $acl) |
---|
| 390 | { |
---|
| 391 | $this->functions->write_log("User removed from the shared account",'USER: '.$user.' - SHARED ACCOUNT: '.$params['uid']); |
---|
| 392 | } |
---|
| 393 | } |
---|
| 394 | if(count($owners_to_add) > 0) |
---|
| 395 | { |
---|
| 396 | foreach($owners_to_add as $user => $acl) |
---|
| 397 | { |
---|
| 398 | $this->functions->write_log("User added from the shared account",'USER: '.$user.' - SHARED ACCOUNT: '.$params['uid']); |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | |
---|
[5133] | 402 | //file_put_contents("/tmp/saida", "old ".print_r($owners_acl_old, true)."remove ".print_r($owners_to_remove, true)."add ".print_r($owners_to_add, true)."update ".print_r($owners_to_update, true)); |
---|
[1913] | 403 | if( is_array($owners_acl_new)){ |
---|
| 404 | foreach($owners_to_remove as $user => $acl){ |
---|
| 405 | $params['user'] = $user; |
---|
[1983] | 406 | $params['acl'] = ""; |
---|
| 407 | $user = $params['user']; |
---|
| 408 | $result = $this->setaclfrombox($user,"",$params['uid']); |
---|
[1913] | 409 | } |
---|
| 410 | //add new users |
---|
| 411 | foreach($owners_to_add as $user => $acl){ |
---|
| 412 | $params['user'] = $user; |
---|
| 413 | $params['acl'] = $acl; |
---|
| 414 | $result = $this->setaclfrombox($user,$acl,$params['uid']); |
---|
| 415 | } |
---|
| 416 | //update users |
---|
| 417 | foreach($owners_to_update as $user => $acl){ |
---|
| 418 | $params['user'] = $user; |
---|
| 419 | $params['acl'] = $acl; |
---|
| 420 | $result = $this->setaclfrombox($user,$acl,$params['uid']); |
---|
| 421 | } |
---|
| 422 | } |
---|
| 423 | /* End Set Acl */ |
---|
| 424 | return $result; |
---|
| 425 | } |
---|
[5133] | 426 | |
---|
| 427 | function sendACLAdvice( $user, $acls, $shared_account ) |
---|
| 428 | { |
---|
| 429 | //acl treat |
---|
| 430 | $acl_labels = array( 'lrs' => 'read messages from this shared account', |
---|
| 431 | 'd' => 'delete/move messages from this shared account', |
---|
| 432 | 'wi' => 'create/add messages in this shared account', |
---|
| 433 | 'a' => 'send message by this shared account', |
---|
| 434 | 'p' => 'save sent messages in this shared account', |
---|
| 435 | 'c' => 'create or delete folders on this shared account' ); |
---|
| 436 | |
---|
| 437 | $acl_found = array(); |
---|
| 438 | |
---|
| 439 | foreach( $acl_labels as $acl => $label ) |
---|
| 440 | { |
---|
| 441 | if( strpos( $acls, $acl ) !== false ) |
---|
| 442 | { |
---|
| 443 | $acl_found[] = $this->functions->lang( $label ); |
---|
| 444 | } |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | $acl = implode( "<br/>", $acl_found ); |
---|
| 448 | |
---|
| 449 | if( empty( $acl ) ) |
---|
| 450 | return; |
---|
| 451 | |
---|
| 452 | //body mail template generation |
---|
| 453 | $body = $this->getTemplate( "body_email.tpl", array( "user" => $user, |
---|
| 454 | "acl" => $acl, |
---|
| 455 | "shared_account" => $shared_account ) ); |
---|
| 456 | |
---|
| 457 | //ldap fetch mail to |
---|
| 458 | require_once('class.ldap_functions.inc.php'); |
---|
| 459 | |
---|
[7769] | 460 | // if( !$ldap ) |
---|
| 461 | // { |
---|
[5133] | 462 | $ldap = new ldap_functions(); |
---|
[7769] | 463 | // } |
---|
[5133] | 464 | |
---|
| 465 | $to = $ldap->uid2mailforwardingaddress( $user ); |
---|
| 466 | $to = $to['mail']; |
---|
| 467 | |
---|
| 468 | //mail send service |
---|
| 469 | $mail = ServiceLocator::getService( 'mail' ); |
---|
| 470 | $mail->sendMail( $to, false, $this->functions->lang("Your user was add/updated in the shared account"), $body ); |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | function getTemplate( $tpls, $macros, $target = false ) |
---|
| 474 | { |
---|
[5850] | 475 | require_once( ROOT.'/header.inc.php' ); |
---|
[5133] | 476 | |
---|
| 477 | $template = CreateObject( 'phpgwapi.Template', PHPGW_APP_TPL ); |
---|
| 478 | |
---|
| 479 | if( !is_array( $tpls ) ) |
---|
| 480 | { |
---|
| 481 | $tpls = array( $tpls ); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | $keys = array_keys( $tpls ); |
---|
| 485 | |
---|
[7769] | 486 | if( !array_diff_key( $tpls, array_keys( $keys ) ) ) |
---|
[5133] | 487 | { |
---|
| 488 | $newTpls = array(); |
---|
| 489 | |
---|
| 490 | foreach( $tpls as $tpl ) |
---|
| 491 | { |
---|
| 492 | $key = basename( $tpl ); |
---|
| 493 | |
---|
| 494 | $dot = strrpos( $key, '.' ); |
---|
| 495 | |
---|
| 496 | if( $dot !== false ) |
---|
| 497 | { |
---|
| 498 | $key = substr( $key, 0, $dot ); |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | $newTpls[ $key ] = $tpl; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | $tpls = $newTpls; |
---|
| 505 | |
---|
| 506 | $keys = array_keys( $tpls ); |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | $template->set_file( $tpls ); |
---|
| 510 | |
---|
| 511 | $target = $target ? $tpls[ $target ] : $keys[0]; |
---|
| 512 | |
---|
| 513 | $template->set_var( $this->functions->make_dinamic_lang( $template, $target ) ); |
---|
| 514 | $template->set_var( $macros ); |
---|
| 515 | |
---|
| 516 | return $template->fp( 'out', $target ); |
---|
| 517 | } |
---|
[2] | 518 | } |
---|