- Added AJAX functionality to fetch role permissions for copying. - Introduced system role management with permission checks for updates. - Implemented role deletion with confirmation modal and backend handling. - Enhanced user role assignment migration scripts to transition from legacy profiles to RBAC. - Created SQL migration scripts for user roles and permissions mapping. - Updated user interface to support new role management features including copy permissions and system role indicators.
165 lines
5.1 KiB
PHP
165 lines
5.1 KiB
PHP
<?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 = '';
|
|
|
|
//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);
|
|
|
|
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; |