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:
172
api/v2/get/marketing_folders.php
Normal file
172
api/v2/get/marketing_folders.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
//------------------------------------------
|
||||
// Marketing Folders
|
||||
//------------------------------------------
|
||||
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
// Function to build hierarchical tree structure
|
||||
function buildFolderTree($folders, $parentId = null) {
|
||||
$tree = [];
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
if ($folder['parent_id'] == $parentId) {
|
||||
$children = buildFolderTree($folders, $folder['id']);
|
||||
$folder['children'] = $children; // Always include children array, even if empty
|
||||
$tree[] = $folder;
|
||||
}
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
list($whereclause,$condition) = getWhereclauselvl2('',$permission,$partner,'get');
|
||||
|
||||
//NEW ARRAY
|
||||
$criterias = [];
|
||||
$clause = '';
|
||||
|
||||
//Check for $_GET variables and build up clause
|
||||
if(isset($get_content) && $get_content!=''){
|
||||
//GET VARIABLES FROM URL
|
||||
$requests = explode("&", $get_content);
|
||||
//Check for keys and values
|
||||
foreach ($requests as $y){
|
||||
$v = explode("=", $y);
|
||||
//INCLUDE VARIABLES IN ARRAY
|
||||
$criterias[$v[0]] = $v[1];
|
||||
|
||||
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='success_msg' || $v[0] == 'action' || $v[0] == 'tree'){
|
||||
//do nothing - these are not SQL parameters
|
||||
}
|
||||
elseif ($v[0] == 'parent_id') {
|
||||
if ($v[1] === 'null' || $v[1] === '') {
|
||||
$clause .= ' AND parent_id IS NULL';
|
||||
} else {
|
||||
$clause .= ' AND parent_id = :parent_id';
|
||||
}
|
||||
}
|
||||
elseif ($v[0] == 'search') {
|
||||
$clause .= ' AND (folder_name LIKE :search OR description LIKE :search)';
|
||||
}
|
||||
else {//create clause
|
||||
$clause .= ' AND '.$v[0].' = :'.$v[0];
|
||||
}
|
||||
}
|
||||
if ($whereclause == '' && $clause !=''){
|
||||
$whereclause = 'WHERE '.substr($clause, 4);
|
||||
} else {
|
||||
$whereclause .= $clause;
|
||||
}
|
||||
}
|
||||
|
||||
//Define Query
|
||||
if(isset($criterias['totals']) && $criterias['totals'] ==''){
|
||||
//Request for total rows
|
||||
$sql = 'SELECT count(*) as count FROM marketing_folders '.$whereclause.'';
|
||||
}
|
||||
elseif (isset($criterias['list']) && $criterias['list'] =='') {
|
||||
//SQL for list (no paging)
|
||||
$sql = "SELECT
|
||||
mf.*,
|
||||
(SELECT COUNT(*) FROM marketing_files WHERE folder_id = mf.id) as file_count,
|
||||
(SELECT COUNT(*) FROM marketing_folders WHERE parent_id = mf.id) as subfolder_count,
|
||||
CASE
|
||||
WHEN mf.parent_id IS NOT NULL THEN
|
||||
(SELECT folder_name FROM marketing_folders WHERE id = mf.parent_id)
|
||||
ELSE NULL
|
||||
END as parent_folder_name
|
||||
FROM marketing_folders mf
|
||||
" . $whereclause . "
|
||||
ORDER BY mf.folder_name ASC";
|
||||
}
|
||||
else {
|
||||
//SQL for paging
|
||||
$sql = "SELECT
|
||||
mf.*,
|
||||
(SELECT COUNT(*) FROM marketing_files WHERE folder_id = mf.id) as file_count,
|
||||
(SELECT COUNT(*) FROM marketing_folders WHERE parent_id = mf.id) as subfolder_count,
|
||||
CASE
|
||||
WHEN mf.parent_id IS NOT NULL THEN
|
||||
(SELECT folder_name FROM marketing_folders WHERE id = mf.parent_id)
|
||||
ELSE NULL
|
||||
END as parent_folder_name
|
||||
FROM marketing_folders mf
|
||||
" . $whereclause . "
|
||||
ORDER BY mf.folder_name ASC
|
||||
LIMIT :page,:num_folders";
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
//Bind to query
|
||||
if (str_contains($whereclause, ':condition')){
|
||||
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
if (!empty($criterias)){
|
||||
foreach ($criterias as $key => $value){
|
||||
$key_condition = ':'.$key;
|
||||
if (str_contains($whereclause, $key_condition)){
|
||||
if ($key == 'search'){
|
||||
$search_value = '%'.$value.'%';
|
||||
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
|
||||
}
|
||||
elseif ($key == 'parent_id' && ($value === 'null' || $value === '')) {
|
||||
// Skip binding for NULL parent_id
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$stmt->bindValue($key, $value, PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Add paging details
|
||||
if(isset($criterias['totals']) && $criterias['totals']==''){
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetch();
|
||||
$messages = $messages[0];
|
||||
}
|
||||
elseif(isset($criterias['list']) && $criterias['list']==''){
|
||||
//Execute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
else {
|
||||
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
|
||||
$stmt->bindValue('page', ($current_page - 1) * $page_rows_folders, PDO::PARAM_INT);
|
||||
$stmt->bindValue('num_folders', $page_rows_folders, PDO::PARAM_INT);
|
||||
|
||||
//Execute Query
|
||||
$stmt->execute();
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// Check if tree structure is requested
|
||||
if (isset($criterias['tree']) && isset($messages) && is_array($messages)) {
|
||||
// Build hierarchical tree structure
|
||||
$messages = buildFolderTree($messages);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_ENCODE
|
||||
//------------------------------------------
|
||||
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//Send results
|
||||
echo $messages;
|
||||
Reference in New Issue
Block a user