المحامي احمد الحسين محمد




نبذة عني

مجالات الخبرة

قضايا قانونية


جاري تحميل القضايا…

تقييمات العملاء

const blogUrl = "https://www.egquiz.com"; const label = "r2a0pWwQjKanuLDCpupz8HEQnPC3"; const resultsPerPage = 8; // عدد القضايا في كل صفحة const maxPostsToFetch = 500; // الحد الأقصى للقضايا لجلبها (حد API)

const gridContainer = document.querySelector(".cases-grid"); const loadMoreBtn = document.getElementById("loadMoreBtn"); const loadMoreContainer = document.querySelector(".load-more-container"); const searchInput = document.getElementById("searchInput");

let allCases = []; // مصفوفة لتخزين جميع القضايا let displayedCount = 0; // عدد القضايا المعروضة حاليًا

// 1. دالة لإنشاء البطاقة (بدون تغيير) function createCaseCard(post) { const postTitle = post.title.$t; let postUrl = '#'; if (post.link) { for (let i = 0; i < post.link.length; i++) { if (post.link[i].rel === 'alternate') { postUrl = post.link[i].href; break; } } } const contentHtml = post.content ? post.content.$t : ''; const tempDiv = document.createElement('div'); tempDiv.innerHTML = contentHtml; const descriptionElement = tempDiv.querySelector('pre.case-description'); const description = descriptionElement ? descriptionElement.textContent : "لا يتوفر وصف..."; post.searchableDescription = description.toLowerCase(); // إضافة الوصف للبحث const publishedDate = new Date(post.published.$t); const formattedDate = new Intl.DateTimeFormat('ar-EG', { day: 'numeric', month: 'long', year: 'numeric' }).format(publishedDate); const caseCard = document.createElement('article'); caseCard.className = 'case-card'; caseCard.innerHTML = `

${postTitle}

${description}

`; return caseCard; }

// 2. دالة لعرض مجموعة من القضايا function displayCases(cases) { cases.forEach(caseData => { const card = createCaseCard(caseData); gridContainer.appendChild(card); }); }

// 3. دالة "عرض المزيد" function loadMoreCases() { const remainingCases = allCases.slice(displayedCount, displayedCount + resultsPerPage); displayCases(remainingCases); displayedCount += remainingCases.length;

// إخفاء الزر إذا لم يعد هناك المزيد لعرضه if (displayedCount >= allCases.length) { loadMoreContainer.style.display = 'none'; } }

// 4. وظيفة البحث searchInput.addEventListener('input', function() { const searchTerm = this.value.toLowerCase().trim();

if (searchTerm === "") { gridContainer.innerHTML = ''; displayedCount = 0; loadMoreCases(); // *** التصحيح هنا أيضاً: إظهار الزر عند مسح البحث *** if (allCases.length > displayedCount) { loadMoreContainer.style.display = 'block'; } return; }

const filteredCases = allCases.filter(caseData => { const title = caseData.title.$t.toLowerCase(); const description = caseData.searchableDescription || ""; return title.includes(searchTerm) || description.includes(searchTerm); });

gridContainer.innerHTML = ''; loadMoreContainer.style.display = 'none';

if (filteredCases.length > 0) { displayCases(filteredCases); } else { gridContainer.innerHTML = '

لم يتم العثور على نتائج.

'; } });

// 5. جلب جميع القضايا عند تحميل الصفحة function fetchAllCases() { const apiUrl = `${blogUrl}/feeds/posts/default/-/${encodeURIComponent(label)}?alt=json-in-script&max-results=${maxPostsToFetch}&callback=processAllCases`;

window.processAllCases = function(data) { allCases = data.feed.entry || []; gridContainer.innerHTML = '';

if (allCases.length > 0) { loadMoreCases(); // عرض أول دفعة من القضايا

// *** ⭐ التصحيح الرئيسي هنا ⭐ *** // بعد عرض الدفعة الأولى، تحقق إذا كان هناك المزيد لإظهار الزر if (allCases.length > displayedCount) { loadMoreContainer.style.display = 'block'; }

} else { gridContainer.innerHTML = '

لا توجد قضايا لعرضها حاليًا.

'; loadMoreContainer.style.display = 'none'; } };

const script = document.createElement('script'); script.src = apiUrl; document.body.appendChild(script); script.onload = () => document.body.removeChild(script); }

loadMoreBtn.addEventListener('click', loadMoreCases);

fetchAllCases(); });

// 1. دمج جميع دوال Firebase المطلوبة في استيراد واحد import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js"; import { getFirestore, doc, getDoc, updateDoc, collection, addDoc } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js"; import { getAuth, onAuthStateChanged } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-auth.js";

// 2. تعريف وتهيئة Firebase مرة واحدة فقط const firebaseConfig = { apiKey: "AIzaSyCXUgLNYwKB9_wrOONQOrD8mlO2zdp4tuc", authDomain: "derby1.firebaseapp.com", projectId: "derby1", storageBucket: "derby1.appspot.com", messagingSenderId: "839166015287", appId: "1:839166015287:web:786225f8220461ea9d0cb2" };

const app = initializeApp(firebaseConfig); const db = getFirestore(app); const auth = getAuth(app);

// ================================================================= // القسم الثاني: تعريف الدوال والوظائف // =================================================================

// --- دالة إنشاء نافذة "طلب استشارة" (من الكود الأول) --- function createAndShowModal(targetLawyerUid, targetLawyerName) { const modalOverlay = document.createElement('div'); modalOverlay.id = 'consultationModal'; modalOverlay.className = 'modal-overlay';

modalOverlay.innerHTML = `

