public static function cleanList($list, $userData, $template = null)
    {
        global $PPHP;
        $db = $PPHP['db'];

        $list = array_map('strtolower', $list);

        $db->begin();

        $out = array();
        foreach ($list as $id) {
            if (is_numeric($id)) {
                $cleanId = $db->selectAtom('SELECT id FROM users WHERE id=?', array($id));
                if ($cleanId !== false) {
                    $out[] = $cleanId;
                };
            } elseif (preg_match('/^[^@ ]+@[^@ .]+\.[^@ ]+$/', $id) == 1) {
                $cleanId = $db->selectAtom('SELECT id FROM users WHERE email=?', array($id));
                if ($cleanId !== false) {
                    $out[] = $cleanId;
                } else {
                    if (isset($userData[$id])) {
                        $cols = $userData[$id];
                    } else {
                        $cols = array();
                    };
                    $cols['email'] = $id;
                    $newbie = self::create($cols);
                    if ($newbie !== false) {
                        $out[] = $newbie[0];
                        if ($template !== null) {
                            trigger('send_invite', $template, $newbie[0]);
                        };
                    };
                };
            };
        };

        $db->commit();

        return $out;
    }