:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/crm/quatation/**
:: Editing File: portfolio_share_user_mobile.php
<?php ob_start(); include 'header.php'; // ✅ Page setup $page_parent = "Portfolio CRM"; $page_parent_link = "portfolio.php"; $page_title = "Share Portfolio"; include 'breadcrumb.php'; include 'menu.php'; // -------------------------- // Helper: get YouTube ID // Accepts iframe HTML or watch URL or youtu.be // Returns video ID string or false function getYouTubeId($input) { if (empty($input)) return false; // If input contains iframe, extract src if (preg_match('/<iframe[^>]+src=["\']([^"\']+)["\']/', $input, $m)) { $input = $m[1]; } // parse URL $parts = parse_url(trim($input)); if (!$parts) return false; // youtu.be short link: path contains the id if (isset($parts['host']) && (strpos($parts['host'], 'youtu.be') !== false)) { $id = ltrim($parts['path'], '/'); return $id ?: false; } // youtube watch or embed if (isset($parts['host']) && (strpos($parts['host'], 'youtube.com') !== false)) { // watch?v=ID if (!empty($parts['query'])) { parse_str($parts['query'], $q); if (!empty($q['v'])) return $q['v']; } // embed/ID or /v/ID if (!empty($parts['path'])) { $segments = explode('/', trim($parts['path'], '/')); // find last non-empty segment $id = end($segments); return $id ?: false; } } // If input is just an ID (rare) if (preg_match('/^[A-Za-z0-9_-]{6,}$/', trim($input))) { return trim($input); } return false; } // -------------------------- // Get portfolio record /* if (!isset($_GET['id']) || empty($_GET['id'])) { header("Location: portfolio.php?msg=Invalid Request"); exit; } $id = intval($_GET['id']); */ $id = '134'; // use prepared-ish query to be safe (mysqli real escape) $result = mysqli_query($conn, "SELECT * FROM portfolio_photos WHERE id='" . intval($id) . "'"); $portfolio = mysqli_fetch_assoc($result); if (!$portfolio) { header("Location: portfolio.php?msg=Portfolio not found"); exit; } // Get section name $sectionQuery = mysqli_query($conn, "SELECT section_name FROM work_sections WHERE id='" . intval($portfolio['work_section_id']) . "'"); $sectionRow = mysqli_fetch_assoc($sectionQuery); $section_name = strtolower(trim($sectionRow['section_name'] ?? '')); $folder_name = preg_replace('/[^a-z0-9]+/', '_', $section_name); // Build paths (base url) $scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http'; $base_dir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/') . '/'; $base_url = $scheme . '://' . $_SERVER['HTTP_HOST'] . $base_dir; $image_path = "uploads/portfolio/$folder_name/" . ($portfolio['img_name'] ?? ''); $full_image_fs_path = __DIR__ . '/' . $image_path; // Prepare video info $video_link_raw = $portfolio['video_link'] ?? ''; $video_id = getYouTubeId(trim($video_link_raw)); $video_share_link = $video_id ? "https://youtu.be/" . $video_id : ''; $video_embed_link = $video_id ? "https://www.youtube.com/embed/" . $video_id : ''; ?> <div class="page-body"> <div class="container-fluid"> <div class="row"> <div class="col-sm-12"> <div class="card"> <div class="card-header"> <h2>Share Portfolio</h2> </div> <div class="card-body"> <form id="shareForm" method="POST" onsubmit="return false;"> <div class="row"> <!-- Mobile Number -- <div class="col-md-12"> <label class="form-label">Mobile Number</label> <input type="text" id="mobile" name="mobile" class="form-control" placeholder="Enter WhatsApp number" value=""> </div> --> <style> .mobile-row { display: flex; gap: 8px; margin-bottom: 8px; } .mobile-input { flex: 1; /* padding: 8px;*/ } .remove-btn { background: #dc3545; color: #fff; border: none; padding: 6px 10px; cursor: pointer; border-radius: 4px; height:35px; } .add-btn { background: #0d6efd; color: #fff; border: none; padding: 8px 14px; /*margin-top: 10px;*/ cursor: pointer; border-radius: 4px; } .send-btn { background: #25d366; color: #fff; border: none; padding: 10px 18px; margin-top: 15px; cursor: pointer; border-radius: 4px; } #mobile_filed .error1 { color: red; margin-top: 8px; display: none; } #mobile_filed small { color: #666; } </style> <div class="col-md-12" id="mobile_filed"> <div class="error1" id="limitError"> Maximum 10 WhatsApp numbers allowed </div> <small>Allowed: max 10 numbers (WhatsApp safe)</small> <div class="row"> <label class="form-label">Mobile Number</label> <div class="col-sm-10"> <div id="mobileWrapper"> <div class="mobile-row "> <input type="text" class="mobile-input form-control" placeholder="Enter 10-digit mobile number" maxlength="10" class=""> </div> </div> </div> <div class="col-sm-2"> <button class="add-btn" onclick="addMobile()">+ Add Number</button> </div> </div> </div> <!-- Portfolio Media --> <div class="col-md-12 mt-3"> <label class="form-label">Portfolio Media</label> <?php if ($section_name === 'video production' && $video_id): ?> <!-- show short share link in the input, and embed preview --> <input type="text" id="media_link" class="form-control" value="<?= htmlspecialchars($video_share_link, ENT_QUOTES); ?>" readonly> <div class="mt-3"> <iframe src="<?= htmlspecialchars($video_embed_link, ENT_QUOTES); ?>" title="YouTube video player" frameborder="0" width="560" height="315" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen> </iframe> </div> <?php elseif (!empty($portfolio['img_name']) && file_exists($full_image_fs_path)): ?> <?php $full_image_url = $base_url . $image_path; ?> <input type="text" id="media_link" class="form-control" value="<?= htmlspecialchars($full_image_url, ENT_QUOTES); ?>" readonly> <?php $extension = strtolower(pathinfo($image_path, PATHINFO_EXTENSION)); ?> <?php if ($extension == 'pdf') { ?> <div class="mt-3"> <a href="<?= htmlspecialchars($full_image_url, ENT_QUOTES); ?>" target="_blank" class="btn btn-outline-primary"> <i class="fa fa-file-pdf-o"></i> View PDF </a> </div> <?php } else { ?> <div class="mt-3"> <img src="<?= htmlspecialchars($full_image_url, ENT_QUOTES); ?>" alt="Portfolio Image" width="250" class="border rounded"> </div> <?php } ?> <?php else: ?> <input type="text" id="media_link" class="form-control" value="No media available" readonly> <?php endif; ?> </div> <!-- Website Link --> <?php if (!empty($portfolio['website_link'])): ?> <div class="col-md-12 mt-4"> <label class="form-label">Website Link</label> <input type="text" id="website_link" class="form-control" value="<?= htmlspecialchars($portfolio['website_link'], ENT_QUOTES); ?>" readonly> <div class="mt-2"> <a href="<?= htmlspecialchars($portfolio['website_link'], ENT_QUOTES); ?>" target="_blank" class="btn btn-outline-info"> <i class="fa fa-globe"></i> View Website </a> </div> </div> <?php endif; ?> </div> <br><br> <div class="text-center"> <!--<button type="button" id="whatsapp-send" class="btn btn-success" style="background:#00d757;border:none;"> <i class="fa fa-whatsapp"></i> Send on WhatsApp </button>-- <button type="button" onclick="sendMultipleWhatsApp()" class="btn btn-success" style="background:#00d757;border:none;"> Send on WhatsApp </button>--> <button class="send-btn" onclick="sendWhatsApp()" class="btn btn-success" style="background:#00d757;border:none;"> Send on WhatsApp </button> <a href="portfolio.php" class="btn btn-secondary">Back</a> </div> </form> </div> </div> </div> </div> </div> </div> <script> function sendMultipleWhatsApp() { const numbers = document.getElementById("mobile_numbers").value; const message = "Hello, please check our portfolio"; const encodedMessage = encodeURIComponent(message); const mobileArray = numbers.split(","); mobileArray.forEach((mobile, index) => { mobile = mobile.trim(); if (mobile.length >= 10) { setTimeout(() => { window.open( `https://wa.me/${mobile}?text=${encodedMessage}`, "_blank" ); }, index * 800); // delay to avoid browser blocking } }); } </script> <!-- ✅ WhatsApp Send Script --> <script> document.getElementById('whatsapp-send').addEventListener('click', function () { const mobileRaw = document.getElementById('mobile').value.trim(); const mediaLinkEl = document.getElementById('media_link'); const media_link = mediaLinkEl ? mediaLinkEl.value.trim() : ''; const websiteEl = document.getElementById('website_link'); const website_link = websiteEl ? websiteEl.value.trim() : ''; if (!mobileRaw) { alert('Please enter mobile number.'); return; } // sanitize mobile number (remove spaces, +, -) let mobile = mobileRaw.replace(/[\s+-]/g, ''); // If mobile starts with 0, remove it (wa.me expects country code) // NOTE: Ideally user should input with country code (e.g., 91XXXXXXXXXX) if (mobile.startsWith('0')) { mobile = mobile.replace(/^0+/, ''); } let message = "Hello,\n\nPlease check out our latest portfolio work:\n"; if (website_link && website_link !== "") { message += "\nVisit our website: " + website_link + "\n"; } // if both website and media exist, include both if (media_link && media_link !== "No media available") { message += "\nMedia: " + media_link + "\n"; } const encodedMessage = encodeURIComponent(message); const whatsappURL = `https://wa.me/${mobile}?text=${encodedMessage}`; window.open(whatsappURL, '_blank'); }); </script> <?php include 'footer.php'; ob_end_flush(); ?> <script> let maxNumbers = 10; function addMobile() { const wrapper = document.getElementById("mobileWrapper"); const count = wrapper.querySelectorAll(".mobile-row").length; if (count >= maxNumbers) { document.getElementById("limitError").style.display = "block"; return; } document.getElementById("limitError").style.display = "none"; const div = document.createElement("div"); div.className = "mobile-row"; div.innerHTML = ` <input type="text" class="mobile-input form-control" placeholder="Enter 10-digit mobile number" maxlength="10"> <button class="remove-btn" onclick="this.parentElement.remove()"> ✖ </button> `; wrapper.appendChild(div); } function sendWhatsApp() { /*const inputs = document.querySelectorAll(".mobile-input"); const message = "Hello, please check our portfolio"; const encodedMessage = encodeURIComponent(message); let index = 0; inputs.forEach(input => { let mobile = input.value.trim(); if (mobile.length >= 10) { setTimeout(() => { window.open( `https://wa.me/${mobile}?text=${encodedMessage}`, "_blank" ); }, index * 1500); index++; } });*/ const inputs = document.querySelectorAll(".mobile-input"); /*const message = "Hello, please check our portfolio";*/ /*const encodedMessage = encodeURIComponent(message);*/ const mediaLinkEl = document.getElementById('media_link'); const media_link = mediaLinkEl ? mediaLinkEl.value.trim() : ''; const websiteEl = document.getElementById('website_link'); const website_link = websiteEl ? websiteEl.value.trim() : ''; /*if (!mobileRaw) { alert('Please enter mobile number.'); return; }*/ // sanitize mobile number (remove spaces, +, -) // let mobile = mobileRaw.replace(/[\s+-]/g, ''); // If mobile starts with 0, remove it (wa.me expects country code) // NOTE: Ideally user should input with country code (e.g., 91XXXXXXXXXX) /*if (mobile.startsWith('0')) { mobile = mobile.replace(/^0+/, ''); } */ let message = "Hello,\n\nPlease check out our latest portfolio work:\n"; if (website_link && website_link !== "") { message += "\nVisit our website: " + website_link + "\n"; } // if both website and media exist, include both if (media_link && media_link !== "No media available") { message += "\nMedia: " + media_link + "\n"; } const encodedMessage = encodeURIComponent(message); let index = 0; inputs.forEach(input => { let mobile = input.value.trim(); // Validate 10-digit number if (!/^[6-9]\d{9}$/.test(mobile)) { input.style.border = "2px solid red"; return; } else { input.style.border = ""; } // Auto add country code let fullNumber = "91" + mobile; setTimeout(() => { window.open( `https://wa.me/${fullNumber}?text=${encodedMessage}`, "_blank" ); }, index * 1500); index++; }); } </script>