`;

document.body.appendChild(modalOverlay); setTimeout(() => modalOverlay.classList.add('show'), 10);

const consultationForm = document.getElementById('consultationForm'); const submitBtn = document.getElementById('submitConsultationBtn'); const closeModalBtn = document.getElementById('closeModalBtn');

const hideAndRemoveModal = () => { modalOverlay.classList.remove('show'); setTimeout(() => { modalOverlay.remove(); }, 300); };

closeModalBtn.addEventListener('click', hideAndRemoveModal); modalOverlay.addEventListener('click', (e) => { if (e.target === modalOverlay) { hideAndRemoveModal(); } });

consultationForm.addEventListener('submit', async (e) => { e.preventDefault(); const user = auth.currentUser; if (!user) { alert("انتهت صلاحية جلسة تسجيل الدخول. يرجى تسجيل الدخول مرة أخرى."); return; }

submitBtn.disabled = true; submitBtn.textContent = 'جاري الإرسال...'; try { const consultationData = { subject: document.getElementById('consultSubject').value, details: document.getElementById('consultDetails').value, caseNumber: document.getElementById('consultCaseNumber').value || '', phone: document.getElementById('consultPhone').value, status: 'pending', createdAt: new Date(), senderUid: user.uid, senderName: user.displayName || 'مستخدم غير معروف', senderPhoto: user.photoURL || '', lawyerUid: targetLawyerUid, lawyerName: targetLawyerName, participants: [user.uid, targetLawyerUid] }; await addDoc(collection(db, "requestToLawyers"), consultationData); alert('تم إرسال استشارتك بنجاح!'); hideAndRemoveModal(); } catch (error) { console.error("Error sending consultation:", error); alert('حدث خطأ. يرجى المحاولة مرة أخرى.'); } finally { submitBtn.disabled = false; submitBtn.textContent = 'إرسال الاستشارة'; } }); }

// --- مصدر بيانات لكل مجالات الخبرة المتاحة (من الكود الثاني) --- const allExpertiseOptions = [ { id: 'companies', title: 'قانون الشركات', icon: 'fas fa-landmark', description: 'تأسيس، دمج، واستحواذ. صياغة عقود الشراكة وحوكمة الشركات.' }, { id: 'litigation', title: 'التقاضي والتحكيم', icon: 'fas fa-balance-scale', description: 'تمثيل العملاء أمام جميع درجات المحاكم والهيئات القضائية والتحكيمية.' }, { id: 'commercial', title: 'العقود التجارية', icon: 'fas fa-briefcase', description: 'صياغة ومراجعة كافة أنواع العقود التجارية المحلية والدولية.' }, { id: 'criminal', title: 'القانون الجنائي', icon: 'fas fa-gavel', description: 'الدفاع في القضايا الجنائية المختلفة مع التركيز على جرائم الأموال.' }, { id: 'real_estate', title: 'العقاري والإنشاءات', icon: 'fas fa-city', description: 'تسجيل العقارات، عقود المقاولات، والنزاعات العقارية.' }, { id: 'labor', title: 'قانون العمل', icon: 'fas fa-users', description: 'عقود العمل، تسوية النزاعات العمالية، وتمثيل الشركات والموظفين.' }, { id: 'ip', title: 'الملكية الفكرية', icon: 'far fa-lightbulb', description: 'تسجيل العلامات التجارية وبراءات الاختراع وحماية حقوق المؤلف.' }, { id: 'banking', title: 'البنوك والتمويل', icon: 'fas fa-university', description: 'التمويل الإسلامي، القروض، والامتثال التنظيمي للبنوك.' } ];

// --- دالة جلب بيانات المحامي وعرضها (من الكود الثاني) --- async function fetchLawyerDetails() { const avatarImg = document.querySelector('.lawyer-card .profile-pic'); const nameEl = document.querySelector('.lawyer-card .lawyer-name'); const descriptionEl = document.getElementById('lawyer-description'); const degreeSpan = document.getElementById('degree-value'); const expertiseSpan = document.getElementById('expertise-value'); const uidElement = document.getElementById('cli-n-fix'); const aboutTextP = document.querySelector('.about-text p'); const expertiseGrid = document.querySelector('.expertise-grid');

if (!uidElement) { console.error("خطأ: لم يتم العثور على عنصر UID."); return; }

const lawyerUid = uidElement.textContent.trim(); if (!lawyerUid) return;

try { const lawyerDocRef = doc(db, "contactForm", lawyerUid); const docSnap = await getDoc(lawyerDocRef);

if (docSnap.exists()) { const lawyerData = docSnap.data();

if (avatarImg) avatarImg.src = lawyerData.photoUrlXP || 'https://placehold.co/120x120/EFEFEF/AAAAAA&text=صورة'; if (nameEl) nameEl.textContent = lawyerData.msgContent || 'اسم غير متوفر'; if (descriptionEl) descriptionEl.textContent = lawyerData.descriptionrw || 'لا يوجد وصف متاح.'; if (degreeSpan) degreeSpan.textContent = lawyerData.degree || 'غير محدد'; if (expertiseSpan) expertiseSpan.textContent = lawyerData.expertise || 'غير محدد'; if (aboutTextP) aboutTextP.textContent = lawyerData.descriptionrw || 'لا يوجد نبذة متاحة.';

const renderExpertise = (expertiseList) => { expertiseGrid.innerHTML = ''; if (expertiseList && expertiseList.length > 0) { expertiseList.forEach(item => { const card = document.createElement('div'); card.className = 'expertise-card'; card.innerHTML = `

