Initial baseline WACloud CI3 production
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<div class="modal fade" id="attachmentModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Lampiran</h5>
|
||||
<button class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="file" class="form-control" multiple>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" data-bs-dismiss="modal">Tutup</button>
|
||||
<button class="btn btn-primary">Kirim</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,5 @@
|
||||
<ul class="list-group list-group-flush" id="chatList">
|
||||
<!-- <li class="list-group-item text-center text-muted">
|
||||
<div class="spinner-border spinner-border-sm"></div> Memuat chat...
|
||||
</li> -->
|
||||
</ul>
|
||||
@@ -0,0 +1,3 @@
|
||||
<div id="chatWindow" class="chat-window messages d-flex flex-column" style="height: calc(100vh - 130px);">
|
||||
<?php $this->load->view('chat/partials/empty_state'); ?>
|
||||
</div>
|
||||
@@ -0,0 +1,164 @@
|
||||
<div class="chat-input-bg">
|
||||
<div id="chatInputUI" class="chat-input" style="display: none;">
|
||||
<!-- Tombol Attach / File -->
|
||||
<div class="dropdown2">
|
||||
<button type="button" class="chat-btn" title="Attach">
|
||||
<i class="fa-solid fa-paperclip"></i>
|
||||
</button>
|
||||
<ul class="dropdown2-files">
|
||||
<li>
|
||||
<label>
|
||||
<i class="fa-solid fa-image"></i> Gambar
|
||||
<input type="file" accept="image/*" style="display:none" onchange="handleFile(this)">
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<i class="fa-solid fa-file"></i> File
|
||||
<input type="file" accept=".pdf,.doc,.docx,.xls,.xlsx,.txt" style="display:none" onchange="handleFile(this)">
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Tombol Emoji -->
|
||||
<div class="dropdown2">
|
||||
<button type="button" class="chat-btn" id="emojiToggle" title="Emoji">
|
||||
<i class="fa-regular fa-face-smile"></i>
|
||||
</button>
|
||||
<div class="dropdown2-menu">
|
||||
<button>😀</button>
|
||||
<button>😃</button>
|
||||
<button>😄</button>
|
||||
<button>😁</button>
|
||||
<button>😆</button>
|
||||
<button>😅</button>
|
||||
<button>😂</button>
|
||||
<button>🤣</button>
|
||||
<button>😊</button>
|
||||
<button>😇</button>
|
||||
<button>🙂</button>
|
||||
<button>🙃</button>
|
||||
<button>😉</button>
|
||||
<button>😌</button>
|
||||
<button>😍</button>
|
||||
<button>🥰</button>
|
||||
<button>😘</button>
|
||||
<button>😗</button>
|
||||
<button>😙</button>
|
||||
<button>😚</button>
|
||||
<button>😋</button>
|
||||
<button>😛</button>
|
||||
<button>😜</button>
|
||||
<button>🤪</button>
|
||||
<button>😝</button>
|
||||
<button>🤑</button>
|
||||
<button>🤗</button>
|
||||
<button>🤭</button>
|
||||
<button>🤫</button>
|
||||
<button>🤔</button>
|
||||
<button>🤐</button>
|
||||
<button>🤨</button>
|
||||
<button>😐</button>
|
||||
<button>😑</button>
|
||||
<button>😶</button>
|
||||
<button>😏</button>
|
||||
<button>😒</button>
|
||||
<button>🙄</button>
|
||||
<button>😬</button>
|
||||
<button>🤥</button>
|
||||
<button>😌</button>
|
||||
<button>😔</button>
|
||||
<button>😪</button>
|
||||
<button>🤤</button>
|
||||
<button>😴</button>
|
||||
<button>😷</button>
|
||||
<button>🤒</button>
|
||||
<button>🤕</button>
|
||||
<button>🤢</button>
|
||||
<button>🤮</button>
|
||||
<button>🤧</button>
|
||||
<button>🥵</button>
|
||||
<button>🥶</button>
|
||||
<button>🥴</button>
|
||||
<button>😵</button>
|
||||
<button>🤯</button>
|
||||
<button>🤠</button>
|
||||
<button>🥳</button>
|
||||
<button>😎</button>
|
||||
<button>🤓</button>
|
||||
<button>🧐</button>
|
||||
<button>😕</button>
|
||||
<button>😟</button>
|
||||
<button>🙁</button>
|
||||
<button>☹️</button>
|
||||
<button>😮</button>
|
||||
<button>😯</button>
|
||||
<button>😲</button>
|
||||
<button>😳</button>
|
||||
<button>🥺</button>
|
||||
<button>😦</button>
|
||||
<button>😧</button>
|
||||
<button>😨</button>
|
||||
<button>😰</button>
|
||||
<button>😥</button>
|
||||
<button>😢</button>
|
||||
<button>😭</button>
|
||||
<button>😱</button>
|
||||
<button>😖</button>
|
||||
<button>😣</button>
|
||||
<button>😞</button>
|
||||
<button>😓</button>
|
||||
<button>😩</button>
|
||||
<button>😫</button>
|
||||
<button>🥱</button>
|
||||
<button>😤</button>
|
||||
<button>😡</button>
|
||||
<button>😠</button>
|
||||
<button>🤬</button>
|
||||
<button>😈</button>
|
||||
<button>👿</button>
|
||||
<button>💀</button>
|
||||
<button>☠️</button>
|
||||
<button>💩</button>
|
||||
<button>🤡</button>
|
||||
<button>👹</button>
|
||||
<button>👺</button>
|
||||
<button>👻</button>
|
||||
<button>👽</button>
|
||||
<button>👾</button>
|
||||
<button>🤖</button>
|
||||
<button>👍</button>
|
||||
<button>👎</button>
|
||||
<button>✊</button>
|
||||
<button>👊</button>
|
||||
<button>🤛</button>
|
||||
<button>🤜</button>
|
||||
<button>👏</button>
|
||||
<button>🙌</button>
|
||||
<button>👐</button>
|
||||
<button>🤲</button>
|
||||
<button>🙏</button>
|
||||
<button>🤝</button>
|
||||
<button>🤟</button>
|
||||
<button>🤘</button>
|
||||
<button>🤙</button>
|
||||
<button>💪</button>
|
||||
<button>✋</button>
|
||||
<button>🖐️</button>
|
||||
<button>🖖</button>
|
||||
<button>👌</button>
|
||||
<button>✌️</button>
|
||||
<button>🤏</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Input Pesan -->
|
||||
<textarea id="chatInput" placeholder="Ketik pesan..." rows="1"></textarea>
|
||||
|
||||
<!-- Tombol Kirim -->
|
||||
<button type="button" id="sendBtn" data-id="${sessionId}" class="chat-btn" title="Kirim" style="display:none;">
|
||||
<i class="fa-solid fa-paper-plane"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
<div class="message <?= $type ?> p-2 shadow-sm" style="max-width: 75%;">
|
||||
<?= nl2br(htmlspecialchars($text)) ?>
|
||||
</div>
|
||||
@@ -0,0 +1,904 @@
|
||||
<?php $this->load->view('chat/components/message_input'); ?>
|
||||
<?php $this->load->view('chat/components/attachment_modal'); ?>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://cdn.socket.io/4.7.2/socket.io.min.js"></script>
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const list = document.getElementById('chatList');
|
||||
const chatContainer = document.querySelector('.chat-list');
|
||||
const searchInput = document.querySelector('input[placeholder="Cari atau mulai chat baru..."]');
|
||||
const filterBtns = document.querySelectorAll('.filter-btn');
|
||||
|
||||
let offset = 0;
|
||||
const limit = 15;
|
||||
let isLoading = false;
|
||||
let hasMore = true;
|
||||
let currentSearch = '';
|
||||
let currentFilter = 'all';
|
||||
|
||||
// Fungsi bantu ambil cookie berdasarkan nama
|
||||
function getCookie(name) {
|
||||
const cookies = document.cookie.split('; ');
|
||||
for (let c of cookies) {
|
||||
const [key, value] = c.split('=');
|
||||
if (key === name) return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function formatWhatsAppBody(text) {
|
||||
if (!text) return '';
|
||||
|
||||
// Bold: *Text* → <b>Text</b>
|
||||
text = text.replace(/\*(.*?)\*/g, '<b>$1</b>');
|
||||
|
||||
// Italic: _Text_ → <i>Text</i>
|
||||
text = text.replace(/_(.*?)_/g, '<i>$1</i>');
|
||||
|
||||
// Strikethrough: ~Text~ → <s>Text</s>
|
||||
text = text.replace(/~(.*?)~/g, '<s>$1</s>');
|
||||
|
||||
// Bisa ditambahkan formatting lain jika perlu
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
async function renderChatMessage(msg, lastDateRef, statusDate = true) {
|
||||
let html = '';
|
||||
|
||||
const align = msg.direction === 'in' ? 'text-start' : 'text-end';
|
||||
const widthMessageBox = msg.message_type === 'text' ? 'min-width: 416px; max-width: 55%' : 'width: 416px;';
|
||||
const captName = msg.name === null ? 'system' : msg.name.toLowerCase();
|
||||
const captMessage = msg.direction === 'in' ? 'read by ' + captName : 'send by ' + captName;
|
||||
|
||||
|
||||
// Format waktu
|
||||
const rawTime = msg.timestamp || msg.time || null;
|
||||
let messageTime = '--:--';
|
||||
let messageDate = '';
|
||||
|
||||
if (rawTime) {
|
||||
const dateObj = new Date(isNaN(rawTime) ? rawTime : rawTime * 1000);
|
||||
const hours = dateObj.getHours().toString().padStart(2, '0');
|
||||
const minutes = dateObj.getMinutes().toString().padStart(2, '0');
|
||||
messageTime = `${hours}:${minutes}`;
|
||||
|
||||
const options = { day: '2-digit', month: 'short', year: 'numeric' };
|
||||
const formattedDate = dateObj.toLocaleDateString('id-ID', options);
|
||||
|
||||
if (statusDate === true) {
|
||||
// Tampilkan tanggal hanya jika beda
|
||||
if (formattedDate !== lastDateRef.value) {
|
||||
messageDate = `<div class="text-center text-muted my-2">${formattedDate}</div>`;
|
||||
lastDateRef.value = formattedDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Status ikon
|
||||
const messageStatus = (msg.status || '').toLowerCase();
|
||||
let statusIcon = '';
|
||||
switch (messageStatus) {
|
||||
case 'pending': statusIcon = '<i class="fa-regular fa-clock text-muted"></i>'; break;
|
||||
case 'sent': statusIcon = '<i class="fa-solid fa-check text-muted"></i>'; break;
|
||||
case 'delivered': statusIcon = '<i class="fa-solid fa-check-double text-muted"></i>'; break;
|
||||
case 'read': statusIcon = '<i class="fa-solid fa-check-double text-primary"></i>'; break;
|
||||
case 'failed': statusIcon = '<i class="fa-solid fa-circle-exclamation text-danger"></i>'; break;
|
||||
case 'canceled': statusIcon = '<i class="fa-solid fa-ban text-danger"></i>'; break;
|
||||
default: statusIcon = ''; break;
|
||||
}
|
||||
|
||||
let content = '';
|
||||
|
||||
// === Template Message ===
|
||||
if (msg.message_type === 'template') {
|
||||
const payload = JSON.parse(msg.content || '{}');
|
||||
|
||||
|
||||
try {
|
||||
const res = await fetch(`<?= base_url('chat/getMessagesTemplate') ?>`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const templateData = await res.json();
|
||||
|
||||
if (templateData.success && templateData.data) {
|
||||
const t = templateData.data;
|
||||
|
||||
if (t.header) {
|
||||
if (typeof t.header === 'string') {
|
||||
// Header teks biasa
|
||||
content += `<div class="template-header mb-1"><strong>${t.header}</strong></div>`;
|
||||
} else if (typeof t.header === 'object' && t.header.type) {
|
||||
// Header media (IMAGE, VIDEO, DOCUMENT)
|
||||
switch (t.header.type) {
|
||||
case 'IMAGE':
|
||||
content += `
|
||||
<div class="template-header mb-1">
|
||||
<img src="${t.header.link}" alt="Header Image" class="img-fluid rounded">
|
||||
</div>`;
|
||||
break;
|
||||
|
||||
case 'VIDEO':
|
||||
content += `
|
||||
<div class="template-header mb-1">
|
||||
<video src="${t.header.link}" controls class="w-100 rounded"></video>
|
||||
</div>`;
|
||||
break;
|
||||
|
||||
case 'DOCUMENT':
|
||||
content += `
|
||||
<div class="template-header mb-1">
|
||||
<a href="${t.header.link}" target="_blank" class="btn btn-sm btn-outline-secondary">
|
||||
📄 Lihat Dokumen
|
||||
</a>
|
||||
</div>`;
|
||||
break;
|
||||
|
||||
default:
|
||||
content += `<div class="template-header mb-1 text-muted">[Unsupported header type]</div>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
content += t.body?.trim()
|
||||
? `<div class="template-body mb-1">${t.body}</div>`
|
||||
: `<div class="template-body text-muted mb-1">[Body kosong]</div>`;
|
||||
|
||||
content += `
|
||||
<div class="template-footer small text-muted d-flex justify-content-between align-items-center mt-1">
|
||||
<span>${t.footer || ''}</span>
|
||||
<span class="d-flex align-items-center">
|
||||
<small class="me-1">${messageTime}</small>
|
||||
${statusIcon}
|
||||
</span>
|
||||
</div>`;
|
||||
|
||||
if (t.buttons && t.buttons.length > 0) {
|
||||
content += `<div class="template-buttons mt-2">`;
|
||||
t.buttons.forEach(btn => {
|
||||
if (btn.type === 'URL' && btn.url) {
|
||||
content += `<a href="${btn.url}" target="_blank" class="btn btn-sm btn-outline-success me-1 w-100">${btn.text}</a>`;
|
||||
} else if (btn.type === 'CALL' && btn.phone_number) {
|
||||
content += `<a href="tel:${btn.phone_number}" class="btn btn-sm btn-outline-success me-1">${btn.text}</a>`;
|
||||
} else if (btn.type === 'quick_reply') {
|
||||
content += `<button class="btn btn-sm btn-outline-secondary me-1">${btn.text}</button>`;
|
||||
}
|
||||
});
|
||||
content += `</div>`;
|
||||
}
|
||||
} else {
|
||||
content = `[Template tidak ditemukan]`;
|
||||
}
|
||||
} catch {
|
||||
content = `[Gagal memuat template]`;
|
||||
}
|
||||
|
||||
html += `
|
||||
<div class="${align} mb-2" data-msg-id="${msg.id}">
|
||||
<span class="d-inline-block rounded p-2 bg-light text-dark" style="${widthMessageBox}">
|
||||
${content}
|
||||
</span>
|
||||
<p><i class="text-secondary" style="margin-left: 5px; margin-rigth: 5px; font-size: 14px">${captMessage}</i></p>
|
||||
</div>`;
|
||||
|
||||
return messageDate + html;
|
||||
}
|
||||
|
||||
const BASE_URL = "<?= base_url() ?>";
|
||||
|
||||
// === Regular Message ===
|
||||
// Parse content JSON dari msg.content
|
||||
let msgContent = {};
|
||||
try {
|
||||
msgContent = msg.content ? JSON.parse(msg.content) : {};
|
||||
} catch (e) {
|
||||
console.error('Gagal decode content JSON:', e);
|
||||
msgContent = {};
|
||||
}
|
||||
|
||||
// === Regular Message ===
|
||||
switch (msg.message_type) {
|
||||
case 'image':
|
||||
content = msg.file_url
|
||||
? `<img src="${BASE_URL + msg.file_url}" alt="image" class="img-fluid rounded" width="400px">
|
||||
${msgContent.caption ? `<div class="template-body mb-1">${msgContent.caption}</div>` : ''}`
|
||||
: `[Gambar belum diunduh]`;
|
||||
break;
|
||||
|
||||
case 'video':
|
||||
content = msg.file_url
|
||||
? `<video controls class="rounded" style="width:400px;">
|
||||
<source src="${BASE_URL + msg.file_url}" type="video/mp4">
|
||||
Browser Anda tidak mendukung video.
|
||||
</video>
|
||||
${msgContent.caption ? `<div class="template-body mb-1">${msgContent.caption}</div>` : ''}`
|
||||
: `[Video belum diunduh]`;
|
||||
break;
|
||||
|
||||
case 'audio':
|
||||
content = msg.file_url
|
||||
? `<audio controls style="width:400px;">
|
||||
<source src="${BASE_URL + msg.file_url}" type="audio/mpeg">
|
||||
Browser Anda tidak mendukung audio.
|
||||
</audio>`
|
||||
: `[Audio belum diunduh]`;
|
||||
break;
|
||||
|
||||
case 'document':
|
||||
const filename = msgContent.filename || msg.file_name || 'Unduh Dokumen';
|
||||
content = msg.file_url
|
||||
? `<a href="${BASE_URL + msg.file_url}" target="_blank" class="text-decoration-none text-dark d-inline-block" style="width: 100%; max-width: 400px;">
|
||||
<div style="
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border: 1px solid #ececec;
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
background-color: #f9f9f9;
|
||||
width: 100%;
|
||||
">
|
||||
<i class="fa fa-file fa-2x me-3 text-secondary"></i>
|
||||
<div style="flex-grow: 1; font-size: 14px; word-break: break-word;">
|
||||
${filename}
|
||||
</div>
|
||||
<i class="fa fa-download ms-3 text-muted"></i>
|
||||
</div>
|
||||
</a>`
|
||||
: `[Dokumen belum diunduh]`;
|
||||
break;
|
||||
|
||||
case 'sticker':
|
||||
content = msg.file_url
|
||||
? `<img src="${BASE_URL + msg.file_url}" alt="sticker" class="rounded" width="200px" style="margin-left: 100px">`
|
||||
: `[Stiker belum diunduh]`;
|
||||
break;
|
||||
|
||||
case 'location':
|
||||
content = msgContent.latitude && msgContent.longitude
|
||||
? `<a href="https://www.google.com/maps?q=${msgContent.latitude},${msgContent.longitude}" target="_blank">
|
||||
📍 ${msgContent.name || 'Lokasi'}<br>
|
||||
${msgContent.address || ''}
|
||||
</a>`
|
||||
: `[Lokasi kosong]`;
|
||||
break;
|
||||
|
||||
case 'contacts':
|
||||
content = Array.isArray(msgContent)
|
||||
? msgContent.map(c => `<div>👤 ${c.name || ''} - ${c.phone || ''}</div>`).join('')
|
||||
: `[Kontak kosong]`;
|
||||
break;
|
||||
|
||||
case 'button':
|
||||
content = msgContent.button
|
||||
? `<button class="btn btn-sm btn-primary">${msgContent.button}</button>`
|
||||
: `[Tombol kosong]`;
|
||||
break;
|
||||
|
||||
case 'interactive':
|
||||
if (msgContent.button_reply) {
|
||||
content = `✅ Tombol dipilih: ${msgContent.button_reply.title || ''}`;
|
||||
} else if (msgContent.list_reply) {
|
||||
content = `✅ List dipilih: ${msgContent.list_reply.title || ''}`;
|
||||
} else {
|
||||
content = `[Interaksi kosong]`;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
content = msg.message_body || '[Pesan kosong]';
|
||||
}
|
||||
|
||||
|
||||
html += `
|
||||
<div class="${align} mb-2" data-msg-id="${msg.id}">
|
||||
<span class="d-inline-block ${msg.message_type === 'sticker' ? '' : 'rounded p-2 bg-light text-dark'}" style="${widthMessageBox}">
|
||||
<span class="bubble-content text-start d-block">${formatWhatsAppBody(content)}</span>
|
||||
<div class="template-footer small text-muted d-flex justify-content-between align-items-center mt-1">
|
||||
<span></span>
|
||||
<span class="d-flex align-items-center ${msg.message_type === 'sticker' ? 'p-2 bg-white rounded' : ''}">
|
||||
<small class="me-1">${messageTime}</small>
|
||||
${statusIcon}
|
||||
</span>
|
||||
</div>
|
||||
</span>
|
||||
<p><i class="text-secondary" style="margin-left: 5px; margin-rigth: 5px; font-size: 14px">${captMessage}</i></p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
|
||||
|
||||
return messageDate + html;
|
||||
}
|
||||
|
||||
|
||||
// 🔹 Fungsi untuk ambil daftar sesi chat (20 per batch)
|
||||
function fetchSessions(reset = false) {
|
||||
if (isLoading || (!hasMore && !reset)) return;
|
||||
isLoading = true;
|
||||
|
||||
if (reset) {
|
||||
list.innerHTML = `
|
||||
<li class="list-group-item text-center text-muted">
|
||||
<div class="spinner-border spinner-border-sm"></div> Memuat chat...
|
||||
</li>`;
|
||||
offset = 0;
|
||||
hasMore = true;
|
||||
}
|
||||
|
||||
const params = new URLSearchParams({
|
||||
whatsapp_id: `<?= $_SESSION['whatsapp_id']; ?>`,
|
||||
limit,
|
||||
offset,
|
||||
search: currentSearch,
|
||||
filter: currentFilter
|
||||
});
|
||||
|
||||
fetch(`<?= base_url("chat/getSessions") ?>?${params}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (reset) list.innerHTML = '';
|
||||
|
||||
if (!data.data || data.data.length === 0) {
|
||||
if (reset)
|
||||
list.innerHTML = `<li class="list-group-item text-center text-muted">Tidak ada sesi aktif</li>`;
|
||||
document.getElementById('btnTambahSession').style.display = 'block';
|
||||
hasMore = false;
|
||||
return;
|
||||
}
|
||||
|
||||
data.data.forEach(item => {
|
||||
const avatar = `https://ui-avatars.com/api/?name=${encodeURIComponent(item.customer_name || item.customer_number)}&background=random`;
|
||||
const lastMessage = (item.last_message?.length > 30)
|
||||
? item.last_message.substring(0, 30) + '...'
|
||||
: (item.last_message || '(belum ada pesan)');
|
||||
const time = item.last_message_at
|
||||
? new Date(item.last_message_at).toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit' })
|
||||
: '';
|
||||
const unread = (item.status === 'open');
|
||||
const unreadBadge = unread ? `<span class="badge unread"></span><br>` : '';
|
||||
|
||||
list.innerHTML += `
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item chat-item"
|
||||
data-id="${item.id}"
|
||||
data-name="${item.customer_name || 'Tanpa Nama'}"
|
||||
data-number="${item.customer_number || '+62'}"
|
||||
style="cursor:pointer;">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="${avatar}" class="rounded-circle me-3" width="40" height="40" alt="${item.customer_name || 'User'}">
|
||||
<div>
|
||||
|
||||
<strong>${phoneFormat(item.customer_number)}</strong><br>
|
||||
<small class="text-muted">${item.customer_name || 'Tanpa Nama'}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div style="text-align:right;">
|
||||
${unreadBadge}
|
||||
<small class="text-muted">${time}</small>
|
||||
</div>
|
||||
</li>`;
|
||||
});
|
||||
|
||||
|
||||
document.getElementById('btnTambahSession').style.display = 'none';
|
||||
|
||||
offset += limit;
|
||||
hasMore = offset < (data.total || offset);
|
||||
attachClickEvents();
|
||||
})
|
||||
.catch(() => {
|
||||
if (reset)
|
||||
list.innerHTML = `<li class="list-group-item text-danger text-center">Gagal memuat data</li>`;
|
||||
document.getElementById('btnTambahSession').style.display = 'block';
|
||||
})
|
||||
.finally(() => isLoading = false);
|
||||
}
|
||||
|
||||
// 🔹 Lazy load saat scroll
|
||||
chatContainer.addEventListener('scroll', function () {
|
||||
if (chatContainer.scrollTop + chatContainer.clientHeight >= chatContainer.scrollHeight - 50) {
|
||||
fetchSessions();
|
||||
}
|
||||
});
|
||||
|
||||
// 🔹 Pencarian
|
||||
// let searchTimeout;
|
||||
// searchInput.addEventListener('input', function () {
|
||||
// clearTimeout(searchTimeout);
|
||||
// searchTimeout = setTimeout(() => {
|
||||
// currentSearch = this.value.trim();
|
||||
// fetchSessions(true);
|
||||
// }, 400);
|
||||
// });
|
||||
|
||||
let searchTimeout;
|
||||
|
||||
searchInput.addEventListener('input', function () {
|
||||
clearTimeout(searchTimeout);
|
||||
|
||||
// 🔹 Hapus karakter non-angka
|
||||
let value = this.value.replace(/\D/g, '');
|
||||
|
||||
// 🔹 Jika dimulai dengan 0, ubah ke format +62
|
||||
if (value.startsWith('0')) {
|
||||
value = '62' + value.substring(1);
|
||||
}
|
||||
|
||||
// 🔹 Format tampilan: +62 812-3456-7890
|
||||
let formatted = value;
|
||||
if (formatted.startsWith('62')) {
|
||||
formatted = '+62 ';
|
||||
const numberPart = value.substring(2);
|
||||
if (numberPart.length > 0) {
|
||||
formatted += numberPart
|
||||
.replace(/^(\d{3})(\d{0,4})(\d{0,4}).*/, function (_, a, b, c) {
|
||||
let res = a;
|
||||
if (b) res += '-' + b;
|
||||
if (c) res += '-' + c;
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.value = formatted.trim();
|
||||
|
||||
// 🔹 Delay fetch agar tidak terlalu sering dipanggil
|
||||
searchTimeout = setTimeout(() => {
|
||||
// Ambil angka murni untuk pencarian (tanpa + dan strip)
|
||||
currentSearch = value;
|
||||
fetchSessions(true);
|
||||
}, 400);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 🔹 Filter tombol ==============================================================
|
||||
filterBtns.forEach(btn => {
|
||||
btn.addEventListener('click', function () {
|
||||
filterBtns.forEach(b => b.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
currentFilter = this.textContent.includes('Belum') ? 'unread' : 'all';
|
||||
fetchSessions(true);
|
||||
});
|
||||
});
|
||||
|
||||
function selectSession(sessionId) {
|
||||
const sendBtn = document.getElementById('sendBtn');
|
||||
const chatInputUI = document.getElementById('chatInputUI');
|
||||
sendBtn.dataset.id = sessionId; // set sessionId
|
||||
sendBtn.style.display = 'none'; // tampilkan tombol
|
||||
chatInputUI.style.display = 'inline-flex'; // tampilkan tombol
|
||||
document.getElementById('chatInput').value = ''; // reset input
|
||||
}
|
||||
|
||||
// 🔹 Pasang ulang event klik tiap chat item (pakai style & logika asli)
|
||||
function attachClickEvents() {
|
||||
document.querySelectorAll('.chat-item').forEach(el => {
|
||||
el.addEventListener('click', () => {
|
||||
|
||||
const sessionId = el.getAttribute('data-id');
|
||||
const nameId = el.getAttribute('data-name');
|
||||
const nameNumber = el.getAttribute('data-number');
|
||||
const avatarUser = `https://ui-avatars.com/api/?name=${encodeURIComponent(nameId || nameNumber)}&background=random`;
|
||||
|
||||
selectSession(sessionId);
|
||||
|
||||
// console.log("Klik session:", sessionId);
|
||||
|
||||
// Cek apakah nilai sebelumnya beda
|
||||
const oldSessionId = getCookie('sessionId');
|
||||
|
||||
if (oldSessionId !== sessionId) {
|
||||
document.cookie = `sessionId=${sessionId}; path=/; max-age=${7 * 24 * 60 * 60}; SameSite=Lax`;
|
||||
// console.log(`[Cookie] sessionId ${oldSessionId ? 'updated' : 'created'}: ${sessionId}`);
|
||||
} else {
|
||||
// console.log('[Cookie] sessionId unchanged:', sessionId);
|
||||
}
|
||||
|
||||
// --- Semua kode kamu untuk tampilkan pesan tetap sama di sini ---
|
||||
const chatWindow = document.getElementById('chatWindow');
|
||||
chatWindow.innerHTML = ``;
|
||||
|
||||
document.getElementById('chatName').innerHTML = nameId;
|
||||
document.getElementById('lastChat').innerHTML = phoneFormat(nameNumber);
|
||||
document.getElementById('imageTopbar').innerHTML = `
|
||||
<img src="${avatarUser}" class="rounded-circle me-3" width="40" height="40" alt="${nameId || nameNumber}">`;
|
||||
|
||||
function scrollToBottom() {
|
||||
if (chatWindow) {
|
||||
chatWindow.scrollTo({ top: chatWindow.scrollHeight, behavior: 'smooth' });
|
||||
}
|
||||
}
|
||||
|
||||
// Ambil pesan berdasarkan session
|
||||
fetch(`<?= base_url('chat/getMessages/') ?>${sessionId}`)
|
||||
.then(res => res.json())
|
||||
.then(async data => {
|
||||
if (!data.status || !data.data) {
|
||||
chatWindow.innerHTML = `
|
||||
<div class="text-center text-muted p-4">
|
||||
Tidak ada pesan dalam sesi ini.
|
||||
</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
// saat di klik load lagi sidebar nya
|
||||
fetchSessions(true);
|
||||
|
||||
// Urutkan pesan berdasarkan timestamp (jika ada)
|
||||
const sortedMessages = [...data.data].sort((a, b) => {
|
||||
const t1 = new Date(isNaN(a.timestamp) ? a.timestamp : a.timestamp * 1000);
|
||||
const t2 = new Date(isNaN(b.timestamp) ? b.timestamp : b.timestamp * 1000);
|
||||
return t1 - t2;
|
||||
});
|
||||
|
||||
let html = '';
|
||||
let lastDate = '27 April 1996'; // catat tanggal terakhir yang sudah ditampilkan
|
||||
|
||||
const lastDateRef = { value: null };
|
||||
|
||||
for (const msg of sortedMessages) {
|
||||
|
||||
const htmlOutput = await renderChatMessage(msg, lastDateRef);
|
||||
// console.log(msg);
|
||||
chatWindow.innerHTML += htmlOutput;
|
||||
}
|
||||
setTimeout(scrollToBottom, 100);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
chatWindow.innerHTML = `
|
||||
<div class="text-danger text-center p-4">
|
||||
Gagal memuat pesan.
|
||||
</div>`;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// === WebSocket listener ===
|
||||
fetchSessions(true);
|
||||
|
||||
// === INIT SOCKET PALING ATAS ===
|
||||
const socket = io('https://wacloud.manjapro.net', {
|
||||
path: '/node-chat/socket.io/',
|
||||
transports: ['websocket', 'polling']
|
||||
});
|
||||
|
||||
socket.on('connect', () => {
|
||||
socket.emit('user_login', <?= $_SESSION['whatsapp_id']; ?>);
|
||||
// console.log('Wesocket connected..!');
|
||||
});
|
||||
|
||||
const oldSessionId = getCookie('sessionId');
|
||||
|
||||
const notifAudio = new Audio('<?= base_url("assets/sounds/notif_1.mp3") ?>');
|
||||
let audioAllowed = false;
|
||||
|
||||
document.addEventListener('click', () => { audioAllowed = true; });
|
||||
|
||||
socket.on('new_message', async (data) => {
|
||||
if (!audioAllowed) return;
|
||||
notifAudio.currentTime = 0;
|
||||
notifAudio.play();
|
||||
|
||||
const oldSessionId = getCookie('sessionId');
|
||||
if (data.session_id == oldSessionId) {
|
||||
const chatWindow = document.getElementById('chatWindow');
|
||||
const lastDateRef = { value: null };
|
||||
|
||||
// Parse message JSON
|
||||
let msgData;
|
||||
try {
|
||||
msgData = typeof data.message === 'string' ? JSON.parse(data.message) : data.message;
|
||||
} catch (e) {
|
||||
console.error('Gagal parse JSON:', e);
|
||||
msgData = data;
|
||||
}
|
||||
|
||||
// 🧩 Tambahkan fallback: kalau name masih null, isi pakai session_id atau nilai lain
|
||||
if (!msgData.name || msgData.name === null) {
|
||||
msgData.name = `<?= $_SESSION['name']; ?>` || 'System';
|
||||
// console.log(msgData.name);
|
||||
}
|
||||
|
||||
// console.log(msgData);
|
||||
|
||||
// ✅ Tunggu hasil dari renderChatMessage
|
||||
const contentNew = await renderChatMessage(msgData, lastDateRef, false);
|
||||
|
||||
chatWindow.innerHTML += contentNew;
|
||||
|
||||
setTimeout(() => {
|
||||
chatWindow.scrollTo({ top: chatWindow.scrollHeight, behavior: 'smooth' });
|
||||
}, 100);
|
||||
|
||||
fetch(`<?= base_url('chat/updateSession/') ?>${oldSessionId}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
fetchSessions(true);
|
||||
}
|
||||
// console.log(data);
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
fetchSessions(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function phoneFormat(number) {
|
||||
// ubah ke string dulu
|
||||
let str = number.toString();
|
||||
|
||||
// pastikan dia mulai dengan "62"
|
||||
if (!str.startsWith('62')) return number;
|
||||
|
||||
// hapus 62 di depan untuk diproses
|
||||
str = str.slice(2);
|
||||
|
||||
// ambil bagian sesuai format: 3-4-4 (contoh: 858-7230-8826)
|
||||
const part1 = str.slice(0, 3);
|
||||
const part2 = str.slice(3, 7);
|
||||
const part3 = str.slice(7);
|
||||
|
||||
return `+62 ${part1}-${part2}-${part3}`;
|
||||
}
|
||||
|
||||
function playNotif() {
|
||||
if (audioAllowed) {
|
||||
notifAudio.play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// const chatInput = document.getElementById('chatInput');
|
||||
// const sendBtn = document.getElementById('sendBtn');
|
||||
const emojiButtons = document.querySelectorAll('.dropdown2-menu button');
|
||||
const dropdown = document.querySelector('.dropdown2');
|
||||
const emojiMenu = document.querySelector('.dropdown2-menu');
|
||||
const emojiToggle = document.getElementById('emojiToggle');
|
||||
|
||||
// Tombol Kirim muncul jika ada isi
|
||||
chatInput.addEventListener('input', () => {
|
||||
sendBtn.style.display = chatInput.value.trim() !== '' ? 'inline-flex' : 'none';
|
||||
});
|
||||
|
||||
// Toggle dropdown emoji
|
||||
emojiToggle.addEventListener('click', (e) => {
|
||||
e.stopPropagation(); // supaya klik tombol tidak menutup dropdown
|
||||
dropdown.classList.toggle('show');
|
||||
});
|
||||
|
||||
// Klik emoji menambahkan ke textarea
|
||||
emojiButtons.forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
e.stopPropagation(); // penting supaya dropdown tidak hilang
|
||||
const startPos = chatInput.selectionStart;
|
||||
const endPos = chatInput.selectionEnd;
|
||||
const textBefore = chatInput.value.substring(0, startPos);
|
||||
const textAfter = chatInput.value.substring(endPos);
|
||||
chatInput.value = textBefore + btn.textContent + textAfter;
|
||||
|
||||
const cursorPos = startPos + btn.textContent.length;
|
||||
chatInput.setSelectionRange(cursorPos, cursorPos);
|
||||
chatInput.focus();
|
||||
|
||||
chatInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
});
|
||||
|
||||
// Klik di luar dropdown menutupnya
|
||||
document.addEventListener('click', (e) => {
|
||||
if (!dropdown.contains(e.target)) {
|
||||
dropdown.classList.remove('show');
|
||||
}
|
||||
});
|
||||
|
||||
// Auto-expand textarea
|
||||
const textarea = document.querySelector('.chat-input textarea');
|
||||
textarea.addEventListener('input', function() {
|
||||
this.style.height = 'auto';
|
||||
this.style.height = Math.min(this.scrollHeight, 1.5*10*16) + 'px';
|
||||
});
|
||||
|
||||
// File handler
|
||||
function handleFile(input) {
|
||||
if (input.files.length > 0) {
|
||||
alert('File terpilih: ' + input.files[0].name);
|
||||
}
|
||||
}
|
||||
|
||||
// Dropdown toggle hanya saat klik tombol
|
||||
document.querySelectorAll('.dropdown2').forEach(drop => {
|
||||
const btn = drop.querySelector('.chat-btn');
|
||||
btn.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
document.querySelectorAll('.dropdown2').forEach(d => {
|
||||
if(d !== drop) d.classList.remove('show');
|
||||
});
|
||||
drop.classList.toggle('show');
|
||||
});
|
||||
});
|
||||
|
||||
// Klik di luar menutup semua dropdown
|
||||
document.addEventListener('click', () => {
|
||||
document.querySelectorAll('.dropdown2').forEach(drop => drop.classList.remove('show'));
|
||||
});
|
||||
|
||||
// Hover dropdown tetap terbuka saat mouse masuk
|
||||
document.querySelectorAll('.dropdown2-menu').forEach(menu => {
|
||||
menu.addEventListener('mouseenter', () => {
|
||||
menu.parentElement.classList.add('show');
|
||||
});
|
||||
menu.addEventListener('mouseleave', () => {
|
||||
menu.parentElement.classList.remove('show');
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.dropdown2-files').forEach(menu => {
|
||||
menu.addEventListener('mouseenter', () => {
|
||||
menu.parentElement.classList.add('show');
|
||||
});
|
||||
menu.addEventListener('mouseleave', () => {
|
||||
menu.parentElement.classList.remove('show');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
sendBtn.addEventListener('click', sendMessageOut);
|
||||
chatInput.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault(); // cegah newline
|
||||
sendMessageOut();
|
||||
}
|
||||
});
|
||||
|
||||
async function sendMessageOut() {
|
||||
const sessionId = sendBtn.dataset.id;
|
||||
const messageText = chatInput.value.trim();
|
||||
|
||||
if (!sessionId) {
|
||||
alert('Session belum dipilih!');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!messageText) {
|
||||
alert('Pesan kosong!');
|
||||
return;
|
||||
}
|
||||
|
||||
// Data tambahan untuk log
|
||||
const extraData = { user_id: 1 };
|
||||
|
||||
// Buat object pesan sementara untuk render awal
|
||||
const tempMsg = {
|
||||
id: 'temp-' + Date.now(), // id sementara unik
|
||||
direction: 'out',
|
||||
message_type: 'text',
|
||||
message_body: messageText,
|
||||
status: 'pending',
|
||||
timestamp: Math.floor(Date.now() / 1000),
|
||||
name: `<?= $_SESSION['name']; ?>`
|
||||
};
|
||||
|
||||
// Render awal ke UI
|
||||
appendMessageToChat(tempMsg, { value: null });
|
||||
|
||||
// Scroll otomatis
|
||||
const chatWindow = document.getElementById('chatWindow');
|
||||
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||
|
||||
// Reset Chat Input
|
||||
document.getElementById('chatInput').value = '';
|
||||
document.getElementById('sendBtn').style.display = 'none';
|
||||
|
||||
// Payload untuk server
|
||||
const payload = { session_id: sessionId, message: messageText, ...extraData };
|
||||
|
||||
try {
|
||||
const res = await fetch('<?= base_url(); ?>chat/sendMessageOut', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const response = await res.json();
|
||||
|
||||
if (response.success && response.data) {
|
||||
// Update pesan sementara dengan data dari server (id asli, status sent/delivered)
|
||||
const msgEl = document.querySelector(`[data-msg-id="${tempMsg.id}"]`);
|
||||
if (msgEl) {
|
||||
msgEl.outerHTML = await renderChatMessage(response.data, { value: null }, false);
|
||||
}
|
||||
|
||||
// Mulai polling untuk cek status read/failed
|
||||
pollMessageStatus(response.data.id,sessionId);
|
||||
} else {
|
||||
console.error('Gagal kirim pesan:', response.message);
|
||||
alert('Gagal kirim pesan: ' + response.message);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error:', err);
|
||||
alert('Terjadi kesalahan saat mengirim pesan.');
|
||||
}
|
||||
}
|
||||
|
||||
// Polling status pesan
|
||||
async function pollMessageStatus(msgId, sessionId) {
|
||||
const interval = 3000; // tiap 3 detik
|
||||
|
||||
const check = async () => {
|
||||
const cookiesSessionId = getCookie('sessionId');
|
||||
|
||||
// Hentikan polling jika sessionId di cookie berbeda
|
||||
if (sessionId !== cookiesSessionId) {
|
||||
// console.log('Polling dihentikan karena sessionId berubah.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`<?= base_url(); ?>chat/getMessageStatus/${msgId}`);
|
||||
const json = await res.json();
|
||||
|
||||
if (json.status && json.data && json.data.length > 0) {
|
||||
const msgData = json.data[0];
|
||||
|
||||
// Ubah timestamp string ke UNIX timestamp (detik)
|
||||
if (msgData.timestamp && isNaN(msgData.timestamp)) {
|
||||
msgData.timestamp = Math.floor(new Date(msgData.timestamp).getTime() / 1000);
|
||||
}
|
||||
|
||||
const msgEl = document.querySelector(`[data-msg-id="${msgId}"]`);
|
||||
if (msgEl) {
|
||||
msgEl.outerHTML = await renderChatMessage(msgData, { value: null }, false);
|
||||
}
|
||||
|
||||
// Stop polling jika status sudah final
|
||||
const status = (msgData.status || '').toLowerCase();
|
||||
if (status === 'read' || status === 'failed' || status === 'canceled') {
|
||||
// console.log('Polling dihentikan karena status final:', status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Polling error:', err);
|
||||
}
|
||||
|
||||
// Jadwalkan polling berikutnya
|
||||
setTimeout(check, interval);
|
||||
};
|
||||
|
||||
check();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Fungsi render pesan ke chat window
|
||||
async function appendMessageToChat(msg, lastDateRef = null) {
|
||||
const chatWindow = document.getElementById('chatWindow');
|
||||
|
||||
// Render konten pesan
|
||||
const contentNew = await renderChatMessage(msg, lastDateRef, false);
|
||||
|
||||
// Tambahkan ke chat window
|
||||
chatWindow.innerHTML += contentNew;
|
||||
|
||||
// Scroll ke bawah
|
||||
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
@@ -0,0 +1,184 @@
|
||||
<meta charset="UTF-8">
|
||||
<title><?= $title ?></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/png" href="<?= base_url('assets/img/icon.png'); ?>">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<style>
|
||||
body { background-color: #f0f2f5; }
|
||||
.chat-container { display: flex; height: 100vh; }
|
||||
.sidebar { width: 400px; background: #fff; border-right: 1px solid #ddd; overflow-y: auto; }
|
||||
.chat-window { flex: 1; background: #ece3daff; display: flex; flex-direction: column; }
|
||||
.chat-header { background: #ededed; padding: 10px; padding-left: 20px; border-bottom: 1px solid #ccc; }
|
||||
.chat-list { height: calc(100vh - 220px);}
|
||||
.messages { flex: 1; padding-left: 10%; padding-right: 10%; padding-top: 20px; padding-bottom: 30px; overflow-y: auto; }
|
||||
.message { margin-bottom: 10px; max-width: 55%; padding: 10px; border-radius: 10px; }
|
||||
.message.sent { background: #dcf8c6; align-self: flex-end; }
|
||||
.message.received { background: #fff; align-self: flex-start; }
|
||||
.chat-input-bg {
|
||||
height: 83px;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
min-width: 80%;
|
||||
background: #ece3daff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding-bottom: 10px;
|
||||
transform-origin: bottom;
|
||||
}
|
||||
|
||||
.chat-input {
|
||||
padding: 10px;
|
||||
border-top: 1px solid #ccc;
|
||||
background: #f0f0f0ff;
|
||||
margin: 10px;
|
||||
border-radius: 25px;
|
||||
width: 75%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
.chat-input textarea {
|
||||
flex: 1;
|
||||
border: none;
|
||||
outline: none;
|
||||
padding: 8px 12px;
|
||||
border-radius: 10px;
|
||||
font-size: 15px;
|
||||
resize: none;
|
||||
overflow-y: auto;
|
||||
max-height: calc(1.5em * 10 + 16px);
|
||||
line-height: 1.5em;
|
||||
}
|
||||
.chat-btn {
|
||||
border: none;
|
||||
background: none;
|
||||
color: #008069;
|
||||
font-size: 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
transition: background 0.2s;
|
||||
position: relative;
|
||||
}
|
||||
.chat-btn:hover { background: rgba(0,137,105,0.1); }
|
||||
|
||||
.dropdown2 { position: relative; }
|
||||
|
||||
.dropdown2-menu {
|
||||
display: none; /* default hidden */
|
||||
position: absolute;
|
||||
bottom: 45px;
|
||||
left: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 10px;
|
||||
padding: 8px;
|
||||
min-width: 345px;
|
||||
max-height: 500px;
|
||||
z-index: 100;
|
||||
overflow-y: auto;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
margin: 2px;
|
||||
}
|
||||
|
||||
.dropdown2-files {
|
||||
display: none; /* default hidden */
|
||||
position: absolute;
|
||||
bottom: 45px;
|
||||
left: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 10px;
|
||||
padding: 8px;
|
||||
min-width: 150px;
|
||||
max-height: 150px;
|
||||
z-index: 100;
|
||||
overflow-y: auto;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
margin: 1px;
|
||||
}
|
||||
|
||||
.dropdown2-files li { list-style: none; padding: 3px 12px; cursor: pointer; width: 100%;}
|
||||
.dropdown2-files li:hover, .dropdown2-menu button:hover { background: #f1f1f1; }
|
||||
.dropdown2-menu button {
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
font-size: 20px;
|
||||
border-radius: 6px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
/* Tampilkan saat .show ditambahkan */
|
||||
.dropdown2.show .dropdown2-menu,
|
||||
.dropdown2.show .dropdown2-files { display: flex; }
|
||||
|
||||
/* Badge biru untuk pesan belum dibaca */
|
||||
.badge.unread {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
background-color: #0d6efd;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
/* Hover effect untuk list item */
|
||||
.hover-item {
|
||||
transition: background 0.2s;
|
||||
cursor: pointer;
|
||||
}
|
||||
.hover-item:hover {
|
||||
background-color: #f1f1f1; /* warna abu muda saat hover */
|
||||
}
|
||||
|
||||
.filter-btn {
|
||||
flex: 1;
|
||||
margin: 0 2px;
|
||||
border-radius: 20px;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s ease-in-out;
|
||||
}
|
||||
.filter-btn.active {
|
||||
background-color: #0b93f6;
|
||||
color: #fff;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
||||
}
|
||||
.filter-btn:not(.active):hover {
|
||||
background-color: #e1f0ff;
|
||||
color: #0b93f6;
|
||||
}
|
||||
|
||||
.bubble-content {
|
||||
text-align: left !important;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.template-body {
|
||||
text-align: left !important;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.template-header {
|
||||
text-align: left !important;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.template-header img,
|
||||
.template-header video {
|
||||
max-width: 400px;
|
||||
object-fit: cover;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<?php $this->load->view('chat/layout/header', ['title' => $title ?? 'Chat']); ?>
|
||||
</head>
|
||||
<body>
|
||||
<audio id="notifAudio" src="<?= base_url('assets/sounds/notif_1.mp3') ?>" preload="auto"></audio>
|
||||
<div class="chat-app d-flex">
|
||||
<aside class="sidebar">
|
||||
<?php $this->load->view('chat/layout/sidebar'); ?>
|
||||
</aside>
|
||||
|
||||
<main class="chat-main flex-fill d-flex flex-column">
|
||||
<?php $this->load->view('chat/layout/topbar'); ?>
|
||||
<div id="chatContent" class="chat-content flex-fill position-relative">
|
||||
<?php $this->load->view($content_view); ?>
|
||||
</div>
|
||||
<?php $this->load->view('chat/layout/footer'); ?>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,122 @@
|
||||
<div class="d-flex align-items-center justify-content-between p-3 border-bottom bg-light position-relative">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://ui-avatars.com/api/?name=<?= $_SESSION['name']; ?>&background=random" width="50" height="50" class="rounded-circle me-3" alt="Profile CS">
|
||||
<div>
|
||||
<strong><?= $_SESSION['name']; ?></strong><br>
|
||||
<small class="text-muted">Online</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-sm btn-light" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-ellipsis-vertical"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuButton">
|
||||
<li><a class="dropdown-item" href="#">Profil</a></li>
|
||||
<li><a class="dropdown-item" href="#">Pengaturan</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item text-danger" href="<?= base_url('auth/logout'); ?>">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
// print_r($_SESSION); ?>
|
||||
</div>
|
||||
|
||||
<!-- PENCARIAN CHAT -->
|
||||
<div class="p-3 border-bottom bg-white">
|
||||
<div class="position-relative mb-2">
|
||||
<!-- <input type="text" id="searchChat" class="form-control pe-5" placeholder="Cari nomor terdaftar..."> -->
|
||||
<input type="text" id="searchChat" class="form-control mb-2" placeholder="Cari atau mulai chat baru...">
|
||||
|
||||
<!-- Tombol tambah diletakkan absolut agar tidak ikut event flex -->
|
||||
<div class="position-absolute top-0 end-0 me-1 mt-1">
|
||||
<button class="btn btn-outline-primary btn-sm" type="button" id="btnTambahSession" style="display: none;">
|
||||
<i class="fas fa-user-plus"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tombol Filter Stylish -->
|
||||
<div class="d-flex justify-content-between px-1">
|
||||
<button class="btn btn-sm btn-outline-primary filter-btn active" data-filter="all">Semua</button>
|
||||
<button class="btn btn-sm btn-outline-primary filter-btn" data-filter="unread">Belum Dibaca</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-list overflow-auto">
|
||||
<?php $this->load->view('chat/components/chat_list'); ?>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
document.getElementById('btnTambahSession').addEventListener('click', function () {
|
||||
const input = document.getElementById('searchChat');
|
||||
let raw = input.value.replace(/\D/g, ''); // hanya angka
|
||||
|
||||
// Ubah awalan 0 jadi 62
|
||||
if (raw.startsWith('0')) {
|
||||
raw = '62' + raw.substring(1);
|
||||
}
|
||||
|
||||
if (!raw || raw.length < 9) {
|
||||
Swal.fire({
|
||||
toast: true,
|
||||
position: 'top-end',
|
||||
icon: 'warning',
|
||||
title: 'Nomor tidak valid!',
|
||||
text: 'Masukkan nomor WhatsApp dengan benar.',
|
||||
showConfirmButton: false,
|
||||
timer: 2000,
|
||||
timerProgressBar: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 🔹 Kirim POST ke controller
|
||||
fetch("<?= base_url('chat/getContact') ?>", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: "number=" + encodeURIComponent(raw)
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
console.log("Response:", data);
|
||||
|
||||
const iconType = data.status === 'success' ? 'success' : 'error';
|
||||
const titleText = data.status === 'success' ? 'Berhasil!' : 'Gagal!';
|
||||
const messageText = data.message || (data.status === 'success'
|
||||
? 'Chat baru berhasil ditambahkan!'
|
||||
: 'Terjadi kesalahan saat menambah chat.');
|
||||
|
||||
Swal.fire({
|
||||
toast: true,
|
||||
position: 'top-end',
|
||||
icon: iconType,
|
||||
title: titleText,
|
||||
text: messageText,
|
||||
showConfirmButton: false,
|
||||
timer: 2000,
|
||||
timerProgressBar: true,
|
||||
});
|
||||
|
||||
if (data.status === 'success') {
|
||||
input.value = ''; // reset input
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error("Error:", err);
|
||||
Swal.fire({
|
||||
toast: true,
|
||||
position: 'top-end',
|
||||
icon: 'error',
|
||||
title: 'Kesalahan!',
|
||||
text: 'Tidak dapat menghubungi server.',
|
||||
showConfirmButton: false,
|
||||
timer: 2000,
|
||||
timerProgressBar: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<div class="d-flex align-items-center justify-content-between p-3 border-bottom bg-white" style="height: 80px">
|
||||
<div class="d-flex align-items-center">
|
||||
<span id="imageTopbar"></span>
|
||||
<div>
|
||||
<strong id="chatName"></strong><br>
|
||||
<small class="text-muted" id="lastChat"></small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="me-3">
|
||||
<i class="fa fa-search me-3"></i>
|
||||
<i class="fa fa-ellipsis-v"></i>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
// halaman utama chat, memuat jendela percakapan
|
||||
$this->load->view('chat/components/chat_window');
|
||||
@@ -0,0 +1,4 @@
|
||||
<div class="d-flex flex-column justify-content-center align-items-center h-100 text-muted">
|
||||
<i class="fa fa-comments fa-3x mb-3"></i>
|
||||
<p>Pilih chat untuk memulai percakapan</p>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
<div class="d-flex justify-content-center align-items-center h-100">
|
||||
<div class="spinner-border text-primary" role="status"></div>
|
||||
</div>
|
||||
@@ -0,0 +1,291 @@
|
||||
<div class="chat-header d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<strong>Customer A</strong><br>
|
||||
<small>Online</small>
|
||||
</div>
|
||||
<i class="fa-solid fa-ellipsis-vertical"></i>
|
||||
</div>
|
||||
|
||||
<div class="messages d-flex flex-column">
|
||||
<div class="message received">Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊</div>
|
||||
<div class="message received">Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊</div>
|
||||
<div class="message received">Halo kak, saya mau tanya...Halo kak, saya mau tanya...Halo kak, saya mau tanya...Halo kak, saya mau tanya...Halo kak, saya mau tanya...Halo kak, saya mau tanya...Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊</div>
|
||||
<div class="message received">Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊Baik kak, silakan 😊Baik kak, silakan 😊Baik kak, silakan 😊Baik kak, silakan 😊Baik kak, silakan 😊</div>
|
||||
<div class="message received">Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊</div>
|
||||
<div class="message received">Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊</div>
|
||||
<div class="message received">Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊</div>
|
||||
<div class="message received">Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊</div>
|
||||
<div class="message received">Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊</div>
|
||||
<div class="message received">Halo kak, saya mau tanya...</div>
|
||||
<div class="message sent">Baik kak, silakan 😊</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="chat-input">
|
||||
|
||||
<!-- Tombol Attach / File -->
|
||||
<div class="dropdown2">
|
||||
<button type="button" class="chat-btn" title="Attach">
|
||||
<i class="fa-solid fa-paperclip"></i>
|
||||
</button>
|
||||
<ul class="dropdown2-files">
|
||||
<li>
|
||||
<label>
|
||||
<i class="fa-solid fa-image"></i> Gambar
|
||||
<input type="file" accept="image/*" style="display:none" onchange="handleFile(this)">
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<i class="fa-solid fa-file"></i> File
|
||||
<input type="file" accept=".pdf,.doc,.docx,.xls,.xlsx,.txt" style="display:none" onchange="handleFile(this)">
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Tombol Emoji -->
|
||||
<div class="dropdown2">
|
||||
<button type="button" class="chat-btn" id="emojiToggle" title="Emoji">
|
||||
<i class="fa-regular fa-face-smile"></i>
|
||||
</button>
|
||||
<div class="dropdown2-menu">
|
||||
<button>😀</button>
|
||||
<button>😃</button>
|
||||
<button>😄</button>
|
||||
<button>😁</button>
|
||||
<button>😆</button>
|
||||
<button>😅</button>
|
||||
<button>😂</button>
|
||||
<button>🤣</button>
|
||||
<button>😊</button>
|
||||
<button>😇</button>
|
||||
<button>🙂</button>
|
||||
<button>🙃</button>
|
||||
<button>😉</button>
|
||||
<button>😌</button>
|
||||
<button>😍</button>
|
||||
<button>🥰</button>
|
||||
<button>😘</button>
|
||||
<button>😗</button>
|
||||
<button>😙</button>
|
||||
<button>😚</button>
|
||||
<button>😋</button>
|
||||
<button>😛</button>
|
||||
<button>😜</button>
|
||||
<button>🤪</button>
|
||||
<button>😝</button>
|
||||
<button>🤑</button>
|
||||
<button>🤗</button>
|
||||
<button>🤭</button>
|
||||
<button>🤫</button>
|
||||
<button>🤔</button>
|
||||
<button>🤐</button>
|
||||
<button>🤨</button>
|
||||
<button>😐</button>
|
||||
<button>😑</button>
|
||||
<button>😶</button>
|
||||
<button>😏</button>
|
||||
<button>😒</button>
|
||||
<button>🙄</button>
|
||||
<button>😬</button>
|
||||
<button>🤥</button>
|
||||
<button>😌</button>
|
||||
<button>😔</button>
|
||||
<button>😪</button>
|
||||
<button>🤤</button>
|
||||
<button>😴</button>
|
||||
<button>😷</button>
|
||||
<button>🤒</button>
|
||||
<button>🤕</button>
|
||||
<button>🤢</button>
|
||||
<button>🤮</button>
|
||||
<button>🤧</button>
|
||||
<button>🥵</button>
|
||||
<button>🥶</button>
|
||||
<button>🥴</button>
|
||||
<button>😵</button>
|
||||
<button>🤯</button>
|
||||
<button>🤠</button>
|
||||
<button>🥳</button>
|
||||
<button>😎</button>
|
||||
<button>🤓</button>
|
||||
<button>🧐</button>
|
||||
<button>😕</button>
|
||||
<button>😟</button>
|
||||
<button>🙁</button>
|
||||
<button>☹️</button>
|
||||
<button>😮</button>
|
||||
<button>😯</button>
|
||||
<button>😲</button>
|
||||
<button>😳</button>
|
||||
<button>🥺</button>
|
||||
<button>😦</button>
|
||||
<button>😧</button>
|
||||
<button>😨</button>
|
||||
<button>😰</button>
|
||||
<button>😥</button>
|
||||
<button>😢</button>
|
||||
<button>😭</button>
|
||||
<button>😱</button>
|
||||
<button>😖</button>
|
||||
<button>😣</button>
|
||||
<button>😞</button>
|
||||
<button>😓</button>
|
||||
<button>😩</button>
|
||||
<button>😫</button>
|
||||
<button>🥱</button>
|
||||
<button>😤</button>
|
||||
<button>😡</button>
|
||||
<button>😠</button>
|
||||
<button>🤬</button>
|
||||
<button>😈</button>
|
||||
<button>👿</button>
|
||||
<button>💀</button>
|
||||
<button>☠️</button>
|
||||
<button>💩</button>
|
||||
<button>🤡</button>
|
||||
<button>👹</button>
|
||||
<button>👺</button>
|
||||
<button>👻</button>
|
||||
<button>👽</button>
|
||||
<button>👾</button>
|
||||
<button>🤖</button>
|
||||
<button>👍</button>
|
||||
<button>👎</button>
|
||||
<button>✊</button>
|
||||
<button>👊</button>
|
||||
<button>🤛</button>
|
||||
<button>🤜</button>
|
||||
<button>👏</button>
|
||||
<button>🙌</button>
|
||||
<button>👐</button>
|
||||
<button>🤲</button>
|
||||
<button>🙏</button>
|
||||
<button>🤝</button>
|
||||
<button>🤟</button>
|
||||
<button>🤘</button>
|
||||
<button>🤙</button>
|
||||
<button>💪</button>
|
||||
<button>✋</button>
|
||||
<button>🖐️</button>
|
||||
<button>🖖</button>
|
||||
<button>👌</button>
|
||||
<button>✌️</button>
|
||||
<button>🤏</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Input Pesan -->
|
||||
<textarea id="chatInput" placeholder="Ketik pesan..." rows="1"></textarea>
|
||||
|
||||
<!-- Tombol Kirim -->
|
||||
<button type="button" id="sendBtn" class="chat-btn" title="Kirim" style="display:none;">
|
||||
<i class="fa-solid fa-paper-plane"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
const chatInput = document.getElementById('chatInput');
|
||||
const sendBtn = document.getElementById('sendBtn');
|
||||
const emojiButtons = document.querySelectorAll('.dropdown2-menu button');
|
||||
const dropdown = document.querySelector('.dropdown2');
|
||||
const emojiMenu = document.querySelector('.dropdown2-menu');
|
||||
const emojiToggle = document.getElementById('emojiToggle');
|
||||
|
||||
// Tombol Kirim muncul jika ada isi
|
||||
chatInput.addEventListener('input', () => {
|
||||
sendBtn.style.display = chatInput.value.trim() !== '' ? 'inline-flex' : 'none';
|
||||
});
|
||||
|
||||
// Toggle dropdown emoji
|
||||
emojiToggle.addEventListener('click', (e) => {
|
||||
e.stopPropagation(); // supaya klik tombol tidak menutup dropdown
|
||||
dropdown.classList.toggle('show');
|
||||
});
|
||||
|
||||
// Klik emoji menambahkan ke textarea
|
||||
emojiButtons.forEach(btn => {
|
||||
btn.addEventListener('click', (e) => {
|
||||
e.stopPropagation(); // penting supaya dropdown tidak hilang
|
||||
const startPos = chatInput.selectionStart;
|
||||
const endPos = chatInput.selectionEnd;
|
||||
const textBefore = chatInput.value.substring(0, startPos);
|
||||
const textAfter = chatInput.value.substring(endPos);
|
||||
chatInput.value = textBefore + btn.textContent + textAfter;
|
||||
|
||||
const cursorPos = startPos + btn.textContent.length;
|
||||
chatInput.setSelectionRange(cursorPos, cursorPos);
|
||||
chatInput.focus();
|
||||
|
||||
chatInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
});
|
||||
|
||||
// Klik di luar dropdown menutupnya
|
||||
document.addEventListener('click', (e) => {
|
||||
if (!dropdown.contains(e.target)) {
|
||||
dropdown.classList.remove('show');
|
||||
}
|
||||
});
|
||||
|
||||
// Auto-expand textarea
|
||||
const textarea = document.querySelector('.chat-input textarea');
|
||||
textarea.addEventListener('input', function() {
|
||||
this.style.height = 'auto';
|
||||
this.style.height = Math.min(this.scrollHeight, 1.5*10*16) + 'px';
|
||||
});
|
||||
|
||||
// File handler
|
||||
function handleFile(input) {
|
||||
if (input.files.length > 0) {
|
||||
alert('File terpilih: ' + input.files[0].name);
|
||||
}
|
||||
}
|
||||
|
||||
// Dropdown toggle hanya saat klik tombol
|
||||
document.querySelectorAll('.dropdown2').forEach(drop => {
|
||||
const btn = drop.querySelector('.chat-btn');
|
||||
btn.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
document.querySelectorAll('.dropdown2').forEach(d => {
|
||||
if(d !== drop) d.classList.remove('show');
|
||||
});
|
||||
drop.classList.toggle('show');
|
||||
});
|
||||
});
|
||||
|
||||
// Klik di luar menutup semua dropdown
|
||||
document.addEventListener('click', () => {
|
||||
document.querySelectorAll('.dropdown2').forEach(drop => drop.classList.remove('show'));
|
||||
});
|
||||
|
||||
// Hover dropdown tetap terbuka saat mouse masuk
|
||||
document.querySelectorAll('.dropdown2-menu').forEach(menu => {
|
||||
menu.addEventListener('mouseenter', () => {
|
||||
menu.parentElement.classList.add('show');
|
||||
});
|
||||
menu.addEventListener('mouseleave', () => {
|
||||
menu.parentElement.classList.remove('show');
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.dropdown2-files').forEach(menu => {
|
||||
menu.addEventListener('mouseenter', () => {
|
||||
menu.parentElement.classList.add('show');
|
||||
});
|
||||
menu.addEventListener('mouseleave', () => {
|
||||
menu.parentElement.classList.remove('show');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,160 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title><?= $title ?></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body { background-color: #f0f2f5; }
|
||||
.chat-container { display: flex; height: 100vh; }
|
||||
.sidebar { width: 25%; background: #fff; border-right: 1px solid #ddd; overflow-y: auto; }
|
||||
.chat-window { flex: 1; background: #e5ddd5; display: flex; flex-direction: column; }
|
||||
.chat-header { background: #ededed; padding: 10px; padding-left: 20px; border-bottom: 1px solid #ccc; }
|
||||
.messages { flex: 1; padding-left: 8%; padding-right: 8%; padding-top: 20px; padding-bottom: 30px; overflow-y: auto; }
|
||||
.message { margin-bottom: 10px; max-width: 55%; padding: 10px; border-radius: 10px; }
|
||||
.message.sent { background: #dcf8c6; align-self: flex-end; }
|
||||
.message.received { background: #fff; align-self: flex-start; }
|
||||
.chat-input {
|
||||
padding: 10px;
|
||||
border-top: 1px solid #ccc;
|
||||
background: #f7f7f7;
|
||||
margin: 10px;
|
||||
border-radius: 20px;
|
||||
width: 75%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
.chat-input textarea {
|
||||
flex: 1;
|
||||
border: none;
|
||||
outline: none;
|
||||
padding: 8px 12px;
|
||||
border-radius: 10px;
|
||||
font-size: 15px;
|
||||
resize: none;
|
||||
overflow-y: auto;
|
||||
max-height: calc(1.5em * 10 + 16px);
|
||||
line-height: 1.5em;
|
||||
}
|
||||
.chat-btn {
|
||||
border: none;
|
||||
background: none;
|
||||
color: #008069;
|
||||
font-size: 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
transition: background 0.2s;
|
||||
position: relative;
|
||||
}
|
||||
.chat-btn:hover { background: rgba(0,137,105,0.1); }
|
||||
|
||||
.dropdown2 { position: relative; }
|
||||
|
||||
.dropdown2-menu {
|
||||
display: none; /* default hidden */
|
||||
position: absolute;
|
||||
bottom: 45px;
|
||||
left: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 10px;
|
||||
padding: 8px;
|
||||
min-width: 345px;
|
||||
max-height: 500px;
|
||||
z-index: 100;
|
||||
overflow-y: auto;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
margin: 2px;
|
||||
}
|
||||
|
||||
.dropdown2-files {
|
||||
display: none; /* default hidden */
|
||||
position: absolute;
|
||||
bottom: 45px;
|
||||
left: 0;
|
||||
background: #fff;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 10px;
|
||||
padding: 8px;
|
||||
min-width: 150px;
|
||||
max-height: 150px;
|
||||
z-index: 100;
|
||||
overflow-y: auto;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
margin: 1px;
|
||||
}
|
||||
|
||||
.dropdown2-files li { list-style: none; padding: 3px 12px; cursor: pointer; width: 100%;}
|
||||
.dropdown2-files li:hover, .dropdown2-menu button:hover { background: #f1f1f1; }
|
||||
.dropdown2-menu button {
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
font-size: 20px;
|
||||
border-radius: 6px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
/* Tampilkan saat .show ditambahkan */
|
||||
.dropdown2.show .dropdown2-menu,
|
||||
.dropdown2.show .dropdown2-files { display: flex; }
|
||||
|
||||
/* Badge biru untuk pesan belum dibaca */
|
||||
.badge.unread {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
background-color: #0d6efd;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
/* Hover effect untuk list item */
|
||||
.hover-item {
|
||||
transition: background 0.2s;
|
||||
cursor: pointer;
|
||||
}
|
||||
.hover-item:hover {
|
||||
background-color: #f1f1f1; /* warna abu muda saat hover */
|
||||
}
|
||||
|
||||
.filter-btn {
|
||||
flex: 1;
|
||||
margin: 0 2px;
|
||||
border-radius: 20px;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s ease-in-out;
|
||||
}
|
||||
.filter-btn.active {
|
||||
background-color: #0b93f6;
|
||||
color: #fff;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
||||
}
|
||||
.filter-btn:not(.active):hover {
|
||||
background-color: #e1f0ff;
|
||||
color: #0b93f6;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="chat-container">
|
||||
<div class="sidebar">
|
||||
<?php $this->load->view('chat2/sidebar'); ?>
|
||||
</div>
|
||||
<div class="chat-window">
|
||||
<?php $this->load->view('chat2/chat_window'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,182 @@
|
||||
<!-- PROFIL CS LOGIN -->
|
||||
<div class="d-flex align-items-center justify-content-between p-3 border-bottom bg-light position-relative">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/50?img=12" class="rounded-circle me-3" alt="Profile CS">
|
||||
<div>
|
||||
<strong>Nama Customer Service</strong><br>
|
||||
<small class="text-muted">Online</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-sm btn-light" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fa-solid fa-ellipsis-vertical"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="dropdownMenuButton">
|
||||
<li><a class="dropdown-item" href="#">Profil</a></li>
|
||||
<li><a class="dropdown-item" href="#">Pengaturan</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item text-danger" href="#">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PENCARIAN CHAT -->
|
||||
<div class="p-3 border-bottom bg-white">
|
||||
<input type="text" class="form-control mb-2" placeholder="Cari atau mulai chat baru...">
|
||||
|
||||
<!-- Tombol Filter Stylish -->
|
||||
<div class="d-flex justify-content-between mb-2 px-1">
|
||||
<button class="btn btn-sm btn-outline-primary filter-btn active">Semua</button>
|
||||
<button class="btn btn-sm btn-outline-primary filter-btn">Belum Dibaca</button>
|
||||
<button class="btn btn-sm btn-outline-primary filter-btn">Group</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- DAFTAR CHAT -->
|
||||
<ul class="list-group list-group-flush">
|
||||
<!-- Belum dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/40" class="rounded-circle me-3" alt="Admin 1">
|
||||
<div>
|
||||
<strong>Admin 1</strong><br>
|
||||
<small>Pesan terakhir...</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge unread"></span>
|
||||
</li>
|
||||
|
||||
<!-- Sudah dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/41" class="rounded-circle me-3" alt="Customer A">
|
||||
<div>
|
||||
<strong>Customer A</strong><br>
|
||||
<small>Halo kak, saya mau tanya...</small>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<!-- Belum dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/42" class="rounded-circle me-3" alt="Customer B">
|
||||
<div>
|
||||
<strong>Customer B</strong><br>
|
||||
<small>Ada info terbaru?</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge unread"></span>
|
||||
</li>
|
||||
<!-- Belum dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/40" class="rounded-circle me-3" alt="Admin 1">
|
||||
<div>
|
||||
<strong>Admin 1</strong><br>
|
||||
<small>Pesan terakhir...</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge unread"></span>
|
||||
</li>
|
||||
|
||||
<!-- Sudah dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/41" class="rounded-circle me-3" alt="Customer A">
|
||||
<div>
|
||||
<strong>Customer A</strong><br>
|
||||
<small>Halo kak, saya mau tanya...</small>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<!-- Belum dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/42" class="rounded-circle me-3" alt="Customer B">
|
||||
<div>
|
||||
<strong>Customer B</strong><br>
|
||||
<small>Ada info terbaru?</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge unread"></span>
|
||||
</li>
|
||||
<!-- Belum dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/40" class="rounded-circle me-3" alt="Admin 1">
|
||||
<div>
|
||||
<strong>Admin 1</strong><br>
|
||||
<small>Pesan terakhir...</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge unread"></span>
|
||||
</li>
|
||||
|
||||
<!-- Sudah dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/41" class="rounded-circle me-3" alt="Customer A">
|
||||
<div>
|
||||
<strong>Customer A</strong><br>
|
||||
<small>Halo kak, saya mau tanya...</small>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<!-- Belum dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/42" class="rounded-circle me-3" alt="Customer B">
|
||||
<div>
|
||||
<strong>Customer B</strong><br>
|
||||
<small>Ada info terbaru?</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge unread"></span>
|
||||
</li>
|
||||
<!-- Belum dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/40" class="rounded-circle me-3" alt="Admin 1">
|
||||
<div>
|
||||
<strong>Admin 1</strong><br>
|
||||
<small>Pesan terakhir...</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge unread"></span>
|
||||
</li>
|
||||
|
||||
<!-- Sudah dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/41" class="rounded-circle me-3" alt="Customer A">
|
||||
<div>
|
||||
<strong>Customer A</strong><br>
|
||||
<small>Halo kak, saya mau tanya...</small>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<!-- Belum dibaca -->
|
||||
<li class="list-group-item d-flex align-items-center justify-content-between hover-item">
|
||||
<div class="d-flex align-items-center">
|
||||
<img src="https://i.pravatar.cc/42" class="rounded-circle me-3" alt="Customer B">
|
||||
<div>
|
||||
<strong>Customer B</strong><br>
|
||||
<small>Ada info terbaru?</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge unread"></span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<script>
|
||||
document.querySelectorAll('.filter-btn').forEach(btn => {
|
||||
btn.addEventListener('click', function() {
|
||||
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,258 @@
|
||||
<div class="container mt-4">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header">
|
||||
<h5>Dashbard</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<?php //print_r($phone_numbers); ?>
|
||||
|
||||
<div class="card-body">
|
||||
<form id="form-modern" class="form-row-modern">
|
||||
<!-- Nomor WhatsApp -->
|
||||
<div class="form-group-modern">
|
||||
<label class="form-label-modern" for="phone_number">Nomor WhatsApp</label>
|
||||
<select class="form-control-modern" name="phone_number" id="phone_number">
|
||||
<?php foreach ($phone_numbers as $p): ?>
|
||||
<option value="<?= $p->phone_number ?>">
|
||||
+<?= substr($p->phone_number, 0, 2) === '62' ? $p->phone_number : '62' . $p->phone_number ; echo ' ( ' . $p->number_name . ' )'; ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Range Tanggal -->
|
||||
<div class="form-group-modern">
|
||||
<label class="form-label-modern" for="date_range">Pilih Tanggal</label>
|
||||
<input type="text" id="date_range" class="form-control-modern" placeholder="Dari – Sampai">
|
||||
<input type="hidden" name="date_start" id="date_start">
|
||||
<input type="hidden" name="date_end" id="date_end">
|
||||
</div>
|
||||
|
||||
<div class="form-group-modern">
|
||||
<button type="submit" class="btn btn-primary btn-modern">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="grafik-container">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="card-body">
|
||||
<div id="grafik-summary"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<canvas id="grafik-analytics" height="120"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<canvas id="grafik-pricing" height="120" class="mt-4"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
let chartAnalytics = null;
|
||||
let chartPricing = null;
|
||||
|
||||
function formatDate(date, time) {
|
||||
const pad = n => n.toString().padStart(2, '0');
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${time}`;
|
||||
}
|
||||
|
||||
// Default 7 hari terakhir
|
||||
let defaultStart = new Date(); defaultStart.setDate(defaultStart.getDate() - 7);
|
||||
let defaultEnd = new Date(); defaultEnd.setDate(defaultEnd.getDate() - 1);
|
||||
document.getElementById('date_start').value = formatDate(defaultStart, "00:00:00");
|
||||
document.getElementById('date_end').value = formatDate(defaultEnd, "23:59:59");
|
||||
|
||||
// Flatpickr setup
|
||||
flatpickr("#date_range", {
|
||||
mode: "range",
|
||||
dateFormat: "Y-m-d",
|
||||
altInput: true,
|
||||
altFormat: "d M Y",
|
||||
defaultDate: [defaultStart, defaultEnd],
|
||||
onClose: function (selectedDates) {
|
||||
if (selectedDates.length === 2) {
|
||||
document.getElementById('date_start').value = formatDate(selectedDates[0], "00:00:00");
|
||||
document.getElementById('date_end').value = formatDate(selectedDates[1], "23:59:59");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function renderAnalyticsChart(points) {
|
||||
// 🔹 Tambah 7 jam (WIB offset)
|
||||
const labels = points.map(p => {
|
||||
const dateWIB = new Date((p.start + (7 * 3600)) * 1000);
|
||||
return dateWIB.toISOString().slice(0, 10);
|
||||
});
|
||||
|
||||
const sent = points.map(p => p.sent || 0);
|
||||
const delivered = points.map(p => p.delivered || 0);
|
||||
|
||||
if (chartAnalytics) chartAnalytics.destroy(); // 🔹 hapus grafik lama
|
||||
|
||||
chartAnalytics = new Chart(document.getElementById('grafik-analytics'), {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [
|
||||
{ label: 'Sent', data: sent, backgroundColor: 'rgba(0,123,255,0.6)' },
|
||||
{ label: 'Delivered', data: delivered, backgroundColor: 'rgba(40,167,69,0.6)' }
|
||||
]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
plugins: {
|
||||
title: { display: true, text: 'Analytics (Pesan Terkirim & Diterima)' },
|
||||
legend: { position: 'bottom' }
|
||||
},
|
||||
scales: {
|
||||
y: { beginAtZero: true, title: { display: true, text: 'Jumlah Pesan' } },
|
||||
x: { title: { display: true, text: 'Tanggal (WIB)' } }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 🔹 Ringkasan analytics
|
||||
const totalSent = sent.reduce((a, b) => a + b, 0);
|
||||
const totalDelivered = delivered.reduce((a, b) => a + b, 0);
|
||||
|
||||
return `
|
||||
<tr><td>Pesan Terkirim</td><td>${totalSent.toLocaleString()}</td></tr>
|
||||
<tr><td>Pesan Diterima</td><td>${totalDelivered.toLocaleString()}</td></tr>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
function renderPricingChart(rawData) {
|
||||
const dataArr = rawData.sort((a, b) => a.start - b.start);
|
||||
|
||||
// 🔹 Konversi timestamp ke tanggal WIB (UTC+7)
|
||||
const labels = dataArr.map(p => {
|
||||
const dateWIB = new Date((p.start + (7 * 3600)) * 1000);
|
||||
return dateWIB.toISOString().slice(0, 10);
|
||||
});
|
||||
|
||||
const volume = dataArr.map(p => p.volume || 0);
|
||||
const cost = dataArr.map(p => p.cost || 0);
|
||||
|
||||
if (chartPricing) chartPricing.destroy(); // 🔹 hapus grafik lama
|
||||
|
||||
chartPricing = new Chart(document.getElementById('grafik-pricing'), {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: labels,
|
||||
datasets: [{
|
||||
label: 'Volume',
|
||||
data: volume,
|
||||
borderColor: '#007bff',
|
||||
backgroundColor: 'rgba(0,123,255,0.1)',
|
||||
pointBackgroundColor: '#007bff',
|
||||
fill: false,
|
||||
tension: 0.3
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
plugins: {
|
||||
title: { display: true, text: 'Pricing Analytics (Volume per Hari - WIB)' },
|
||||
legend: { position: 'bottom' },
|
||||
tooltip: {
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.95)',
|
||||
borderColor: '#007bff',
|
||||
borderWidth: 1,
|
||||
titleColor: '#333',
|
||||
bodyColor: '#333',
|
||||
displayColors: false,
|
||||
padding: 12,
|
||||
cornerRadius: 8,
|
||||
usePointStyle: true,
|
||||
callbacks: {
|
||||
title: function (context) {
|
||||
return `📅 ${labels[context[0].dataIndex]}`;
|
||||
},
|
||||
label: function (context) {
|
||||
const index = context.dataIndex;
|
||||
return [
|
||||
`📦 Volume: ${volume[index].toLocaleString()}`,
|
||||
`💰 Harga: Rp ${cost[index].toLocaleString()}`
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
title: { display: true, text: 'Volume' },
|
||||
grid: { color: 'rgba(0,0,0,0.05)' }
|
||||
},
|
||||
x: {
|
||||
title: { display: true, text: 'Tanggal (WIB)' },
|
||||
grid: { color: 'rgba(0,0,0,0.05)' }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 🔹 Ringkasan pricing
|
||||
const totalVol = volume.reduce((a, b) => a + b, 0);
|
||||
const totalCost = cost.reduce((a, b) => a + b, 0);
|
||||
|
||||
return `
|
||||
<tr><td>Volume (Total)</td><td>${totalVol.toLocaleString()}</td></tr>
|
||||
<tr><td>Biaya (Total)</td><td>Rp ${totalCost.toLocaleString()}</td></tr>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
function loadGrafik() {
|
||||
const data = {
|
||||
phone_number: $('#phone_number').val(),
|
||||
date_start: $('#date_start').val(),
|
||||
date_end: $('#date_end').val()
|
||||
};
|
||||
|
||||
$.post("<?= base_url('dashboard/get_grafik') ?>", data, function (res) {
|
||||
if (typeof res === "string") res = JSON.parse(res);
|
||||
let summaryRows = "";
|
||||
|
||||
if (res.analytics?.data?.analytics) {
|
||||
summaryRows += renderAnalyticsChart(res.analytics.data.analytics.data_points || []);
|
||||
}
|
||||
|
||||
if (res.pricing_analytics?.data?.pricing_analytics) {
|
||||
summaryRows += renderPricingChart(res.pricing_analytics.data.pricing_analytics.data?.[0]?.data_points || []);
|
||||
}
|
||||
|
||||
if (summaryRows) {
|
||||
$('#grafik-summary').html(`
|
||||
<table class="table table-bordered table-sm mt-3">
|
||||
<thead class="thead-light">
|
||||
<tr><th>Kategori</th><th>Total</th></tr>
|
||||
</thead>
|
||||
<tbody>${summaryRows}</tbody>
|
||||
</table>
|
||||
`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(loadGrafik);
|
||||
$('#form-modern').on('submit', function (e) {
|
||||
e.preventDefault();
|
||||
loadGrafik();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,35 @@
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title mb-0">Form Tambah Device Baru</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (validation_errors()): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo validation_errors(); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php echo form_open('devices/create'); ?>
|
||||
<div class="mb-3">
|
||||
<label for="number_name" class="form-label">Nama Nomor</label>
|
||||
<input type="text" class="form-control" id="number_name" name="number_name" value="<?php echo set_value('number_name'); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="phone_number" class="form-label">Nomor Telepon</label>
|
||||
<input type="text" class="form-control" id="phone_number" name="phone_number" value="<?php echo set_value('phone_number'); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="phone_number_id" class="form-label">Phone Number ID</label>
|
||||
<input type="text" class="form-control" id="phone_number_id" name="phone_number_id" value="<?php echo set_value('phone_number_id'); ?>" required>
|
||||
</div>
|
||||
<div class="d-flex justify-content-end">
|
||||
<a href="<?php echo site_url('devices'); ?>" class="btn btn-secondary me-2">Batal</a>
|
||||
<button type="submit" class="btn btn-primary">Simpan Device</button>
|
||||
</div>
|
||||
<?php echo form_close(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,46 @@
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h1 class="h3">Daftar Device</h1>
|
||||
<a href="<?php echo site_url('devices/add'); ?>" class="btn btn-primary">
|
||||
<i class="bi bi-plus-circle"></i> Tambah Device Baru
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php if ($this->session->flashdata('success')): ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<?php echo $this->session->flashdata('success'); ?>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Nama</th>
|
||||
<th>Nomor Telepon</th>
|
||||
<th>Phone Number ID</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($devices)): ?>
|
||||
<?php foreach ($devices as $device): ?>
|
||||
<tr>
|
||||
<td><?php echo $device->id; ?></td>
|
||||
<td><?php echo $device->number_name; ?></td>
|
||||
<td><?php echo $device->phone_number; ?></td>
|
||||
<td><?php echo $device->phone_number_id; ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<tr>
|
||||
<td colspan="4" class="text-center text-muted py-4">Belum ada data device.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
echo "\nERROR: ",
|
||||
$heading,
|
||||
"\n\n",
|
||||
$message,
|
||||
"\n\n";
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
echo "\nDatabase error: ",
|
||||
$heading,
|
||||
"\n\n",
|
||||
$message,
|
||||
"\n\n";
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
|
||||
|
||||
An uncaught Exception was encountered
|
||||
|
||||
Type: <?php echo get_class($exception), "\n"; ?>
|
||||
Message: <?php echo $message, "\n"; ?>
|
||||
Filename: <?php echo $exception->getFile(), "\n"; ?>
|
||||
Line Number: <?php echo $exception->getLine(); ?>
|
||||
|
||||
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
Backtrace:
|
||||
<?php foreach ($exception->getTrace() as $error): ?>
|
||||
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
|
||||
File: <?php echo $error['file'], "\n"; ?>
|
||||
Line: <?php echo $error['line'], "\n"; ?>
|
||||
Function: <?php echo $error['function'], "\n\n"; ?>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php endif ?>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
echo "\nERROR: ",
|
||||
$heading,
|
||||
"\n\n",
|
||||
$message,
|
||||
"\n\n";
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
|
||||
|
||||
A PHP Error was encountered
|
||||
|
||||
Severity: <?php echo $severity, "\n"; ?>
|
||||
Message: <?php echo $message, "\n"; ?>
|
||||
Filename: <?php echo $filepath, "\n"; ?>
|
||||
Line Number: <?php echo $line; ?>
|
||||
|
||||
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
Backtrace:
|
||||
<?php foreach (debug_backtrace() as $error): ?>
|
||||
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
|
||||
File: <?php echo $error['file'], "\n"; ?>
|
||||
Line: <?php echo $error['line'], "\n"; ?>
|
||||
Function: <?php echo $error['function'], "\n\n"; ?>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php endif ?>
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>404 Page Not Found</title>
|
||||
<style type="text/css">
|
||||
|
||||
::selection { background-color: #E13300; color: white; }
|
||||
::-moz-selection { background-color: #E13300; color: white; }
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font: 13px/20px normal Helvetica, Arial, sans-serif;
|
||||
color: #4F5155;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #003399;
|
||||
background-color: transparent;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #444;
|
||||
background-color: transparent;
|
||||
border-bottom: 1px solid #D0D0D0;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 14px 0;
|
||||
padding: 14px 15px 10px 15px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, Monaco, Courier New, Courier, monospace;
|
||||
font-size: 12px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #D0D0D0;
|
||||
color: #002166;
|
||||
display: block;
|
||||
margin: 14px 0 14px 0;
|
||||
padding: 12px 10px 12px 10px;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin: 10px;
|
||||
border: 1px solid #D0D0D0;
|
||||
box-shadow: 0 0 8px #D0D0D0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 12px 15px 12px 15px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<h1><?php echo $heading; ?></h1>
|
||||
<?php echo $message; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Database Error</title>
|
||||
<style type="text/css">
|
||||
|
||||
::selection { background-color: #E13300; color: white; }
|
||||
::-moz-selection { background-color: #E13300; color: white; }
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font: 13px/20px normal Helvetica, Arial, sans-serif;
|
||||
color: #4F5155;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #003399;
|
||||
background-color: transparent;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #444;
|
||||
background-color: transparent;
|
||||
border-bottom: 1px solid #D0D0D0;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 14px 0;
|
||||
padding: 14px 15px 10px 15px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, Monaco, Courier New, Courier, monospace;
|
||||
font-size: 12px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #D0D0D0;
|
||||
color: #002166;
|
||||
display: block;
|
||||
margin: 14px 0 14px 0;
|
||||
padding: 12px 10px 12px 10px;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin: 10px;
|
||||
border: 1px solid #D0D0D0;
|
||||
box-shadow: 0 0 8px #D0D0D0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 12px 15px 12px 15px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<h1><?php echo $heading; ?></h1>
|
||||
<?php echo $message; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?>
|
||||
|
||||
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
|
||||
|
||||
<h4>An uncaught Exception was encountered</h4>
|
||||
|
||||
<p>Type: <?php echo get_class($exception); ?></p>
|
||||
<p>Message: <?php echo $message; ?></p>
|
||||
<p>Filename: <?php echo $exception->getFile(); ?></p>
|
||||
<p>Line Number: <?php echo $exception->getLine(); ?></p>
|
||||
|
||||
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
<p>Backtrace:</p>
|
||||
<?php foreach ($exception->getTrace() as $error): ?>
|
||||
|
||||
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
|
||||
|
||||
<p style="margin-left:10px">
|
||||
File: <?php echo $error['file']; ?><br />
|
||||
Line: <?php echo $error['line']; ?><br />
|
||||
Function: <?php echo $error['function']; ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Error</title>
|
||||
<style type="text/css">
|
||||
|
||||
::selection { background-color: #E13300; color: white; }
|
||||
::-moz-selection { background-color: #E13300; color: white; }
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font: 13px/20px normal Helvetica, Arial, sans-serif;
|
||||
color: #4F5155;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #003399;
|
||||
background-color: transparent;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #444;
|
||||
background-color: transparent;
|
||||
border-bottom: 1px solid #D0D0D0;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 14px 0;
|
||||
padding: 14px 15px 10px 15px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, Monaco, Courier New, Courier, monospace;
|
||||
font-size: 12px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #D0D0D0;
|
||||
color: #002166;
|
||||
display: block;
|
||||
margin: 14px 0 14px 0;
|
||||
padding: 12px 10px 12px 10px;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin: 10px;
|
||||
border: 1px solid #D0D0D0;
|
||||
box-shadow: 0 0 8px #D0D0D0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 12px 15px 12px 15px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<h1><?php echo $heading; ?></h1>
|
||||
<?php echo $message; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?>
|
||||
|
||||
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
|
||||
|
||||
<h4>A PHP Error was encountered</h4>
|
||||
|
||||
<p>Severity: <?php echo $severity; ?></p>
|
||||
<p>Message: <?php echo $message; ?></p>
|
||||
<p>Filename: <?php echo $filepath; ?></p>
|
||||
<p>Line Number: <?php echo $line; ?></p>
|
||||
|
||||
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
<p>Backtrace:</p>
|
||||
<?php foreach (debug_backtrace() as $error): ?>
|
||||
|
||||
<?php if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0): ?>
|
||||
|
||||
<p style="margin-left:10px">
|
||||
File: <?php echo $error['file'] ?><br />
|
||||
Line: <?php echo $error['line'] ?><br />
|
||||
Function: <?php echo $error['function'] ?>
|
||||
</p>
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
<?php endforeach ?>
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,59 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login Sistem</title>
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="card login-card shadow-sm">
|
||||
<div class="card-body p-5">
|
||||
<h3 class="card-title text-center mb-4">Admin Login</h3>
|
||||
|
||||
<?php if ($this->session->flashdata('error')): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?= $this->session->flashdata('error'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="<?= base_url('auth/login_process'); ?>" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" id="username" name="username" value="<?= set_value('username'); ?>" required>
|
||||
<small class="text-danger"><?= form_error('username'); ?></small>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
<small class="text-danger"><?= form_error('password'); ?></small>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bootstrap 5 JS -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,12 @@
|
||||
<!-- <footer class="bg-light text-center text-lg-start mt-auto">
|
||||
<div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.2);">
|
||||
© 2025 Hak Cipta:
|
||||
<a class="text-dark" href="#">SistemLogin.com</a>
|
||||
</div>
|
||||
</footer> -->
|
||||
|
||||
<!-- Bootstrap 5 JS Bundle -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,268 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="id">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="icon" type="image/png" href="<?= base_url('assets/img/icon.png'); ?>">
|
||||
<title>Halaman Admin</title>
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/js/all.min.js"
|
||||
referrerpolicy="no-referrer"></script>
|
||||
|
||||
<!-- Flatpickr CSS & JS -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
|
||||
|
||||
<style>
|
||||
/* Modern form style */
|
||||
.form-row-modern {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: flex-end;
|
||||
flex-wrap: wrap;
|
||||
zoom: 90%;
|
||||
}
|
||||
|
||||
.form-group-modern {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-label-modern {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 500;
|
||||
color: #555;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.form-control-modern {
|
||||
border-radius: 8px;
|
||||
border: 1px solid #ccc;
|
||||
padding: 0.5rem 0.75rem;
|
||||
transition: border 0.2s, box-shadow 0.2s;
|
||||
min-width: 250px;
|
||||
}
|
||||
|
||||
.form-control-modern:focus {
|
||||
border-color: #0d6efd;
|
||||
box-shadow: 0 0 0 0.2rem rgba(13,110,253,0.25);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.btn-modern {
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
padding: 0 1.2rem;
|
||||
}
|
||||
|
||||
/* ====== STYLE UTAMA UNTUK TABLE ====== */
|
||||
.table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.table th,
|
||||
.table td {
|
||||
border: 1px solid #dee2e6;
|
||||
padding: 8px 12px;
|
||||
vertical-align: middle; /* ⬇️ center secara vertikal */
|
||||
}
|
||||
|
||||
/* ====== HEADER TABLE (TH) CENTER HORIZONTAL & VERTIKAL ====== */
|
||||
.table thead th {
|
||||
text-align: center; /* ⬅️ center horizontal */
|
||||
vertical-align: middle; /* ⬇️ center vertikal */
|
||||
/*background-color: #f8f9fa;*/
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* ====== BODY TABLE (TD) DEFAULT: CENTER VERTIKAL SAJA ====== */
|
||||
.table tbody td {
|
||||
vertical-align: middle; /* ⬇️ center vertikal */
|
||||
text-align: left; /* default kiri (bisa diubah) */
|
||||
}
|
||||
|
||||
/* ====== OPSIONAL: ALIGN CONTROL ====== */
|
||||
/* Pusat horizontal */
|
||||
.center-h {
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
/* Pusat vertikal */
|
||||
.center-v {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
|
||||
/* Pusat vertikal + horizontal */
|
||||
.center-all {
|
||||
text-align: center !important;
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
|
||||
.mw-20 {
|
||||
max-width: 20px !important;
|
||||
}
|
||||
|
||||
.mw-70 {
|
||||
max-width: 70px !important;
|
||||
}
|
||||
|
||||
/* Warna dasar link */
|
||||
.navbar-nav .nav-link {
|
||||
color: #4b5563 !important; /* abu gelap */
|
||||
transition: all 0.25s ease;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Hover */
|
||||
.navbar-nav .nav-link:hover {
|
||||
color: #111827 !important; /* teks gelap */
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
/* Aktif */
|
||||
.navbar-nav .nav-link.active {
|
||||
color: #0d6efd !important; /* biru modern Bootstrap 5 */
|
||||
font-weight: 600;
|
||||
border-bottom: 2px solid #0d6efd;
|
||||
}
|
||||
|
||||
/* Hover ikon kanan */
|
||||
.navbar-nav.ms-auto .nav-link:hover i {
|
||||
color: #0d6efd !important;
|
||||
transform: scale(1.1);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
/* Responsif */
|
||||
@media (max-width: 991.98px) {
|
||||
.navbar-collapse {
|
||||
text-align: left !important;
|
||||
}
|
||||
|
||||
.navbar-nav {
|
||||
align-items: flex-start !important;
|
||||
}
|
||||
|
||||
.navbar-nav.ms-auto {
|
||||
margin-top: 0.5rem;
|
||||
align-items: flex-start !important;
|
||||
}
|
||||
|
||||
.navbar-nav .nav-link.active {
|
||||
border: none;
|
||||
background: rgba(13, 110, 253, 0.1);
|
||||
border-radius: 6px;
|
||||
padding-left: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm border-bottom">
|
||||
<div class="container">
|
||||
<!-- Brand -->
|
||||
<a class="navbar-brand fw-bold text-dark" href="<?= base_url('dashboard'); ?>">
|
||||
Sistem Panel
|
||||
</a>
|
||||
|
||||
<!-- Toggler -->
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<!-- Menu -->
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<!-- Menu kiri -->
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<?php
|
||||
$current = $this->uri->segment(1);
|
||||
$role = $this->session->userdata('role');
|
||||
?>
|
||||
|
||||
<?php if ($role == 'admin'): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link d-flex align-items-center gap-2 <?= $current == 'dashboard' ? 'active' : '' ?>" href="<?= base_url('dashboard'); ?>">
|
||||
<i class="fas fa-home"></i> <span>Dashboard</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link d-flex align-items-center gap-2 <?= $current == 'user_management' ? 'active' : '' ?>" href="<?= base_url('user_management'); ?>">
|
||||
<i class="fas fa-users-cog"></i> <span>Manajemen User</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link d-flex align-items-center gap-2 <?= $current == 'device' ? 'active' : '' ?>" href="<?= base_url('device'); ?>">
|
||||
<i class="fas fa-plug"></i> <span>Add Device</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link d-flex align-items-center gap-2 <?= $current == 'chat' ? 'active' : '' ?>" href="<?= base_url('chat'); ?>">
|
||||
<i class="fas fa-comments"></i> <span>Chat</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
|
||||
<!-- Menu kanan -->
|
||||
<ul class="navbar-nav ms-auto align-items-lg-center">
|
||||
<li class="nav-item me-lg-3">
|
||||
<a class="nav-link text-secondary" href="#" data-bs-toggle="modal" data-bs-target="#profileModal">
|
||||
<i class="fas fa-user-circle fa-2x"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-danger" href="<?= base_url('auth/logout'); ?>">
|
||||
<i class="fas fa-sign-out-alt fa-lg"></i>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Modal Profil User -->
|
||||
<div class="modal fade" id="profileModal" tabindex="-1" aria-labelledby="userModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-0 shadow-lg rounded-3">
|
||||
<div class="modal-header bg-light border-0">
|
||||
<h5 class="modal-title fw-bold" id="userModalLabel">
|
||||
<i class="fas fa-user-circle me-2 text-primary"></i> Profil Pengguna
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body text-center">
|
||||
<i class="fas fa-user-circle fa-5x text-secondary mb-3"></i>
|
||||
<h5 class="fw-semibold mb-1">
|
||||
<?= $this->session->userdata('name'); ?>
|
||||
</h5>
|
||||
<p class="text-muted small mb-3">
|
||||
<?= ucfirst($this->session->userdata('role')); ?>
|
||||
</p>
|
||||
|
||||
<div class="text-start px-4">
|
||||
<p class="mb-1"><strong>Email:</strong> <?= $this->session->userdata('email'); ?></p>
|
||||
<p class="mb-1"><strong>Username:</strong> <?= $this->session->userdata('username'); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer border-0 d-flex justify-content-between px-4 pb-4">
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">
|
||||
<i class="fas fa-times me-1"></i> Tutup
|
||||
</button>
|
||||
<a href="<?= base_url('auth/logout'); ?>" class="btn btn-danger">
|
||||
<i class="fas fa-sign-out-alt me-1"></i> Logout
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title w-100 text-center">Tambah User</h5>
|
||||
</div>
|
||||
|
||||
<form id="formUser" action="<?= base_url('user_management/save'); ?>" method="post">
|
||||
<div class="modal-body">
|
||||
<div class="form-group mb-3">
|
||||
<label>Nama</label>
|
||||
<input type="text" name="name" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label>Username</label>
|
||||
<input type="text" name="username" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label>Password</label>
|
||||
<input type="text" name="password" class="form-control" required>
|
||||
</div>
|
||||
<?php if($_SESSION['user_id'] == 1) { ?>
|
||||
<div class="form-group mb-3">
|
||||
<label>Role</label>
|
||||
<select class="form-control" name="role" required>
|
||||
<option value="">--- Pilih Role ---</option>
|
||||
<option value="admin">Admin</option>
|
||||
<option value="user">User</option>
|
||||
</select>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="form-group mb-3">
|
||||
<label>WhatsApp Number</label>
|
||||
<select class="form-control" name="whatsapp_id" required>
|
||||
<option value="">--- Pilih ---</option>
|
||||
<?php foreach ($phone_numbers as $p): ?>
|
||||
<option value="<?= $p->id ?>">
|
||||
<?= substr($p->phone_number, 0, 2) === '62' ? $p->phone_number : '62' . $p->phone_number ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Simpan</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,42 @@
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title w-100 text-center">Edit User</h5>
|
||||
</div>
|
||||
|
||||
<form id="formUser" action="<?= site_url('user_management/save'); ?>" method="post">
|
||||
<input type="hidden" name="id" value="<?= $user->id; ?>">
|
||||
<div class="modal-body">
|
||||
<div class="form-group mb-3">
|
||||
<label>Nama</label>
|
||||
<input type="text" name="name" value="<?= $user->name; ?>" class="form-control" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label>Username</label>
|
||||
<input type="text" name="username" value="<?= $user->username; ?>" class="form-control" required>
|
||||
</div>
|
||||
<?php if($_SESSION['user_id'] == 1) { ?>
|
||||
<div class="form-group mb-3">
|
||||
<label>Role</label>
|
||||
<select class="form-control" name="role" required>
|
||||
<option value="">--- Pilih Role ---</option>
|
||||
<option value="admin" <?= ($user->role == 'admin') ? 'selected' : '' ?>>Admin</option>
|
||||
<option value="user" <?= ($user->role == 'user') ? 'selected' : '' ?>>User</option>
|
||||
</select>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="form-group mb-3">
|
||||
<label>WhatsApp Number</label>
|
||||
<select class="form-control" name="whatsapp_id" required>
|
||||
<option value="">--- Pilih ---</option>
|
||||
<?php foreach ($phone_numbers as $p): ?>
|
||||
<option value="<?= $p->id ?>" <?= ($user->whatsapp_id == $p->id) ? 'selected' : '' ?>>
|
||||
<?= substr($p->phone_number, 0, 2) === '62' ? $p->phone_number : '62' . $p->phone_number ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Update</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -0,0 +1,155 @@
|
||||
<div class="container mt-4">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-6 center-v">
|
||||
<h5>Daftar User Management</h5>
|
||||
</div>
|
||||
<div class="col-6 text-end">
|
||||
<button class="btn btn-primary btn-sm mb-3" id="btnAdd">Tambah User</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-bordered" id="userTable">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th class="mw-20">No</th>
|
||||
<th>Nama</th>
|
||||
<th>Username</th>
|
||||
<th>Role</th>
|
||||
<th class="mw-70">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="userModal" tabindex="-1" aria-labelledby="userModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content" id="modalContent">
|
||||
<!-- konten add/edit akan dimuat via AJAX -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
|
||||
// 🔹 Load Data Awal
|
||||
function loadData() {
|
||||
$.ajax({
|
||||
url: "<?= base_url('user_management/get_list'); ?>",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(res) {
|
||||
let html = "";
|
||||
if (res.length > 0) {
|
||||
$.each(res, function(i, row) {
|
||||
html += `
|
||||
<tr>
|
||||
<td class="center-all mw-20">${i+1}</td>
|
||||
<td>${row.name}</td>
|
||||
<td>${row.username}</td>
|
||||
<td class="center-all">${row.role}</td>
|
||||
<td class="center-all mw-70">
|
||||
<button class="btn btn-sm btn-warning btnEdit" style="margin-right: 5px;" data-id="${row.id}">Edit</button>
|
||||
<button class="btn btn-sm btn-danger btnDelete" data-id="${row.id}">Hapus</button>
|
||||
</td>
|
||||
</tr>`;
|
||||
});
|
||||
} else {
|
||||
html = `<tr><td colspan="4" class="text-center">Belum ada data</td></tr>`;
|
||||
}
|
||||
$("#userTable tbody").html(html);
|
||||
}
|
||||
});
|
||||
}
|
||||
loadData();
|
||||
|
||||
// 🔹 Tombol Tambah
|
||||
$("#btnAdd").on("click", function() {
|
||||
$("#modalContent").load("<?= base_url('user_management/add'); ?>", function() {
|
||||
$("#userModal").modal("show");
|
||||
});
|
||||
});
|
||||
|
||||
// 🔹 Tombol Edit
|
||||
$(document).on("click", ".btnEdit", function() {
|
||||
let id = $(this).data("id");
|
||||
$("#modalContent").load("<?= base_url('user_management/edit/'); ?>" + id, function() {
|
||||
$("#userModal").modal("show");
|
||||
});
|
||||
});
|
||||
|
||||
// 🔹 Submit Form Add/Edit
|
||||
$(document).on("submit", "#formUser", function(e) {
|
||||
e.preventDefault();
|
||||
let form = $(this);
|
||||
$.ajax({
|
||||
url: form.attr("action"),
|
||||
type: "POST",
|
||||
data: form.serialize(),
|
||||
dataType: "json",
|
||||
success: function(res) {
|
||||
if (res.status == "success") {
|
||||
$("#userModal").modal("hide");
|
||||
loadData();
|
||||
Swal.fire("Berhasil!", res.message, "success");
|
||||
} else {
|
||||
Swal.fire("Gagal!", res.message, "error");
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire("Error!", "Terjadi kesalahan pada server", "error");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 🔹 DELETE DENGAN SWEETALERT
|
||||
$(document).on("click", ".btnDelete", function() {
|
||||
const id = $(this).data("id");
|
||||
|
||||
Swal.fire({
|
||||
title: "Yakin hapus user ini?",
|
||||
text: "Data yang dihapus tidak dapat dikembalikan!",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#d33",
|
||||
cancelButtonColor: "#3085d6",
|
||||
confirmButtonText: "Ya, hapus!",
|
||||
cancelButtonText: "Batal"
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
url: "<?= site_url('user_management/delete/'); ?>" + id,
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
success: function(res) {
|
||||
if (res.status === "success") {
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Berhasil!",
|
||||
text: res.message,
|
||||
timer: 1500,
|
||||
showConfirmButton: false
|
||||
});
|
||||
loadData();
|
||||
} else {
|
||||
Swal.fire("Gagal!", res.message, "error");
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire("Error!", "Terjadi kesalahan di server.", "error");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Welcome to CodeIgniter</title>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
::selection { background-color: #E13300; color: white; }
|
||||
::-moz-selection { background-color: #E13300; color: white; }
|
||||
|
||||
body {
|
||||
background-color: #fff;
|
||||
margin: 40px;
|
||||
font: 13px/20px normal Helvetica, Arial, sans-serif;
|
||||
color: #4F5155;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #003399;
|
||||
background-color: transparent;
|
||||
font-weight: normal;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #97310e;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #444;
|
||||
background-color: transparent;
|
||||
border-bottom: 1px solid #D0D0D0;
|
||||
font-size: 19px;
|
||||
font-weight: normal;
|
||||
margin: 0 0 14px 0;
|
||||
padding: 14px 15px 10px 15px;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, Monaco, Courier New, Courier, monospace;
|
||||
font-size: 12px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #D0D0D0;
|
||||
color: #002166;
|
||||
display: block;
|
||||
margin: 14px 0 14px 0;
|
||||
padding: 12px 10px 12px 10px;
|
||||
}
|
||||
|
||||
#body {
|
||||
margin: 0 15px 0 15px;
|
||||
min-height: 96px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0 0 10px;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
p.footer {
|
||||
text-align: right;
|
||||
font-size: 11px;
|
||||
border-top: 1px solid #D0D0D0;
|
||||
line-height: 32px;
|
||||
padding: 0 10px 0 10px;
|
||||
margin: 20px 0 0 0;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin: 10px;
|
||||
border: 1px solid #D0D0D0;
|
||||
box-shadow: 0 0 8px #D0D0D0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
<h1>Welcome to CodeIgniter!</h1>
|
||||
|
||||
<div id="body">
|
||||
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
|
||||
|
||||
<p>If you would like to edit this page you'll find it located at:</p>
|
||||
<code>application/views/welcome_message.php</code>
|
||||
|
||||
<p>The corresponding controller for this page is found at:</p>
|
||||
<code>application/controllers/Welcome.php</code>
|
||||
|
||||
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="userguide3/">User Guide</a>.</p>
|
||||
</div>
|
||||
|
||||
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user