Add PayPal webhook handler and marketing styles
- Implemented PayPal webhook for handling payment notifications, including signature verification and transaction updates. - Created invoice generation and license management for software upgrades upon successful payment. - Added comprehensive logging for debugging purposes. - Introduced new CSS styles for the marketing file management system, including layout, toolbar, breadcrumb navigation, search filters, and file management UI components.
This commit is contained in:
429
marketing.php
429
marketing.php
@@ -10,107 +10,362 @@ if (debug && debug_id == $_SESSION['id']){
|
||||
include_once './assets/functions.php';
|
||||
include_once './settings/settings_redirector.php';
|
||||
|
||||
$page = 'marketing';
|
||||
//Check if allowed
|
||||
if (isAllowed('marketing',$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
||||
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
|
||||
header('location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
//PAGE Security
|
||||
$update_allowed = isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'U');
|
||||
$delete_allowed = isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'D');
|
||||
$create_allowed = isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'C');
|
||||
|
||||
//GET PARAMETERS:
|
||||
$product_group = $_GET['product_group'] ?? '';
|
||||
$product_content = $_GET['product_content'] ?? '';
|
||||
$current_folder = $_GET['folder'] ?? '';
|
||||
$view_mode = $_GET['view'] ?? 'grid';
|
||||
$search_term = $_GET['search'] ?? '';
|
||||
$tag_filter = $_GET['tag'] ?? '';
|
||||
|
||||
template_header('Marketing', 'marketing');
|
||||
echo '
|
||||
<div class="content-title">
|
||||
<div class="title">
|
||||
<i class="fa-solid fa-house"></i>
|
||||
<div class="txt">
|
||||
<h2>'.$marketing_h2.'</h2>
|
||||
<p>'.$marketing_p.'</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="products content-wrapper">
|
||||
<div style="display: flex;align-items: center;align-content: center;flex-wrap: nowrap;flex-direction: column;">
|
||||
<div class="">';
|
||||
foreach ($marketing_structure as $marketing => $folders){
|
||||
$style = '';
|
||||
if (!empty($product_group) && $product_group !== $marketing) {
|
||||
$style = ' style="opacity: 0.5; color: #999; background-color: #f5f5f5;"';
|
||||
} elseif (!empty($product_group) && $product_group === $marketing) {
|
||||
$style = ' style="background-color: #007cba; color: white;"';
|
||||
// Handle AJAX API requests
|
||||
if (isset($_GET['action'])) {
|
||||
$action = $_GET['action'];
|
||||
|
||||
// Suppress errors for API responses to avoid HTML output breaking JSON
|
||||
error_reporting(0);
|
||||
ini_set('display_errors', 0);
|
||||
|
||||
try {
|
||||
// Marketing folders
|
||||
if ($action === 'marketing_folders') {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Create folder - use standard format expected by POST API
|
||||
$payload = [
|
||||
'folder_name' => $_POST['folder_name'] ?? '',
|
||||
'parent_id' => $_POST['parent_id'] ?? '',
|
||||
'description' => $_POST['description'] ?? ''
|
||||
// rowID is empty = insert (standard pattern)
|
||||
];
|
||||
$response = ioServer('/v2/marketing_folders', json_encode($payload));
|
||||
} else {
|
||||
// Get folders
|
||||
$get_values = urlGETdetails($_GET) ?? '';
|
||||
$response = ioServer('/v2/marketing_folders/' . $get_values, '');
|
||||
}
|
||||
echo '<a href="index.php?page=marketing&product_group='.$marketing.'" class="btn"'.$style.'>'.$marketing.'</a>';
|
||||
header('Content-Type: application/json');
|
||||
echo $response;
|
||||
exit;
|
||||
}
|
||||
echo'
|
||||
</div>
|
||||
<div class="">';
|
||||
// Only show folders if a product group is selected
|
||||
if (!empty($product_group) && isset($marketing_structure[$product_group])) {
|
||||
foreach($marketing_structure[$product_group] as $folder){
|
||||
echo '<a href="index.php?page=marketing&product_group='.$product_group.'&product_content='.$folder.'" class="btn"> <img src="./assets/images/folder3.png" width="15" height="15" alt=""> '.$folder.'</a>';
|
||||
|
||||
// Marketing files
|
||||
if ($action === 'marketing_files') {
|
||||
// Filter out 'page', 'action', and cache busting timestamp from GET parameters
|
||||
$filtered_params = $_GET;
|
||||
unset($filtered_params['page']);
|
||||
unset($filtered_params['action']);
|
||||
unset($filtered_params['_t']);
|
||||
|
||||
$get_values = urlGETdetails($filtered_params) ?? '';
|
||||
// API expects path segments, not query string: /v2/marketing_files/params
|
||||
$api_url = '/v2/marketing_files/' . $get_values;
|
||||
$response = ioServer($api_url, '');
|
||||
header('Content-Type: application/json');
|
||||
echo $response;
|
||||
exit;
|
||||
}
|
||||
|
||||
// Marketing tags
|
||||
if ($action === 'marketing_tags') {
|
||||
// Filter out 'page' and 'action' from GET parameters
|
||||
$get_values = urlGETdetails($_GET) ?? '';
|
||||
$response = ioServer('/v2/marketing_tags?' . $get_values, '');
|
||||
header('Content-Type: application/json');
|
||||
echo $response;
|
||||
exit;
|
||||
}
|
||||
|
||||
// Marketing upload
|
||||
if ($action === 'marketing_upload' && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK && $_FILES['file']['size'] > 0) {
|
||||
// Use the uploaded file's temp path directly
|
||||
$temp_path = $_FILES['file']['tmp_name'];
|
||||
|
||||
// Get actual MIME type from file content (more secure than trusting browser)
|
||||
$actual_mime_type = mime_content_type($temp_path);
|
||||
|
||||
// Sanitize filename - remove path info and dangerous characters
|
||||
$safe_filename = basename($_FILES['file']['name']);
|
||||
$safe_filename = preg_replace('/[^a-zA-Z0-9._-]/', '_', $safe_filename);
|
||||
|
||||
$fileData = [
|
||||
'file' => new CURLFile($temp_path, $actual_mime_type, $safe_filename)
|
||||
];
|
||||
|
||||
$additionalData = $_POST; // Include any additional POST data
|
||||
|
||||
$token = createCommunicationToken($_SESSION['userkey']);
|
||||
|
||||
$response = ioAPIv2_FileUpload('/v2/marketing_upload/', $fileData, $additionalData, $token);
|
||||
|
||||
// No need to unlink since we didn't move the file
|
||||
} else {
|
||||
$response = json_encode(['error' => 'No file uploaded or upload error']);
|
||||
}
|
||||
header('Content-Type: application/json');
|
||||
echo $response;
|
||||
exit;
|
||||
}
|
||||
echo '
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
|
||||
if (isset($product_group) && $product_group !='' && isset($product_content) && $product_content !=''){
|
||||
|
||||
echo '
|
||||
<div class="content-block">
|
||||
<div class="products-wrapper">';
|
||||
$dir_name = $main_marketing_dir.$product_group.'/'.$product_content;
|
||||
|
||||
$files = array_diff(scandir($dir_name), array('.', '..'));
|
||||
echo'';
|
||||
|
||||
foreach ($files as $file) {
|
||||
$filetype = strtolower(pathinfo($file,PATHINFO_EXTENSION));
|
||||
|
||||
if ( $filetype != '' && $filetype != 'ds_store'){
|
||||
echo '
|
||||
<div class="product">
|
||||
<a href="'.$dir_name.'/'.$file.'" class="product">
|
||||
';
|
||||
if ( $filetype == "jpg" || $filetype == "png" || $filetype == "jpeg" || $filetype == "gif" || $filetype == "png"){
|
||||
echo'
|
||||
<img src="'.$dir_name.'/Thumb/'.$file.'" width="200" height="200" alt=""/> </a>
|
||||
';
|
||||
|
||||
// Marketing delete
|
||||
if ($action === 'marketing_delete' && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$payload = ['file_id' => $_POST['file_id'] ?? ''];
|
||||
$response = ioServer('/v2/marketing_delete', json_encode($payload));
|
||||
header('Content-Type: application/json');
|
||||
echo $response;
|
||||
exit;
|
||||
}
|
||||
if ($filetype == "doc" || $filetype == "docx" || $filetype == "xls"|| $filetype == "xlsx"){
|
||||
echo'
|
||||
<img src="./assets/images/brochure.png" width="200" height="200" alt=""> </a>
|
||||
';
|
||||
}
|
||||
if ( $filetype == "pdf"){
|
||||
echo'
|
||||
<img src="./assets/images/download-pdf.png" width="200" height="200" alt="'.ucfirst(substr($file, 0, strpos($file, "."))).'"></a>
|
||||
<span class="name">'.ucfirst(substr(substr($file, 0, strpos($file, ".")),0 ,25)).'</span>
|
||||
';
|
||||
}
|
||||
if ( $filetype == "mp4"){
|
||||
echo'
|
||||
<video width="200" height="200" controls>
|
||||
<source src="'.$dir_name.'/'.$file.'" type="video/mp4">
|
||||
Your browser does not support the video tag.
|
||||
</video> </a>
|
||||
';
|
||||
}
|
||||
|
||||
echo'
|
||||
<button class="btn"><a href="'.$dir_name.'/'.$file.'" style="text-decoration: none;color: #ffff;"download="">Download</a></button>
|
||||
</div>';
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
header('Content-Type: application/json');
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo '</div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
template_header('Marketing', 'marketing');
|
||||
?>
|
||||
|
||||
<link rel="stylesheet" href="./style/marketing.css">
|
||||
|
||||
<div class="content-title">
|
||||
<div class="title">
|
||||
<i class="fa-solid fa-rectangle-ad"></i>
|
||||
<div class="txt">
|
||||
<h2><?php echo $marketing_h2; ?></h2>
|
||||
<p><?php echo $marketing_p; ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Marketing File Management Interface -->
|
||||
<div class="marketing-container">
|
||||
|
||||
<!-- Toolbar -->
|
||||
<div class="marketing-toolbar">
|
||||
<div class="toolbar-left">
|
||||
<?php if ($create_allowed === 1): ?>
|
||||
<button id="uploadBtn" class="btn btn-primary">
|
||||
<i class="fa fa-upload"></i>
|
||||
</button>
|
||||
<button id="createFolderBtn" class="btn btn-secondary">
|
||||
<i class="fa fa-folder-plus"></i>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="toolbar-right">
|
||||
<!-- Search and Filters -->
|
||||
<div class="search-container">
|
||||
<input type="text" id="searchInput" class="search-input" placeholder="Search files..." value="<?php echo htmlspecialchars($search_term); ?>">
|
||||
<i class="fa fa-search search-icon"></i>
|
||||
</div>
|
||||
|
||||
<select id="tagFilter" class="filter-select">
|
||||
<option value="">All Tags</option>
|
||||
</select>
|
||||
|
||||
<div class="view-toggle">
|
||||
<button id="gridViewBtn" class="view-btn <?php echo $view_mode === 'grid' ? 'active' : ''; ?>">
|
||||
<i class="fa fa-th-large"></i>
|
||||
</button>
|
||||
<button id="listViewBtn" class="view-btn <?php echo $view_mode === 'list' ? 'active' : ''; ?>">
|
||||
<i class="fa fa-list"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content Area -->
|
||||
<div class="marketing-content">
|
||||
|
||||
<!-- Sidebar -->
|
||||
<div class="marketing-sidebar">
|
||||
<div class="sidebar-section">
|
||||
<h3>Folders</h3>
|
||||
<div id="folderTree" class="folder-tree">
|
||||
<!-- Folder tree will be loaded here -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-section">
|
||||
<h3>File Types</h3>
|
||||
<div class="file-type-filters">
|
||||
<div class="filter-item">
|
||||
<input type="checkbox" id="filterImages" value="jpg,jpeg,png,gif,webp">
|
||||
<label for="filterImages">
|
||||
<i class="fa fa-image"></i> Images
|
||||
</label>
|
||||
</div>
|
||||
<div class="filter-item">
|
||||
<input type="checkbox" id="filterDocuments" value="pdf,doc,docx">
|
||||
<label for="filterDocuments">
|
||||
<i class="fa fa-file-text"></i> Documents
|
||||
</label>
|
||||
</div>
|
||||
<div class="filter-item">
|
||||
<input type="checkbox" id="filterSpreadsheets" value="xls,xlsx">
|
||||
<label for="filterSpreadsheets">
|
||||
<i class="fa fa-file-excel"></i> Spreadsheets
|
||||
</label>
|
||||
</div>
|
||||
<div class="filter-item">
|
||||
<input type="checkbox" id="filterVideos" value="mp4,mov,avi">
|
||||
<label for="filterVideos">
|
||||
<i class="fa fa-file-video"></i> Videos
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="marketing-main">
|
||||
|
||||
<!-- Files Grid -->
|
||||
<div id="filesContainer" class="files-container <?php echo $view_mode; ?>-view">
|
||||
<!-- Files will be loaded here -->
|
||||
</div>
|
||||
|
||||
<!-- Loading Indicator -->
|
||||
<div id="loadingIndicator" class="loading-indicator">
|
||||
<i class="fa fa-spinner fa-spin"></i>
|
||||
<span>Loading files...</span>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<div id="emptyState" class="empty-state" style="display: none;">
|
||||
<i class="fa fa-folder-open"></i>
|
||||
<h3>No files found</h3>
|
||||
<p>Upload your first file to get started</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Upload Modal -->
|
||||
<?php if ($create_allowed === 1): ?>
|
||||
<div id="uploadModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3>Upload Files</h3>
|
||||
<button class="modal-close">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="upload-area" id="uploadArea">
|
||||
<div class="upload-icon">
|
||||
<i class="fa fa-cloud-upload"></i>
|
||||
</div>
|
||||
<h4>Drag & Drop Files Here</h4>
|
||||
<p>or <button class="browse-btn" id="browseBtn">Browse Files</button></p>
|
||||
<input type="file" id="fileInput" multiple accept="image/*,.pdf,.doc,.docx,.xls,.xlsx,.mp4,.mov,.avi">
|
||||
</div>
|
||||
|
||||
<div id="uploadQueue" class="upload-queue">
|
||||
<!-- Upload queue items will appear here -->
|
||||
</div>
|
||||
|
||||
<div class="upload-options">
|
||||
<div class="form-group">
|
||||
<label for="uploadFolder">Upload to Folder:</label>
|
||||
<select id="uploadFolder" class="form-control">
|
||||
<option value="">Root Folder</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="uploadTags">Tags (comma separated):</label>
|
||||
<input type="text" id="uploadTags" class="form-control" placeholder="marketing, brochure, product">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="startUpload" class="btn btn-primary" disabled>
|
||||
<i class="fa fa-upload"></i>
|
||||
</button>
|
||||
<button class="modal-cancel btn btn-secondary">X</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Create Folder Modal -->
|
||||
<?php if ($create_allowed === 1): ?>
|
||||
<div id="folderModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3>Create New Folder</h3>
|
||||
<button class="modal-close">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label for="folderName">Folder Name:</label>
|
||||
<input type="text" id="folderName" class="form-control" placeholder="Enter folder name">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="parentFolder">Parent Folder:</label>
|
||||
<select id="parentFolder" class="form-control">
|
||||
<option value="">Root Folder</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="folderDescription">Description:</label>
|
||||
<textarea id="folderDescription" class="form-control" rows="3" placeholder="Optional description"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="createFolder" class="btn btn-primary">
|
||||
<i class="fa fa-folder-plus"></i>
|
||||
</button>
|
||||
<button class="modal-cancel btn btn-secondary">X</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- File Preview Modal -->
|
||||
<div id="previewModal" class="modal preview-modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3 id="previewTitle">File Preview</h3>
|
||||
<button class="modal-close">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div id="previewContent" class="preview-content">
|
||||
<!-- Preview content will be loaded here -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="downloadFile" class="btn btn-primary">
|
||||
<i class="fa fa-download"></i>
|
||||
</button>
|
||||
<?php if ($delete_allowed === 1): ?>
|
||||
<button id="deleteFile" class="btn btn-danger">
|
||||
<i class="fa fa-trash"></i>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="./assets/marketing.js"></script>
|
||||
|
||||
<?php
|
||||
template_footer();
|
||||
?>
|
||||
Reference in New Issue
Block a user