${item.title}

${item.description}

`; expertiseGrid.appendChild(card); }); } else { expertiseGrid.innerHTML = `

لا توجد مجالات خبره محدده

`; } }; renderExpertise(lawyerData.exLawMad);

onAuthStateChanged(auth, (user) => { if (document.getElementById('edit-description-btn')) { return; }

const isOwner = user && user.uid === lawyerUid;

const container = aboutTextP.parentElement; if (container) { const editButton = document.createElement('button'); editButton.id = 'edit-description-btn'; editButton.textContent = 'تعديل الوصف'; editButton.style.fontFamily = 'zain'; editButton.style.padding = '5px 10px'; editButton.style.background = '#2c2c2c'; editButton.style.borderRadius = '81px'; editButton.style.fontSize = '15px'; editButton.style.border = '1px solid #494949';

const editContainer = document.createElement('div'); editContainer.id = 'edit-container'; editContainer.style.display = 'none'; editContainer.style.marginTop = '10px'; const descriptionTextarea = document.createElement('textarea'); descriptionTextarea.rows = 4; descriptionTextarea.style.width = '100%';

const saveButton = document.createElement('button'); saveButton.textContent = 'حفظ'; saveButton.style.fontFamily = 'zain'; saveButton.style.padding = '5px 10px'; saveButton.style.background = '#2c2c2c'; saveButton.style.borderRadius = '81px'; saveButton.style.fontSize = '15px'; saveButton.style.border = '1px solid #494949';

const cancelButton = document.createElement('button'); cancelButton.textContent = 'إلغاء'; cancelButton.style.marginRight = '5px'; cancelButton.style.fontFamily = 'zain'; cancelButton.style.padding = '5px 10px'; cancelButton.style.background = '#2c2c2c'; cancelButton.style.borderRadius = '81px'; cancelButton.style.fontSize = '15px'; cancelButton.style.border = '1px solid #494949';

editContainer.appendChild(descriptionTextarea); editContainer.appendChild(saveButton); editContainer.appendChild(cancelButton); container.appendChild(editButton); container.appendChild(editContainer);

if (user && user.uid === lawyerUid) { editButton.disabled = false; editButton.addEventListener('click', () => { aboutTextP.style.display = 'none'; editContainer.style.display = 'block'; descriptionTextarea.value = aboutTextP.textContent; editButton.style.display = 'none'; }); cancelButton.addEventListener('click', () => { aboutTextP.style.display = 'block'; editContainer.style.display = 'none'; editButton.style.display = 'block'; }); saveButton.addEventListener('click', async () => { const newDescription = descriptionTextarea.value; await updateDoc(lawyerDocRef, { descriptionrw: newDescription }); aboutTextP.textContent = newDescription; if (descriptionEl) descriptionEl.textContent = newDescription; aboutTextP.style.display = 'block'; editContainer.style.display = 'none'; editButton.style.display = 'block'; }); } else { editButton.disabled = true; editButton.title = "التعديل متاح لصاحب الحساب فقط"; } }

const expertiseContainerParent = expertiseSpan.parentElement; if (expertiseContainerParent) { const editExpertiseBtn = document.createElement('button'); editExpertiseBtn.id = 'edit-expertise-btn'; editExpertiseBtn.textContent = 'تعديل'; editExpertiseBtn.style.marginRight = '10px'; editExpertiseBtn.style.fontFamily = 'zain'; editExpertiseBtn.style.padding = '5px 10px'; editExpertiseBtn.style.background = '#2c2c2c'; editExpertiseBtn.style.borderRadius = '81px'; editExpertiseBtn.style.fontSize = '15px'; editExpertiseBtn.style.border = '1px solid #494949';

const editExpertiseContainer = document.createElement('div'); editExpertiseContainer.style.display = 'none'; const expertiseInput = document.createElement('input'); expertiseInput.type = 'text'; expertiseInput.style.color = '#fff';

const saveExpertiseBtn = document.createElement('button'); saveExpertiseBtn.textContent = 'حفظ'; saveExpertiseBtn.style.fontFamily = 'zain'; saveExpertiseBtn.style.padding = '5px 10px'; saveExpertiseBtn.style.background = '#2c2c2c'; saveExpertiseBtn.style.borderRadius = '81px'; saveExpertiseBtn.style.fontSize = '15px'; saveExpertiseBtn.style.border = '1px solid #494949';

const cancelExpertiseBtn = document.createElement('button'); cancelExpertiseBtn.textContent = 'إلغاء'; cancelExpertiseBtn.style.fontFamily = 'zain'; cancelExpertiseBtn.style.padding = '5px 10px'; cancelExpertiseBtn.style.background = '#2c2c2c'; cancelExpertiseBtn.style.borderRadius = '81px'; cancelExpertiseBtn.style.fontSize = '15px'; cancelExpertiseBtn.style.border = '1px solid #494949';

editExpertiseContainer.appendChild(expertiseInput); editExpertiseContainer.appendChild(saveExpertiseBtn); editExpertiseContainer.appendChild(cancelExpertiseBtn);

expertiseSpan.after(editExpertiseBtn, editExpertiseContainer);

if (user && user.uid === lawyerUid) { editExpertiseBtn.disabled = false; editExpertiseBtn.addEventListener('click', () => { expertiseSpan.style.display = 'none'; editExpertiseContainer.style.display = 'inline-block'; expertiseInput.value = expertiseSpan.textContent; editExpertiseBtn.style.display = 'none'; }); cancelExpertiseBtn.addEventListener('click', () => { expertiseSpan.style.display = 'inline-block'; editExpertiseContainer.style.display = 'none'; editExpertiseBtn.style.display = 'inline-block'; }); saveExpertiseBtn.addEventListener('click', async () => { const newExpertise = expertiseInput.value; await updateDoc(lawyerDocRef, { expertise: newExpertise }); expertiseSpan.textContent = newExpertise; expertiseSpan.style.display = 'inline-block'; editExpertiseContainer.style.display = 'none'; editExpertiseBtn.style.display = 'inline-block'; }); } else { editExpertiseBtn.disabled = true; } }

const sectionTitle = document.querySelector('#expertise .section-title'); if (sectionTitle && (user && user.uid === lawyerUid)) { const editExpertiseAreasBtn = document.createElement('button'); editExpertiseAreasBtn.textContent = 'تعديل مجالات الخبرة'; editExpertiseAreasBtn.style.marginRight = '20px'; editExpertiseAreasBtn.style.fontFamily = 'zain'; editExpertiseAreasBtn.style.padding = '5px 10px'; editExpertiseAreasBtn.style.background = '#2c2c2c'; editExpertiseAreasBtn.style.borderRadius = '81px'; editExpertiseAreasBtn.style.fontSize = '15px'; editExpertiseAreasBtn.style.border = '1px solid #494949';

sectionTitle.appendChild(editExpertiseAreasBtn);

editExpertiseAreasBtn.addEventListener('click', () => { openExpertiseModal(lawyerData.exLawMad || []); }); }

const openExpertiseModal = (savedExpertise) => { const modalBackdrop = document.createElement('div'); modalBackdrop.style.cssText = `position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); display: flex; justify-content: center; align-items: center; z-index: 1000;`; const modalContent = document.createElement('div'); modalContent.style.cssText = `background: #333; color: #fff; padding: 20px; border-radius: 8px; width: 80%; max-width: 600px; max-height: 80vh; overflow-y: auto;`; modalContent.innerHTML = `

