πŸ“‚ File Browser

//AgentAIv3_backup
πŸŒ™ Dark Mode
🎯 Quick Launch:

πŸ“ Directories

πŸ“ tmp/ πŸ”“ Open
πŸ“ vendor/ πŸ”“ Open

πŸ“„ Files

🐘 chat_handler.php
β–Ά Open πŸ“„ View Source
🐘 chat_handler_test.php
β–Ά Open πŸ“„ View Source
🐘 check_db.php
β–Ά Open πŸ“„ View Source
🐘 cleanup.php
β–Ά Open πŸ“„ View Source
🐘 config.php
β–Ά Open πŸ“„ View Source
🐘 database.php
β–Ά Open πŸ“„ View Source
🐘 delete_chat.php
β–Ά Open πŸ“„ View Source
🐘 fetch_emails.php
β–Ά Open πŸ“„ View Source
🐘 get_email.php
β–Ά Open πŸ“„ View Source
🐘 index.php
β–Ά Open πŸ“„ View Source
🐘 index_minimal.php
β–Ά Open πŸ“„ View Source
🐘 index_simple.php
β–Ά Open πŸ“„ View Source
🐘 logout.php
β–Ά Open πŸ“„ View Source
🐘 mark_read.php
β–Ά Open πŸ“„ View Source
🐘 new_chat.php
β–Ά Open πŸ“„ View Source
🐘 oauth2callback.php
β–Ά Open πŸ“„ View Source
🐘 rename_chat.php
β–Ά Open πŸ“„ View Source
🎨 style.css
β–Ά Open πŸ“„ View Source
🐘 switch_chat.php
β–Ά Open πŸ“„ View Source
🐘 sync_emails.php
β–Ά Open πŸ“„ View Source
🐘 test_chat.php
β–Ά Open πŸ“„ View Source
🐘 test_error.php
β–Ά Open πŸ“„ View Source
🐘 test_session.php
β–Ά Open πŸ“„ View Source
🐘 test_session2.php
β–Ά Open πŸ“„ View Source
🐘 test_session_check.php
β–Ά Open πŸ“„ View Source
🐘 test_simple.php
β–Ά Open πŸ“„ View Source

πŸ“„ Source: index.php

<?php
session_name('INBOXZERO');
session_set_cookie_params(0, '/', '', false, true);
session_start();
require_once 'vendor/autoload.php';

$client = new Google\Client();
$client->setClientId('1082083393389-c5uekspcp2boc1gd0n0gr3v1a5vbb3jg.apps.googleusercontent.com');
$client->setClientSecret('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');
$client->setRedirectUri("http://createcraftweb.playit.plus/AgentAIv3/oauth2callback.php");
$client->addScope('https://www.googleapis.com/auth/gmail.readonly');
$client->setAccessType('offline');
$client->setPrompt('consent');

