countFiles = 1; isValidCallback = false; function create_shared_accounts() { // select_owners = Element('ea_select_owners'); hidden_owners_acl = Element('owners_acls'); hidden_owners_calendar_acl = Element('owners_calendar_acls'); select_owners = Element('ea_select_owners'); for(var i = 0;i < select_owners.options.length; i++) select_owners.options[i].selected = true; hidden_owners_acl.value = admin_connector.serialize(sharemailbox.ownersAcl); hidden_owners_calendar_acl.value = admin_connector.serialize(sharemailbox.ownersCalendarAcl); cExecuteForm ("$this.shared_accounts.create", document.forms['shared_accounts_form'], handler_create_shared_accounts); hidden_owners_acl.value = ""; isValidCallback = true; } function handler_create_shared_accounts(data_return) { handler_create_shared_accounts2(data_return); return; } function handler_create_shared_accounts2(data_return) { if (data_return && !data_return.status) { write_msg(data_return.msg, 'error'); } else { if(sharemailbox.ownersExpressoCalendarAcl && isValidCallback){ isValidCallback = false; calback(); } close_lightbox(); write_msg(get_lang('Shared account successful created') + '.', 'normal'); } return; } function empty_inbox(uid) { var action = get_lang('Cleanned user mailbox'); var handler_write_log = function(){} var handler_empty_inbox = function(data) { if (!data.status) alert(data.msg); else{ cExecute ('$this.user.write_log_from_ajax&_action='+action+'&userinfo='+uid, handler_write_log); alert(get_lang('Emptied') +' '+ data.inbox_size + ' ' + get_lang('MB from user inbox')); document.getElementById('mailquota_used').value = data.mailquota_used; } } cExecute ('$this.shared_accounts.empty_inbox&uid='+Element('anchor').value, handler_empty_inbox); } function set_onload() { if(sharemailbox.ownersAcl) { delete sharemailbox.ownersAcl; sharemailbox.ownersAcl = new Array(); } if(sharemailbox.ownersCalendarAcl) { delete sharemailbox.ownersAcl; sharemailbox.ownersAcl = new Array(); } get_associated_domain(Element('ea_combo_org').value); } function search_organization(key, element) { var organizations = Element(element); var RegExp_org = new RegExp("\\b"+key, "i"); for(i = 0; i < organizations.length; i++) { if (RegExp_org.test(organizations[i].text)) { organizations[i].selected = true; return; } } } function sinc_combos_org(context) { combo_org_available_users = Element('ea_combo_org_available_users'); for (i=0; i" + select_available_users.options[i].text + ""; } } else { if ( (select_owners.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) { new_options += "'; Element('ea_select_owners').outerHTML = Element('ea_select_owners').outerHTML; } } delete sharemailbox.currentPemissions[undefined]; } } } else write_msg(data.msg, 'error'); } cExecute ('$this.shared_accounts.get_data&uid='+uid, handle_edit_shared_account); } function save_shared_accounts() { if (is_ie){ var i = 0; while (document.forms(i).name != "shared_accounts_form"){ i++ } form = document.forms(i); } else form = document.forms["shared_accounts_form"]; hidden_owners_calendar_acl = Element('owners_calendar_acls'); hidden_owners_acl = Element('owners_acls'); select_owners = Element('ea_select_owners'); for(var i = 0;i < select_owners.options.length; i++){ var user = select_owners.options[i].value; select_owners.options[i].value = user; } hidden_owners_acl.value = admin_connector.serialize(sharemailbox.ownersAcl); hidden_owners_calendar_acl.value = admin_connector.serialize(sharemailbox.ownersCalendarAcl); cExecuteForm ("$this.shared_accounts.save", form, handler_save_shared_accounts); get_shared_accounts(Element('ea_shared_account_search').value); if(sharemailbox.ownersExpressoCalendarAcl) calback(); } function handler_save_shared_accounts(data_return) { handler_save_shared_accounts2(data_return); return; } function handler_save_shared_accounts2(data_return) { if(data_return){ if (data_return.status){ hidden_owners_acl.value = ""; close_lightbox(); write_msg(get_lang('Shared account successful saved') + '.', 'normal'); }else write_msg(data_return.msg , 'error'); } return; } function callbackDelete(sharedUser){ if(!!sharedUser && $.isArray(sharedUser)) for(var i = 0; i < sharedUser.length; i++) if(sharedUser[i].phpgwAccountType == 's'){ sharedUser = sharedUser[i]; break; } var signature = DataLayer.get('calendarSignature', { filter: ['=','user', sharedUser.id] }); signature = $.isArray(signature) ? signature[0] : signature; DataLayer.remove('calendarSignature', signature.id) DataLayer.commit(); } function calback(){ var sharedUser = DataLayer.get('user', { filter: ['=','mail',$('#mail').val()] }); if(!!sharedUser && $.isArray(sharedUser)) for(var i = 0; i < sharedUser.length; i++) if(sharedUser[i].phpgwAccountType == 's'){ sharedUser = sharedUser[i]; break; } if(!!!sharemailbox.currentPemissions[sharedUser.id]) DataLayer.put('calendarSignature', { user: sharedUser.id, calendar: { timezone: 'America/Sao_Paulo', name: $('#cn').val(), location : $('#sharedAccountsLocation').val() + '/' + $('#cn').val(), description : $('#cn').val() }, isOwner: '1', fontColor: '000000', backgroundColor: 'f1efac', borderColor: 'eddb21' }); var returns = function(data){ var calendar = ''; if(data){ for(var i in data) if(i.indexOf('calendar:') >= 0) calendar = data[i].id; }else{ calendar = DataLayer.get('calendarSignature', { filter: ['=','user', sharedUser.id] }); calendar = calendar[0].calendar; } $.each(sharemailbox.ownersExpressoCalendarAcl, function(user, acl) { var usuario = DataLayer.get('user', { filter: ['=','uid',user], criteria: { notExternal: true } }); if($.isArray(usuario)) usuario = usuario[0]; DataLayer.put('calendarToPermission', DataLayer.merge({ user: usuario.id, type: '0', acl: acl, calendar: calendar }, !!sharemailbox.currentPemissions[usuario.uid] ? { id: sharemailbox.currentPemissions[usuario.uid] } : {})); if(!!!sharemailbox.currentPemissions[usuario.uid]) DataLayer.put('calendarSignature', { user: usuario.id, calendar: calendar, isOwner: '0', fontColor: '000000', backgroundColor: 'f1efac', borderColor: 'eddb21' }); }) DataLayer.commit(); }; if(!!sharemailbox.currentPemissions[sharedUser.id]) returns(false); else DataLayer.commit(false, false, returns); } function delete_shared_accounts(uid, mail) { if (!confirm(get_lang('Are you sure that you want to delete this shared account') + "?")) return; var user = {}; if(sharemailbox.ownersExpressoCalendarAcl) user = DataLayer.get('user', { filter: ['=','mail',mail] }); var handle_delete_shared_account = function(data_return) { if (!data_return.status) { write_msg(data_return.msg, 'error'); } else { if(sharemailbox.ownersExpressoCalendarAcl){ callbackDelete(user); } write_msg(get_lang('Shared account successful deleted') + '.', 'normal'); get_shared_accounts(Element('ea_shared_account_search').value); } return; } cExecute ('$this.shared_accounts.delete&uid='+uid, handle_delete_shared_account); } function cShareMailbox() { this.arrayWin = new Array(); this.el; this.alert = false; this.ownersAcl = new Array(); this.ownersCalendarAcl = new Array(); this.ownersExpressoCalendarAcl = {}; this.currentPemissions = {}; } cShareMailbox.prototype.get_available_users = function(context) { var handler_get_available_users = function(data) { select_available_users = document.getElementById('em_select_available_users'); //Limpa o select for(var i=0; i 0)) { // Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio. select_available_users.innerHTML = '#' + data; select_available_users.outerHTML = select_available_users.outerHTML; select_available_users.disabled = false; select_available_users_clone = document.getElementById('em_select_available_users').cloneNode(true); document.getElementById('em_input_searchUser').value = ''; } } cExecute ("$this.ldap_functions.get_available_users2&context="+context, handler_get_available_users); } cShareMailbox.prototype.getaclfromuser = function(user) { Element('em_input_readAcl').checked = false; Element('em_input_deleteAcl').checked = false; Element('em_input_writeAcl').checked = false; Element('em_input_sendAcl').checked = false; Element('em_input_folderAcl').checked = false; Element('em_input_readCalendar').checked = false; Element('em_input_writeCalendar').checked = false; Element('em_input_editCalendar').checked = false; Element('em_input_deleteCalendar').checked = false; Element('em_input_restrictCalendar').checked = false; Element('em_input_readExpressoCalendar').checked = false; Element('em_input_writeExpressoCalendar').checked = false; Element('em_input_freebusyExpressoCalendar').checked = false; Element('em_input_deleteExpressoCalendar').checked = false; Element('em_input_editCalendar').disabled = true; Element('em_input_deleteCalendar').disabled = true; Element('em_input_restrictCalendar').disabled = true; if(this.ownersExpressoCalendarAcl[user]) { if (this.ownersExpressoCalendarAcl[user].indexOf('r') >= 0) { Element('em_input_readExpressoCalendar').checked = true; Element('em_input_writeExpressoCalendar').checked = false; Element('em_input_freebusyExpressoCalendar').checked = false; Element('em_input_deleteExpressoCalendar').checked = false; } if (this.ownersExpressoCalendarAcl[user].indexOf('w') >= 0) { Element('em_input_writeExpressoCalendar').checked = true; } if (this.ownersExpressoCalendarAcl[user].indexOf('d') >= 0) { Element('em_input_deleteExpressoCalendar').checked = true; } if (this.ownersExpressoCalendarAcl[user].indexOf('b') >= 0) { Element('em_input_freebusyExpressoCalendar').checked = true; } } if(this.ownersCalendarAcl[user]) { if (this.ownersCalendarAcl[user].indexOf('1-',0) >= 0) { Element('em_input_readCalendar').checked = true; Element('em_input_editCalendar').disabled = false; Element('em_input_deleteCalendar').disabled = false; Element('em_input_restrictCalendar').disabled = false; Element('em_input_readExpressoCalendar').checked = true; Element('em_input_writeExpressoCalendar').checked = false; Element('em_input_freebusyExpressoCalendar').checked = false; Element('em_input_deleteExpressoCalendar').checked = false; } if (this.ownersCalendarAcl[user].indexOf('2-',0) >= 0) { Element('em_input_writeCalendar').checked = true; Element('em_input_writeExpressoCalendar').checked = true; } if (this.ownersCalendarAcl[user].indexOf('4-',0) >= 0) { Element('em_input_editCalendar').checked = true; Element('em_input_writeExpressoCalendar').checked = true; } if (this.ownersCalendarAcl[user].indexOf('8-',0) >= 0) { Element('em_input_deleteCalendar').checked = true; Element('em_input_deleteExpressoCalendar').checked = true; } if (this.ownersCalendarAcl[user].indexOf('16-',0) >= 0) { Element('em_input_restrictCalendar').checked = true; } } if(this.ownersAcl[user]) { if ( (this.ownersAcl[user].indexOf('l',0) >= 0) && (this.ownersAcl[user].indexOf('r',0) >= 0) && (this.ownersAcl[user].indexOf('s',0) >= 0) ) { Element('em_input_sendAcl').disabled = false; Element('em_input_readAcl').checked = true; } else Element('em_input_sendAcl').disabled = true; if ( (this.ownersAcl[user].indexOf('t',0) >= 0) && (this.ownersAcl[user].indexOf('e',0) >= 0) ) { Element('em_input_deleteAcl').checked = true; } if ( (this.ownersAcl[user].indexOf('w',0) >= 0) && (this.ownersAcl[user].indexOf('i',0) >= 0) ) { Element('em_input_writeAcl').checked = true; } if ((this.ownersAcl[user].indexOf('p',0) >= 0) && (this.ownersAcl[user].indexOf('a',0) >= 0) ) { Element('em_input_sendAcl').disabled = false; Element('em_input_sendAcl').checked = true; } if ( (this.ownersAcl[user].indexOf('k',0) >= 0) && (this.ownersAcl[user].indexOf('x',0) >= 0) ) { Element('em_input_folderAcl').checked = true; } } //$() var checkboxes = $(".shared-permissions input:checkbox"); var check = $("#em_input_readAcl").attr("checked") == undefined ? false : true; if(check){ checkboxes.removeAttr("disabled"); }else{ checkboxes.not(".shared-required").attr("disabled", "disabled"); checkboxes.removeAttr("checked"); } } cShareMailbox.prototype.setaclfromuser = function() { var acl = ''; var select = Element('ea_select_owners'); if(select.selectedIndex == "-1"){ alert("Selecione antes um usuario!"); return false; } for(var k = 0; k < select.options.length; k ++ ) { if(select.options[k].selected !== true ) continue; acl = ''; var user = select.options[k].value; if (Element('em_input_readAcl').checked) { Element('em_input_sendAcl').disabled = false; acl = 'lrs'; } else{ Element('em_input_sendAcl').disabled = true; Element('em_input_sendAcl').checked = false; } if (Element('em_input_deleteAcl').checked) acl += 'tea'; if (Element('em_input_writeAcl').checked) acl += 'wia'; if (Element('em_input_sendAcl').checked) acl += 'pa'; if (Element('em_input_folderAcl').checked) acl += 'kxa'; this.ownersAcl[user] = acl; } } cShareMailbox.prototype.setCalendaraclfromuser = function() { var acl = ''; var select = Element('ea_select_owners'); sharemailbox.ownersExpressoCalendarAcl = false; if(select.selectedIndex == "-1"){ alert("Selecione antes um usuario!"); return false; } for(var k = 0; k < select.options.length; k ++ ) { if(select.options[k].selected !== true ) continue; acl = ''; var user = select.options[k].value; if (Element('em_input_readCalendar').checked) { acl += '1-'; Element('em_input_editCalendar').disabled = false; Element('em_input_deleteCalendar').disabled = false; Element('em_input_restrictCalendar').disabled = false; if (Element('em_input_editCalendar').checked) acl += '4-'; if (Element('em_input_deleteCalendar').checked ) acl += '8-'; if (Element('em_input_restrictCalendar').checked) acl += '16-'; } else { Element('em_input_editCalendar').disabled = true; Element('em_input_deleteCalendar').disabled = true; Element('em_input_restrictCalendar').disabled = true; Element('em_input_editCalendar').checked = false; Element('em_input_deleteCalendar').checked = false; Element('em_input_restrictCalendar').checked = false; } if (Element('em_input_writeCalendar').checked || Element('em_input_writeExpressoCalendar').checked) acl += '2-'; this.ownersCalendarAcl[user] = acl; } } cShareMailbox.prototype.setExpressoCalendaraclfromuser = function() { var acl = ''; var select = Element('ea_select_owners'); sharemailbox.ownersCalendarAcl = false; if(select.selectedIndex == "-1"){ alert("Selecione antes um usuario!"); return false; } for(var k = 0; k < select.options.length; k ++ ) { if(select.options[k].selected !== true ) continue; acl = ''; var user = select.options[k].value; if(Element('em_input_freebusyExpressoCalendar').checked) { Element('em_input_writeExpressoCalendar').disabled = true; Element('em_input_deleteExpressoCalendar').disabled = true; Element('em_input_readExpressoCalendar').disabled = true; Element('em_input_writeExpressoCalendar').checked = false; Element('em_input_deleteExpressoCalendar').checked = false; Element('em_input_readExpressoCalendar').checked = false; acl += 'b' } else { Element('em_input_readExpressoCalendar').disabled = false; if (Element('em_input_readExpressoCalendar').checked) { acl += 'r'; Element('em_input_writeExpressoCalendar').disabled = false; Element('em_input_deleteExpressoCalendar').disabled = false; //Element('em_input_freebusyExpressoCalendar').disabled = false; if (Element('em_input_writeExpressoCalendar').checked) acl += 'w'; if (Element('em_input_deleteExpressoCalendar').checked) acl += 'd'; } else { Element('em_input_writeExpressoCalendar').disabled = true; Element('em_input_deleteExpressoCalendar').disabled = true; //Element('em_input_freebusyExpressoCalendar').disabled = true; Element('em_input_writeExpressoCalendar').checked = false; Element('em_input_deleteExpressoCalendar').checked = false; // Element('em_input_freebusyExpressoCalendar').checked = false; } } this.ownersExpressoCalendarAcl[user] = acl; } } cShareMailbox.prototype.add_user = function() { var select_available_users = document.getElementById('em_select_available_users'); var select_users = document.getElementById('ea_select_owners'); var count_available_users = select_available_users.length; var count_users = select_users.options.length; var new_options = ''; for (i = 0 ; i < count_available_users ; i++) { if (select_available_users.options[i].selected) { if(document.all) { if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' ) { new_options += ''; } } else { if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' ) { new_options += ''; } } } } if (new_options != '') { select_users.innerHTML = '#' + new_options + select_users.innerHTML; select_users.outerHTML = select_users.outerHTML; } } cShareMailbox.prototype.remove_user = function() { select_users = document.getElementById('ea_select_owners'); for(var i = 0;i < select_users.options.length; i++) if(select_users.options[i].selected) { var user = select_users.options[i].value; this.ownersCalendarAcl[user] = ''; select_users.options[i--] = null; } Element('em_input_readAcl').checked = false; Element('em_input_deleteAcl').checked = false; Element('em_input_writeAcl').checked = false; Element('em_input_sendAcl').checked = false; Element('em_input_folderAcl').checked = false; Element('em_input_readCalendar').checked = false; Element('em_input_writeCalendar').checked = false; Element('em_input_editCalendar').checked = false; Element('em_input_deleteCalendar').checked = false; Element('em_input_restrictCalendar').checked = false; Element('em_input_readExpressoCalendar').disabled = true; Element('em_input_writeExpressoCalendar').disabled = true; Element('em_input_deleteExpressoCalendar').disabled = true; Element('em_input_readExpressoCalendar').disabled = true; } /* Build the Object */ var sharemailbox; sharemailbox = new cShareMailbox();