Beispiel #1
0
function process_page($app, $action, &$var)
{
    $var['domain_count'] = Domain::count();
    $var['user_count'] = User::count();
    $var['domains'] = Domain::list_all();
    if (!isset($var['domain_id'])) {
        if (isset($_COOKIE['app/aliases/domain_id'])) {
            $var['domain_id'] = filter_var($_COOKIE['app/aliases/domain_id'], FILTER_SANITIZE_STRING);
            if (Domain::list_by_id($var['domain_id']) == null) {
                $var['domain_id'] = 0;
            }
        } else {
            $var['domain_id'] = 0;
        }
    }
    if ($var['domain_id'] != 0) {
        $var['users'] = User::list_by_domain_id($var['domain_id']);
        $var['active_domain'] = Domain::list_by_id($var['domain_id']);
    } else {
        $var['users'] = User::list_all();
    }
    if (!isset($var['user_id'])) {
        if (isset($_COOKIE['app/aliases/user_id'])) {
            $var['user_id'] = filter_var($_COOKIE['app/aliases/user_id'], FILTER_SANITIZE_STRING);
            if (User::list_by_id($var['user_id']) == null) {
                $var['user_id'] = 0;
            }
        } else {
            $var['user_id'] = 0;
        }
    }
    if ($var['user_id'] != 0) {
        $var['active_user'] = User::list_by_id($var['user_id']);
        $var['aliases'] = Alias::list_by_destination($var['active_user']->get_email());
    } else {
        if ($var['domain_id'] != 0) {
            $var['aliases'] = Alias::list_by_domain_id($var['domain_id']);
        } else {
            $var['aliases'] = Alias::list_all();
        }
    }
    switch ($app->action) {
        case 'select_domain':
            setcookie('app/aliases/domain_id', $var['domain_id']);
            setcookie('app/aliases/user_id', null);
            $app->reload();
            break;
        case 'select_user':
            setcookie('app/aliases/user_id', $var['user_id']);
            $app->reload();
            break;
        case 'edit_alias':
            $var['alias_source'] = Alias::list_by_id($var['alias_id'])->get_source();
            break;
        case 'insert_new_alias':
            $alias = new Alias();
            $alias->set_destination($var['active_user']->get_email());
            $alias->set_domain_id($var['domain_id']);
            $alias->set_source($var['alias_source']);
            if ($alias->insert()) {
                $app->reload();
            } else {
                $app->action = 'new_alias';
            }
            break;
        case 'update_edit_alias':
            $alias = Alias::list_by_id($var['alias_id']);
            $alias->set_source($var['alias_source']);
            if ($alias->update()) {
                $app->reload();
            } else {
                $app->action = 'edit_alias';
            }
            break;
        case 'delete_alias':
            $alias = Alias::list_by_id($var['alias_id']);
            if ($alias->delete()) {
                $app->reload();
            }
            break;
    }
}