$isMobile = preg_match('/(android|iphone|ipad|mobile)/i', $_SERVER['HTTP_USER_AGENT']);
$lang = $_COOKIE['inboxzero_lang'] ?? 'en';
?>
<!DOCTYPE html>
<html lang="<?php echo $lang; ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>InboxZero AI v3</title>
    <style>
        * { box-sizing: border-box; }
        body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background: #f0f2f5; }
        .container { max-width: 1200px; margin: auto; background: white; border-radius: 10px; overflow: hidden; }
        .header { background: #667eea; color: white; padding: 15px 20px; }
        .header-top { display: flex; justify-content: space-between; align-items: center; }
        .content { display: flex; min-height: 500px; }
        .sidebar { width: 300px; background: #f8f9fa; padding: 15px; border-right: 1px solid #ddd; }
        .chat-area { flex: 1; display: flex; flex-direction: column; }
        .messages { flex: 1; padding: 15px; overflow-y: auto; min-height: 400px; background: white; }
        .input-area { padding: 15px; border-top: 1px solid #ddd; display: flex; gap: 10px; }
        .input-area input { flex: 1; padding: 10px; border: 1px solid #ddd; border-radius: 20px; }
        .input-area button { padding: 10px 20px; background: #667eea; color: white; border: none; border-radius: 20px; cursor: pointer; }
        .message { margin-bottom: 10px; padding: 10px; border-radius: 10px; max-width: 80%; }
        .user-message { background: #667eea; color: white; margin-left: auto; }
        .ai-message { background: #f1f3f4; color: #333; margin-right: auto; }
        .login-btn { background: white; color: #667eea; padding: 10px 20px; text-decoration: none; border-radius: 20px; display: inline-block; }
        .logout-btn { background: #dc3545; color: white; padding: 8px; border: none; border-radius: 10px; cursor: pointer; width: 100%; margin-bottom: 10px; }
        .email-list { list-style: none; padding: 0; margin: 0; max-height: 400px; overflow-y: auto; }
        .email-item { padding: 8px; margin-bottom: 5px; background: white; border-radius: 8px; border: 1px solid #ddd; cursor: pointer; }
        .email-from { font-weight: bold; font-size: 12px; }
        .email-subject { font-size: 11px; color: #666; }
        .email-date { font-size: 10px; color: #999; }
        .loading { text-align: center; padding: 20px; color: #999; }
        .badge { background: rgba(255,255,255,0.2); padding: 2px 8px; border-radius: 20px; font-size: 12px; }
        .controls { display: flex; gap: 10px; }
        .theme-toggle, .lang-select { background: rgba(255,255,255,0.2); border: none; color: white; padding: 5px 10px; border-radius: 20px; cursor: pointer; }
        .chat-history-item { padding: 6px; margin-bottom: 4px; background: white; border-radius: 8px; cursor: pointer; font-size: 12px; }
        .chat-history-item.active { background: #667eea; color: white; }
        .new-chat-btn { width: 100%; padding: 6px; background: #667eea; color: white; border: none; border-radius: 20px; cursor: pointer; margin-top: 10px; }
        hr { margin: 10px 0; }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <div class="header-top">
            <h1>πŸ“§ InboxZero AI v3</h1>
            <div class="controls">
                <button class="theme-toggle" onclick="toggleTheme()">πŸŒ™ Dark</button>
                <select class="lang-select" onchange="changeLanguage(this.value)">
                    <option value="en">πŸ‡¬πŸ‡§ English</option>
                    <option value="ro">πŸ‡·πŸ‡΄ RomΓ’nΔƒ</option>
                </select>
            </div>
        </div>
        <p>Your intelligent email assistant - ask anything about your emails</p>
    </div>
    <div class="content">
        <div class="sidebar">
            <div class="chat-history-section">
                <h3>πŸ’¬ Recent Chats</h3>
                <div id="chatHistoryList"></div>
                <button onclick="newChat()" class="new-chat-btn">+ New Chat</button>
            </div>
            <hr>
            <h3>πŸ“¬ Your Emails</h3>
            <?php if (isset($_SESSION['access_token'])): ?>
                <button onclick="logout()" class="logout-btn">πŸšͺ Logout</button>
                <div id="emailList" class="loading">πŸ“₯ Loading your emails...</div>
            <?php else: ?>
                <p>πŸ” Login to access your Gmail inbox</p>
                <a href="<?php echo $client->createAuthUrl(); ?>" class="login-btn">πŸ”‘ Sign in with Google</a>
            <?php endif; ?>
        </div>
        <div class="chat-area">
            <div class="messages" id="messages">
                <div class="message ai-message">πŸ€– Hello! I'm InboxZero AI v3. Ask me about your emails!</div>
            </div>
            <?php if (isset($_SESSION['access_token'])): ?>
            <div class="input-area">
                <input type="text" id="userInput" placeholder="Ask about your emails..." onkeypress="if(event.key==='Enter') sendMessage()">
                <button onclick="sendMessage()">πŸ“€ Send</button>
            </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<script>
let currentLang = '<?php echo $lang; ?>';
let currentConversationId = null;

function toggleTheme() {
    document.body.style.background = document.body.style.background === '#1a1a2e' ? '#f0f2f5' : '#1a1a2e';
}

function changeLanguage(lang) {
    currentLang = lang;
    document.cookie = `inboxzero_lang=${lang}; path=/`;
}

async function sendMessage() {
    const input = document.getElementById('userInput');
    const message = input.value.trim();
    if (!message) return;

    addMessage('user', message);
    input.value = '';

    try {
        const response = await fetch('chat_handler.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ query: message, lang: currentLang, conversation_id: currentConversationId })
        });
        const data = await response.json();
        addMessage('ai', data.reply);
        
        if (data.conversation_id && !currentConversationId) {
            currentConversationId = data.conversation_id;
            loadChatHistory();
        }
        
        if (data.emails && data.emails.length > 0) {
            displayEmails(data.emails);
        }
    } catch (error) {
        addMessage('ai', 'Error: ' + error.message);
    }
}

function addMessage(role, text) {
    const messagesDiv = document.getElementById('messages');
    const div = document.createElement('div');
    div.className = `message ${role === 'user' ? 'user-message' : 'ai-message'}`;
    div.innerHTML = (role === 'user' ? 'πŸ‘€ ' : 'πŸ€– ') + text.replace(/\n/g, '<br>');
    messagesDiv.appendChild(div);
    messagesDiv.scrollTop = messagesDiv.scrollHeight;
}

async function loadEmails() {
    try {
        const response = await fetch('fetch_emails.php');
        const emails = await response.json();
        if (emails.error) {
            document.getElementById('emailList').innerHTML = `<div class="loading">❌ ${emails.error}</div>`;
        } else {
            displayEmails(emails);
        }
    } catch (error) {
        document.getElementById('emailList').innerHTML = '<div class="loading">❌ Failed to load emails</div>';
    }
}

function displayEmails(emails) {
    if (!emails || emails.length === 0) {
        document.getElementById('emailList').innerHTML = '<div class="loading">πŸ“­ No emails found</div>';
        return;
    }
    let html = '<ul class="email-list">';
    for (let i = 0; i < Math.min(emails.length, 15); i++) {
        const email = emails[i];
        html += `<li class="email-item" onclick="viewEmail('${email.id}', '${email.threadId}')">
                    <div class="email-from">πŸ“¨ ${escapeHtml(email.from.substring(0, 40))}</div>
                    <div class="email-subject">${escapeHtml(email.subject.substring(0, 50))}</div>
                    <div class="email-date">πŸ“… ${escapeHtml(email.date)}</div>
                </li>`;
    }
    html += '</ul>';
    document.getElementById('emailList').innerHTML = html;
}

async function viewEmail(emailId, threadId) {
    addMessage('ai', 'πŸ“– Opening email...');
    try {
        const response = await fetch('get_email.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ email_id: emailId })
        });
        const data = await response.json();
        if (data.content) {
            addMessage('ai', data.content.substring(0, 1000));
        } else {
            addMessage('ai', '❌ Could not load email content.');
        }
    } catch (error) {
        addMessage('ai', '❌ Failed to load email.');
    }
}

async function loadChatHistory() {
    try {
        const response = await fetch('get_chats.php');
        const chats = await response.json();
        const container = document.getElementById('chatHistoryList');
        if (container && !chats.error) {
            if (chats.length === 0) {
                container.innerHTML = '<div class="chat-history-item">No previous chats</div>';
            } else {
                container.innerHTML = chats.map(chat => `
                    <div class="chat-history-item ${currentConversationId == chat.id ? 'active' : ''}" onclick="switchChat(${chat.id})">
                        ${escapeHtml(chat.title)}
                    </div>
                `).join('');
            }
        }
    } catch (e) {
        console.error('Load chat history error:', e);
    }
}

async function newChat() {
    const response = await fetch('new_chat.php', { method: 'POST' });
    const data = await response.json();
    if (data.success) {
        currentConversationId = data.chat_id;
        document.getElementById('messages').innerHTML = '<div class="message ai-message">πŸ€– Hello! I\'m InboxZero AI v3. Ask me about your emails!</div>';
        loadChatHistory();
    }
}

async function switchChat(chatId) {
    currentConversationId = chatId;
    const response = await fetch('switch_chat.php', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ chat_id: chatId })
    });
    const data = await response.json();
    if (data.messages) {
        const messagesDiv = document.getElementById('messages');
        messagesDiv.innerHTML = '';
        for (const msg of data.messages) {
            addMessage(msg.role, msg.content);
        }
    }
    loadChatHistory();
}

function logout() {
    fetch('logout.php').then(() => window.location.reload());
}

function escapeHtml(text) {
    if (!text) return '';
    const div = document.createElement('div');
    div.textContent = text;
    return div.innerHTML;
}

// IniΘ›ializare
if (document.getElementById('emailList')) {
    loadEmails();
}
loadChatHistory();
</script>
</body>
</html>
← Back