اختر مجالات خبرتك


`; const form = document.createElement('form');

allExpertiseOptions.forEach(option => { const isChecked = savedExpertise.some(saved => saved.id === option.id); const itemDiv = document.createElement('div'); itemDiv.style.marginBottom = '10px'; itemDiv.innerHTML = ``; form.appendChild(itemDiv); });

modalContent.appendChild(form); const saveBtn = document.createElement('button'); saveBtn.textContent = 'حفظ'; const cancelBtn = document.createElement('button'); cancelBtn.textContent = 'إلغاء'; modalContent.append(saveBtn, cancelBtn); modalBackdrop.appendChild(modalContent); document.body.appendChild(modalBackdrop);

const closeModal = () => document.body.removeChild(modalBackdrop); cancelBtn.onclick = closeModal; modalBackdrop.onclick = (e) => { if (e.target === modalBackdrop) closeModal(); };

saveBtn.onclick = async () => { const selectedIds = Array.from(form.querySelectorAll('input:checked')).map(input => input.value); const newExpertiseList = allExpertiseOptions.filter(option => selectedIds.includes(option.id)); saveBtn.textContent = 'جارٍ الحفظ...'; saveBtn.disabled = true; await updateDoc(lawyerDocRef, { exLawMad: newExpertiseList }); renderExpertise(newExpertiseList); lawyerData.exLawMad = newExpertiseList; closeModal(); }; }; });

} else { if (nameEl) nameEl.textContent = 'المحامي غير موجود'; } } catch (error) { console.error("حدث خطأ أثناء جلب البيانات:", error); if (nameEl) nameEl.textContent = 'خطأ في التحميل'; } }

// --- دالة لإعداد زر "طلب استشارة" --- function setupConsultationButton() { const mainConsultButton = document.querySelector('.contact-button'); const lawyerUidElement = document.getElementById('cli-n-fix');

if (mainConsultButton && lawyerUidElement) { mainConsultButton.addEventListener('click', (event) => { event.preventDefault(); const user = auth.currentUser; if (!user) { alert("يرجى تسجيل الدخول أولاً لطلب استشارة."); return; } const targetLawyerUid = lawyerUidElement.textContent.trim(); const lawyerNameElement = document.querySelector('h1'); const targetLawyerName = lawyerNameElement ? lawyerNameElement.textContent.trim() : 'محامي'; createAndShowModal(targetLawyerUid, targetLawyerName); }); } }

// ================================================================= // القسم الثالث: تشغيل الكود بعد تحميل الصفحة // ================================================================= document.addEventListener('DOMContentLoaded', () => { fetchLawyerDetails(); setupConsultationButton(); });


تابع جديد الوظائف
Scroll to Top