/** * Return manager instance * * @access protected * @param void * @return MailAccountImapFolders */ function manager() { if (!$this->manager instanceof MailAccountImapFolders) { $this->manager = MailAccountImapFolders::instance(); } return $this->manager; }
/** * Return manager instance * * @access protected * @param void * @return MailAccountImapFolders */ function manager() { if(!($this->manager instanceof MailAccountImapFolders)) $this->manager = MailAccountImapFolders::instance(); return $this->manager; } // manager
/** * Edit email account * * @access public * @param void * @return null */ function edit_account() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $this->setTemplate('add_account', $this->plugin_name); $mailAccount = MailAccounts::findById(get_id()); if (!$mailAccount instanceof MailAccount) { flash_error(lang('mailAccount dnx')); ajx_current("empty"); return; } // if if (!$mailAccount->canEdit(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if // get mail account users $mailAccountUsers = MailAccountContacts::getByAccount($mailAccount); $mau = array(); foreach ($mailAccountUsers as $au) { $contact = $au->getContact(); if (!$contact instanceof Contact) { continue; } $mau[$au->getContactId()] = array('name' => $contact->getObjectName(), 'can_edit' => $au->getCanEdit()); } tpl_assign('mailAccountUsers', $mau); $is_admin = logged_user()->isAdministrator(); tpl_assign('is_admin', $is_admin); $mailAccount_data = array_var($_POST, 'mailAccount'); if (!is_array($mailAccount_data)) { $mailAccount_data = array('user_id' => logged_user()->getId(), 'name' => $mailAccount->getName(), 'email' => $mailAccount->getEmail(), 'email_addr' => $mailAccount->getEmailAddress(), 'password' => MailUtilities::ENCRYPT_DECRYPT($mailAccount->getPassword()), 'server' => $mailAccount->getServer(), 'is_imap' => $mailAccount->getIsImap(), 'incoming_ssl' => $mailAccount->getIncomingSsl(), 'incoming_ssl_port' => $mailAccount->getIncomingSslPort(), 'smtp_server' => $mailAccount->getSmtpServer(), 'smtp_port' => $mailAccount->getSmtpPort(), 'smtp_username' => $mailAccount->getSmtpUsername(), 'smtp_password' => MailUtilities::ENCRYPT_DECRYPT($mailAccount->getSmtpPassword()), 'smtp_use_auth' => $mailAccount->getSmtpUseAuth(), 'del_from_server' => $mailAccount->getDelFromServer(), 'mark_read_on_server' => $mailAccount->getMarkReadOnServer(), 'outgoing_transport_type' => $mailAccount->getOutgoingTrasnportType()); // array if (config_option('sent_mails_sync')) { $sync_details = array('sync_server' => $mailAccount->getSyncServer(), 'sync_addr' => $mailAccount->getSyncAddr(), 'sync_pass' => MailUtilities::ENCRYPT_DECRYPT($mailAccount->getSyncPass()), 'sync_ssl' => $mailAccount->getSyncSsl(), 'sync_sslport' => $mailAccount->getSyncSslPort()); $mailAccount_data = array_merge($mailAccount_data, $sync_details); } } else { if (!isset($mailAccount_data['sync_ssl'])) { $mailAccount_data['sync_ssl'] = false; } if (!isset($mailAccount_data['incoming_ssl'])) { $mailAccount_data['incoming_ssl'] = false; } if (!isset($mailAccount_data['is_default'])) { $mailAccount_data['is_default'] = false; } } if ($mailAccount->getIsImap()) { /*try { $real_folders = MailUtilities::getImapFolders($mailAccount); DB::beginWork(); foreach ($real_folders as $folder_name) { if (!MailAccountImapFolders::findById(array('account_id' => $mailAccount->getId(), 'folder_name' => $folder_name))) { $acc_folder = new MailAccountImapFolder(); $acc_folder->setAccountId($mailAccount->getId()); $acc_folder->setFolderName($folder_name); $acc_folder->setCheckFolder($folder_name == 'INBOX');// By default only INBOX is checked $acc_folder->save(); } } DB::commit(); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); }*/ $imap_folders = MailAccountImapFolders::getMailAccountImapFolders($mailAccount->getId()); tpl_assign('imap_folders', $imap_folders); } tpl_assign('mailAccount', $mailAccount); tpl_assign('mailAccount_data', $mailAccount_data); if (array_var($_POST, 'submitted')) { try { $user_changed = false; $selected_user = array_var($_POST, 'users_select_box'); if (!$is_admin) { $selected_user = $mailAccount->getContactId(); } $mail_account_user = Contacts::findById($selected_user); if ($mail_account_user instanceof Contact) { $old_user_id = $mailAccount->getContactId(); if ($old_user_id != $mail_account_user->getId()) { $user_changed = true; } $mailAccount_data['user_id'] = $mail_account_user->getId(); } $mailAccount_data['sync_ssl'] = array_var($mailAccount_data, 'sync_ssl') == "checked"; DB::beginWork(); $logged_user_settings = MailAccountContacts::getByAccountAndContact($mailAccount, logged_user()); $logged_user_can_edit = $logged_user_settings instanceof MailAccountContact && $logged_user_settings->getCanEdit() || $mailAccount->getContactId() == logged_user()->getId() || logged_user()->isAdministrator(); if ($logged_user_can_edit || $is_admin) { if (!array_var($mailAccount_data, 'del_mails_from_server', false)) { $mailAccount_data['del_from_server'] = 0; } if (!array_var($mailAccount_data, 'mark_read_on_server', false)) { $mailAccount_data['mark_read_on_server'] = 0; } $mailAccount->setFromAttributes($mailAccount_data); $mailAccount->setServer(trim($mailAccount->getServer())); $mailAccount->setPassword(MailUtilities::ENCRYPT_DECRYPT($mailAccount->getPassword())); $mailAccount->setSmtpPassword(MailUtilities::ENCRYPT_DECRYPT($mailAccount->getSmtpPassword())); $outbox_folder = array_var($_POST, 'outbox_select_box'); if (config_option("sent_mails_sync") && isset($outbox_folder)) { $mailAccount->setSyncPass(MailUtilities::ENCRYPT_DECRYPT($mailAccount_data['sync_pass'])); $mailAccount->setSyncFolder($outbox_folder); } //in case there is a new owner of the email account if ($user_changed && $mail_account_user instanceof Contact) { DB::executeAll("UPDATE " . TABLE_PREFIX . "objects SET created_by_id=" . $mail_account_user->getId() . " WHERE \r\n\t\t\t\t\t\t\t`created_by_id` = '{$old_user_id}' AND (select `account_id` FROM " . TABLE_PREFIX . "mail_contents mc WHERE mc.object_id=id) = " . $mailAccount->getId()); $mailAccount->setContactId($mail_account_user->getId()); } //If imap, save folders to check if ($mailAccount->getIsImap() && is_array(array_var($_POST, 'check'))) { $checks = array_var($_POST, 'check'); $names = array(); foreach ($checks as $name => $checked) { $name = str_replace(array('¡', '!'), array('[', ']'), $name); //to avoid a mistaken array if name contains [ $names[] = $name; $imap_folder = MailAccountImapFolders::instance()->findOne(array('conditions' => array('folder_name = ? AND account_id = ?', $name, $mailAccount->getId()))); if (!$imap_folder instanceof MailAccountImapFolder) { $imap_folder = new MailAccountImapFolder(); $imap_folder->setAccountId($mailAccount->getId()); $imap_folder->setFolderName($name); } $imap_folder->setCheckFolder($checked == 'checked'); $imap_folder->save(); } if (count($names) > 0) { DB::execute("UPDATE " . TABLE_PREFIX . "mail_account_imap_folder SET check_folder=0 WHERE account_id=" . $mailAccount->getId() . " AND folder_name NOT IN ('" . implode("','", $names) . "')"); } } $member_ids = json_decode(array_var($_POST, 'members')); $member_ids_str = ""; foreach ($member_ids as $mid) { if (is_numeric($mid)) { $member_ids_str .= ($member_ids_str == "" ? "" : ",") . $mid; } } $mailAccount->setMemberId($member_ids_str); $mailAccount->save(); // process users $account_users = Contacts::findAll(); $user_access = array_var($_POST, 'user_access'); foreach ($account_users as $account_user) { $user_id = $account_user->getId(); $access = array_var($user_access, $user_id, 'none'); $account_user = MailAccountContacts::getByAccountAndContact($mailAccount, $account_user); if ($mail_account_user instanceof Contact && ($access != 'none' || $user_id == $mail_account_user->getId())) { if (!$account_user instanceof MailAccountContact) { $account_user = new MailAccountContact(); $account_user->setAccountId($mailAccount->getId()); $account_user->setContactId($user_id); } $account_user->setCanEdit($access == 'write'); $account_user->save(); } else { if ($account_user instanceof MailAccountContact) { $account_user->delete(); } } } /*// delete any remaining ones $account_users = MailAccountContacts::getByAccount($mailAccount); foreach ($account_users as $account_user) { if ($access = array_var($user_access, $account_user->getId(), 'none') == 'none') { $account_user->delete(); } }*/ evt_add("mail account edited", array("id" => $mailAccount->getId(), "name" => $mailAccount->getName(), "email" => $mailAccount->getEmail())); } // personal settings if (array_var($_POST, 'is_default')) { $user_accounts = MailAccountContacts::getByContact(logged_user()); foreach ($user_accounts as $acc) { if ($acc->getAccountId() != $mailAccount->getId()) { $acc->setIsDefault(false); $acc->save(); } else { $acc->setIsDefault(true); $acc->save(); } } } $logged_user_settings = MailAccountContacts::getByAccountAndContact($mailAccount, logged_user()); if ($logged_user_settings instanceof MailAccountContact) { $logged_user_settings->setSignature(array_var($_POST, 'signature')); $logged_user_settings->setSenderName(array_var($_POST, 'sender_name')); $logged_user_settings->save(); } DB::commit(); flash_success(lang('success edit mail account', $mailAccount->getName())); ajx_current("back"); // Error... } catch (Exception $e) { DB::rollback(); ajx_current("empty"); flash_error($e->getMessage()); } // try } // if }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'MailAccountImapFolders')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return MailAccountImapFolders::instance()->paginate($arguments, $items_per_page, $current_page); //$instance =& MailAccounts::instance(); //return $instance->paginate($arguments, $items_per_page, $current_page); } // if }