CMXX - Categories and filters

This commit is contained in:
“VeLiTi”
2025-02-03 11:28:05 +01:00
parent 754359f6b6
commit 59c23bf46c
15 changed files with 688 additions and 9 deletions

View File

@@ -53,12 +53,30 @@ elseif ($command == 'insert'){
$post_content['created'] = $date;
$post_content['createdby'] = $username;
$post_content['accounthierarchy'] = $partner_product;
}
else {
//do nothing
}
//CREAT NEW ARRAY AND MAP TO CLAUSE
//CHECK IF CATEGORIES ARE SEND AND UPDATE
if (isset($post_content['categories'])){
if ($command != 'insert'){
//CHANGE OR DELETE SO PRODUCT_ID IS AVAILABLE IN CALL
$api_url = '/v2/products_categories/';
$data = json_encode(array("categories" => $post_content['categories'], "product_id" => $id), JSON_UNESCAPED_UNICODE);
$responses = ioApiv2($api_url,$data,$clientsecret);
} else {
//INSERT Product ROWID NOT AVAILABLE YET. store $post_content['categories'] in different variable.
$categories = $post_content['categories'];
}
//REMOVE CATERGORIES FROM POST_CONTENT ARRAY
unset($post_content['categories']);
}
//CREATe NEW ARRAY AND MAP TO CLAUSE
if(isset($post_content) && $post_content!=''){
foreach ($post_content as $key => $var){
if ($key == 'submit' || $key == 'rowID'){
@@ -90,6 +108,11 @@ elseif ($command == 'insert' && isAllowed('products',$profile,$permission,'C') =
$sql = 'INSERT INTO products ('.$clause_insert.') VALUES ('.$input_insert.')';
$stmt = $pdo->prepare($sql);
$stmt->execute($execute_input);
$api_url = '/v2/products_categories/';
$data = json_encode(array("categories" => $categories, "product_id" => $id), JSON_UNESCAPED_UNICODE);
$responses = ioApiv2($api_url,$data,$clientsecret);
}
elseif ($command == 'delete' && isAllowed('products',$profile,$permission,'D') === 1){
$stmt = $pdo->prepare('DELETE FROM products WHERE rowID = ? '.$whereclause.'');

View File

@@ -48,8 +48,12 @@ if(isset($get_content) && $get_content!=''){
//build up search
$clause .= ' AND name like :'.$v[0];
}
elseif ($v[0] == 'rowid_exclude') {
//build up search
$clause .= ' AND rowID != :'.$v[0];
}
else {//create clause
$clause .= ' AND '.$v[0].' = :'.$v[0];
$clause .= ' AND '.$v[0].' = :'.$v[0];
}
}
if ($whereclause == '' && $clause !=''){
@@ -66,6 +70,7 @@ if(isset($criterias['totals']) && $criterias['totals'] ==''){
else {
//SQL for Paging
$sql = 'SELECT * FROM categories '.$whereclause.' LIMIT :page,:num_products';
}
$stmt = $pdo->prepare($sql);

View File

@@ -0,0 +1,123 @@
<?php
defined($security_key) or exit;
//------------------------------------------
// Products catagories
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//SoldTo is empty
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
//default whereclause
$whereclause = '';
switch ($permission) {
case '4':
$whereclause = '';
break;
case '3':
$whereclause = '';
break;
default:
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
$whereclause = 'WHERE accounthierarchy like "'.$condition.'"';
break;
}
//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] =='history'|| $v[0] =='success_msg'){
//do nothing
}
elseif ($v[0] == 'search') {
//build up search
$clause .= ' AND c.name like :'.$v[0];
}
else {//create clause
$clause .= ' AND pc.'.$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 products_categories '.$whereclause.'';
}
else {
//SQL for Paging
$sql = 'SELECT c.name, c.rowID FROM products_categories pc JOIN categories c ON c.rowID = pc.category_id '.$whereclause.'';
}
$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);
}
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']==''){
//Excute 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_products, PDO::PARAM_INT);
//$stmt->bindValue('num_products', $page_rows_products, PDO::PARAM_INT);
//Excute Query
$stmt->execute();
//Get results
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
//------------------------------------------
//JSON_ENCODE
//------------------------------------------
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
//Send results
echo $messages;
?>

View File

@@ -0,0 +1,98 @@
<?php
defined($security_key) or exit;
//------------------------------------------
// Categories
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//CONTENT FROM API (POST)
$post_content = json_decode($input,true);
//SoldTo is empty
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
//default whereclause
$whereclause = '';
switch ($permission) {
case '4':
$whereclause = '';
break;
case '3':
$whereclause = '';
break;
default:
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
$whereclause = ' AND c.accounthierarchy like "'.$condition.'"';
break;
}
//BUILD UP PARTNERHIERARCHY FROM USER
$partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE);
$id = $post_content['rowID'] ?? ''; //check for rowID
$command = ($id == '')? 'insert' : 'update'; //IF rowID = empty then INSERT
if (isset($post_content['delete'])){$command = 'delete';} //change command to delete
$date = date('Y-m-d H:i:s');
//CREATE EMPTY STRINGS
$clause = '';
$clause_insert ='';
$input_insert = '';
if ($command == 'update'){
$post_content['updatedby'] = $username;
}
if ($command == 'insert'){
$post_content['createdby'] = $username;
$post_content['accounthierarchy'] = $partner_product;
}
//CREAT NEW ARRAY AND MAP TO CLAUSE
if(isset($post_content) && $post_content!=''){
foreach ($post_content as $key => $var){
if ($key == 'submit' || $key == 'rowID'){
//do nothing
}
else {
$criterias[$key] = $var;
$clause .= ' , '.$key.' = ?';
$clause_insert .= ' , '.$key.'';
$input_insert .= ', ?'; // ? for each insert item
$execute_input[]= $var; // Build array for input
}
}
}
//CLEAN UP INPUT
$clause = substr($clause, 2); //Clean clause - remove first comma
$clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma
$input_insert = substr($input_insert, 1); //Clean clause - remove first comma
//QUERY AND VERIFY ALLOWED
if ($command == 'update' && isAllowed('categories',$profile,$permission,'U') === 1){
$sql = 'UPDATE categories SET '.$clause.' WHERE rowID = ? '.$whereclause.'';
$execute_input[] = $id;
$stmt = $pdo->prepare($sql);
$stmt->execute($execute_input);
}
elseif ($command == 'insert' && isAllowed('categories',$profile,$permission,'C') === 1){
$sql = 'INSERT INTO categories ('.$clause_insert.') VALUES ('.$input_insert.')';
$stmt = $pdo->prepare($sql);
$stmt->execute($execute_input);
}
elseif ($command == 'delete' && isAllowed('categories',$profile,$permission,'D') === 1){
$stmt = $pdo->prepare('DELETE c, pc FROM categories c LEFT JOIN products_categories pc ON pc.category_id = c.rowID WHERE c.rowID = ? '.$whereclause.'');
$stmt->execute([ $id ]);
//Add deletion to changelog
changelog($dbname,'categories',$id,'Delete','Delete',$username);
} else
{
//do nothing
}
?>

View File

@@ -58,6 +58,23 @@ else {
//do nothing
}
//CHECK IF CATEGORIES ARE SEND AND UPDATE
if (isset($post_content['categories'])){
if ($command != 'insert'){
//CHANGE OR DELETE SO PRODUCT_ID IS AVAILABLE IN CALL
$api_url = '/v2/products_categories/';
$data = json_encode(array("categories" => $post_content['categories'], "product_id" => $id), JSON_UNESCAPED_UNICODE);
$responses = ioApiv2($api_url,$data,$clientsecret);
} else {
//INSERT Product ROWID NOT AVAILABLE YET. store $post_content['categories'] in different variable.
$categories = $post_content['categories'];
}
//REMOVE CATERGORIES FROM POST_CONTENT ARRAY
unset($post_content['categories']);
}
//CREAT NEW ARRAY AND MAP TO CLAUSE
if(isset($post_content) && $post_content!=''){
foreach ($post_content as $key => $var){
@@ -90,6 +107,10 @@ elseif ($command == 'insert' && isAllowed('products',$profile,$permission,'C') =
$sql = 'INSERT INTO products ('.$clause_insert.') VALUES ('.$input_insert.')';
$stmt = $pdo->prepare($sql);
$stmt->execute($execute_input);
$api_url = '/v2/products_categories/';
$data = json_encode(array("categories" => $categories, "product_id" => $id), JSON_UNESCAPED_UNICODE);
$responses = ioApiv2($api_url,$data,$clientsecret);
}
elseif ($command == 'delete' && isAllowed('products',$profile,$permission,'D') === 1){
$stmt = $pdo->prepare('DELETE FROM products WHERE rowID = ? '.$whereclause.'');

View File

@@ -0,0 +1,66 @@
<?php
defined($security_key) or exit;
//------------------------------------------
// Categories
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//CONTENT FROM API (POST)
$post_content = json_decode($input,true);
//SoldTo is empty
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
//default whereclause
$whereclause = '';
switch ($permission) {
case '4':
$whereclause = '';
break;
case '3':
$whereclause = '';
break;
default:
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
$whereclause = ' AND accounthierarchy like "'.$condition.'"';
break;
}
//CHECK IF PRODUCT ID IS SEND
if (isset($post_content['product_id']) && $post_content['product_id'] != ''){
//CHECK IF ALLOWED TO CRUD CATEGORIES
$sql = "SELECT * FROM products WHERE rowID = ? '.$whereclause.'";
$stmt = $pdo->prepare($sql);
$stmt->execute([isset($post_content['product_id'])]);
$product_data = $stmt->fetch();
$product_owner = ($product_data['rowID'])? 1 : 0;
//IF PRODUCT IS OWNED THEN CRUD is ALLOWED
if ($product_owner === 1 ){
if(isAllowed('products_categories',$profile,$permission,'U') === 1 || isAllowed('products_categories',$profile,$permission,'C') === 1) {
if (isset($post_content['categories']) && is_array($post_content['categories']) && count($post_content['categories']) > 0) {
$in = str_repeat('?,', count($post_content['categories']) - 1) . '?';
$stmt = $pdo->prepare('DELETE FROM products_categories WHERE product_id = ? AND category_id NOT IN (' . $in . ')');
$stmt->execute(array_merge([$post_content['product_id'] ], $post_content['categories']));
foreach ($post_content['categories'] as $cat) {
$stmt = $pdo->prepare('INSERT IGNORE INTO products_categories (product_id,category_id) VALUES (?,?)');
$stmt->execute([$post_content['product_id'], $cat ]);
}
}
} else {
if(isAllowed('products_categories',$profile,$permission,'D') === 1){
$stmt = $pdo->prepare('DELETE FROM products_categories WHERE product_id = ?');
$stmt->execute([$post_content['product_id']]);
changelog($dbname,'products_categories',$id,'Delete','Delete',$username);
}
}
}
}

View File

@@ -14,12 +14,12 @@ include_once './settings/settings.php';
$prev_page = $_SESSION['prev_origin'] ?? '';
$page = $_SESSION['origin'] = 'catalog';
/*Check if allowed
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
*/
//GET PARAMETERS
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';

142
categories.php Normal file
View File

@@ -0,0 +1,142 @@
<?php
defined(page_security_key) or exit;
if (debug && debug_id == $_SESSION['id']){
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
}
include_once './assets/functions.php';
include_once './settings/settings.php';
//SET ORIGIN FOR NAVIGATION
$prev_page = $_SESSION['prev_origin'] ?? '';
$page = $_SESSION['origin'] = 'categories';
//Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
//GET PARAMETERS
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
// Determine the URL
$url = 'index.php?page=categories'.$search;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v2/categories/'.$GET_VALUES;
$categories = ioServer($api_url,'');
//Decode Payload
if (!empty($categories)){$categories = json_decode($categories,true);}else{$categories = null;}
//Return QueryTotal from API
$api_url = '/v2/categories/totals=';
$query_total = ioServer($api_url,'');
//Decode Payload
if (!empty($query_total)){$query_total = json_decode($query_total,true);}else{$query_total = null;}
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = $message_categories_1 ?? 'Created';
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_categories_2 ?? 'Updated';
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_categories_3 ?? 'Deleted' ;
}
}
function admin_populate_categories($categories, $parent_id = 0, $n = 0) {
$html = '';
foreach ($categories as $category) {
if ($parent_id == $category['parent_id']) {
$html .= '
<tr>
<td><span style="padding-right:8px;color:#bbbec0;border-left:1px solid #bbbec0;padding-bottom:2px;">-' . str_repeat('----', $n) . '</span>' . $category['name'] . '</td>
<td><a href="index.php?page=category&rowID=' . $category['rowID'] . '" class="link1">Edit</a> (ID =' . $category['rowID'] . ') </td>
</tr>
';
$html .= admin_populate_categories($categories, $category['rowID'], $n+1);
}
}
return $html;
}
template_header('Categories', 'categories','view');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-box-open"></i>
<div class="txt">
<h2>'.($categories_h2 ?? 'Categories').' ('.$query_total.')</h2>
<p>'.($categories_p ?? '').'</p>
</div>
</div>
</div>';
if (isset($success_msg)){
$view .= ' <div class="msg success">
<i class="fas fa-check-circle"></i>
<p>'.$success_msg.'</p>
<i class="fas fa-times"></i>
</div>';
}
$view .= '
<div class="content-header responsive-flex-column pad-top-5">
<a href="index.php?page=category" class="btn">Create Category</a>
</div>
<div class="content-block">
<div class="table">
<table>
<thead>
<tr>
<td>'.($categories_name ?? 'Name').'</td>
<td>'.$general_actions.'</td>
</tr>
</thead>
<tbody>';
if (empty($categories)){
$view .= '<tr>
<td colspan="8" style="text-align:center;">'.($message_no_categories ?? 'There are no categories').'</td>
</tr>';
}
else {
$view .= admin_populate_categories($categories);
}
$view .= '
</tbody>
</table>
</div>
</div>
';
$view.='<div class="pagination">';
if ($pagination_page > 1) {
$page = $pagination_page-1;
$view .= '<a href="'.$url.'&p=1">'.$general_first.'</a>';
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_prev.'</a>';
}
$totals = ceil($query_total / $page_rows_categories) == 0 ? 1 : ceil($query_total / $page_rows_categories);
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
if ($pagination_page * $page_rows_categories < $query_total){
$page = $pagination_page+1;
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_next.'</a>';
$view .= '<a href="'.$url.'&p='.$totals.'">'.$general_last.'</a>';
}
$view .= '</div>';
//OUTPUT
echo $view;
template_footer();
?>

143
category.php Normal file
View File

@@ -0,0 +1,143 @@
<?php
defined(page_security_key) or exit;
$page = 'category';
//Check if allowed
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');
$category = [
'rowID' => '',
'name' => '',
'parent_id' => 0,
'status' => 1,
'filter' => 0,
'accounthierarchy' => ''
];
$category_exclude = (isset($_GET['rowID'])) ? 'rowID_exclude='.$_GET['rowID'] : '';
//GET ALL CATEGORIES
$api_url = '/v2/categories/'.$category_exclude;
$categories = ioServer($api_url,'');
//Decode Payload
if (!empty($categories)){$categories = json_decode($categories,true);}else{$categories = null;}
if (isset($_GET['rowID'])) {
//CALL TO API
$api_url = '/v2/categories/rowID='.$_GET['rowID'];
$category = ioServer($api_url,'');
//Decode Payload
if (!empty($category)){$category = json_decode($category,true);}else{$category = null;}
$category = $category[0];
// ID param exists, edit an existing category
$page = 'Edit';
if (isset($_POST['submit'])) {
//Update the category
//GET ALL POST DATA
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v2/categories', $payload);
if ($responses === 'NOK'){
} else {
header('Location: index.php?page=categories&success_msg=2');
exit;
}
}
if (isset($_POST['delete'])) {
//GET ALL POST DATA
$payload = json_encode($_POST, JSON_UNESCAPED_UNICODE);
var_dump($payload);
//API call
$responses = ioServer('/v2/categories', $payload);
if ($responses === 'NOK'){
} else {
//Redirect and delete product
header('Location: index.php?page=categories&success_msg=3');
exit;
}
}
} else {
// Create a new category
$page = 'Create';
if (isset($_POST['submit'])) {
//GET ALL POST DATA
$payload = json_encode($_POST , JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v2/categories', $payload);
if ($responses === 'NOK'){
// DO nothing
}
else {
header('Location: index.php?page=categories&success_msg=1');
exit;
}
}
}
template_header('Category', 'categories', 'manage');
$view ='
<form action="" method="post" enctype="multipart/form-data">
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">'.($categories_h2 ?? 'Categories').'</h2>
<a href="index.php?page=categories" class="btn alt mar-right-2">'.$button_cancel.'</a>
';
if ($delete_allowed === 1){
$view .= '<input type="submit" name="delete" value="Delete" class="btn red mar-right-2" onclick="return confirm(\'Are you sure you want to delete this category?\')">';
}
if ($update_allowed === 1){
$view .= '<input type="submit" name="submit" value="Save" class="btn">';
}
$view .= '</div>';
$view .= '<div class="content-block tab-content active">
<div class="content-block">
<div class="form responsive-width-100">
<label for="name"><i class="required">*</i>'.($categories_name ?? 'Name').'</label>
<input id="name" type="text" name="name" placeholder="Name" value="'.$category['name'].'" required>
<label for="parent_id">'.($categories_parent ?? 'Parent').'</label>
<select id="parent_id" name="parent_id">
<option value="0">(none)</option>';
foreach ($categories as $c){
$view .= '<option value="'.$c['rowID'].'" '.(($c['rowID']==$category['parent_id']) ? ' selected':'').'>'.$c['name'].'</option>';
}
$view .= ' </select>
<label for="status">'.($categories_status ?? 'Status').'</label>
<select name="status">
<option value="1" '.($category['status']==1?' selected':'').'>'.$general_status_1.'</option>
<option value="0" '.($category['status']==0?' selected':'').'>'.$general_status_0.'</option>
</select>
<label for="status">'.($categories_filter ?? 'Filter criteria').'</label>
<select name="filter">
<option value="1" '.($category['filter']==1?' selected':'').'>'.$general_yes.'</option>
<option value="0" '.($category['filter']==0?' selected':'').'>'.$general_no.'</option>
</select>
<input type="hidden" name="rowID" value="'.$category['rowID'].'">
</div>
</div>
</form>';
//Output
echo $view;
template_footer()
?>

View File

@@ -68,6 +68,12 @@ $products_configurations = ioServer($api_url,'');
//Decode Payload
if (!empty($products_configurations)){$products_configurations = json_decode($products_configurations,true);}else{$products_configurations = null;}
//GET RELATED CATEGORIES
$api_url = '/v2/products_categories/product_id='.$_GET['rowID'];
$product['categories'] = ioServer($api_url,'');
//Decode Payload
if (!empty($product['categories'] )){$product['categories'] = json_decode($product['categories'] ,true);}else{$product['categories'] = null;}
//------------------------------
// Variables
//------------------------------
@@ -146,6 +152,17 @@ $view .= ' <div class="content-block order-details">
<div class="order-detail">
<h3>'.($product_quantity ?? 'Quantity').'</h3>
<p>'.(${$responses->quantity} ?? $responses->quantity).'</p>
</div>
<div class="order-detail">
<h3>'.($product_categories_text ?? 'Categories').'</h3>
<p><div class="multiselect" data-name="categories[]">';
foreach ($product['categories'] as $cat){
$view .= ' <span class="item">
<i class="remove">&times;</i>'.$cat['name'].'
</span>';
}
$view .= ' </div>
</p>
</div>';
$view .='

View File

@@ -41,9 +41,18 @@ $product = [
'partnerhierarchy' => '',
'sn' =>'',
'healthindex' =>'',
'configurable' =>''
'configurable' =>'',
'categories' => []
];
//GET ALL CATEGORIES
$api_url = '/v2/categories/';
$categories = ioServer($api_url,'');
//Decode Payload
if (!empty($categories)){$categories = json_decode($categories,true);}else{$categories = null;}
if (isset($_GET['id'])) {
// ID param exists, edit an existing product
//CALL TO API
@@ -68,6 +77,13 @@ if (isset($_GET['id'])) {
}
}
//GET RELATED CATEGORIES
$api_url = '/v2/products_categories/product_id='.$_GET['id'];
$product['categories'] = ioServer($api_url,'');
//Decode Payload
if (!empty($product['categories'] )){$product['categories'] = json_decode($product['categories'] ,true);}else{$product['categories'] = null;}
if ($update_allowed === 1){
if (isset($_POST['file_upload'])){
uploadProduct($_POST['productcode']);
@@ -186,6 +202,21 @@ $view .= '<div class="content-block tab-content active">
<label for="price"><i class="required">*</i> '.($product_quantity ?? 'Quantity').' </label>
<input id="price" type="number" name="quantity" placeholder="'.($product_quantity ?? 'Quantity').'" min="0" step="1" value="'.$product['quantity'].'">
<input type="hidden" name="rowID" value="'.$product['rowID'].'">
<label for="category">Categories</label>
<div class="multiselect" data-name="categories[]">';
foreach ($product['categories'] as $cat){
$view .= ' <span class="item" data-value="'.$cat['rowID'].'">
<i class="remove">&times;</i>'.$cat['name'].'
<input type="hidden" name="categories[]" value="'.$cat['rowID'].'">
</span>';
}
$view .= ' <input type="text" class="search" id="category" placeholder="Categories">
<div class="list">';
foreach ($categories as $cat) {
$view .= ' <span data-value="'.$cat['rowID'].'">'.$cat['name'].'</span>';
}
$view .= ' </div>
</div>
<input id="source_'.$product['rowID'].'" type="hidden" name="product_media" value="'.$product['product_media'].'">
<img id="image_'.$product['rowID'].'" src="'.$product['full_path'].'" alt="" style="display: block; max-width: 75px;">
<button type="button" class="btn" id="openSelectorBtn" onclick="setSourceID(\''.$product['rowID'].'\'), openDialog(\'image_'.$product['rowID'].'\')">'.($button_assign_image ?? 'Assign Image').'</button>

View File

@@ -77,9 +77,7 @@ if (isset($_GET['rowID'])) {
if (isset($_POST['submit']) && $create_allowed === 1) {
//GET ALL POST DATA
$data = json_encode($_POST , JSON_UNESCAPED_UNICODE);
//Secure data
$payload = generate_payload($data);
$payload = json_encode($_POST , JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v2/products_versions', $payload);
if ($responses === 'NOK'){

View File

@@ -6,7 +6,7 @@ define('superuser_profile','dashboard,profile,assets,equipments,equipment,equipm
/*Admin*/
define('admin_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,rmas,rma,rma_manage,rma_history,rma_history_manage,buildtool,products,products_versions,products_software,product,product_manage,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_contracts_billing,report_healthindex,changelog,application');
/*AdminPlus*/
define('adminplus_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,billing,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,rmas,rma,rma_manage,rma_history,rma_history_manage,buildtool,products,products_versions,products_software,products_attributes,products_attributes_items,products_attributes_manage,products_configurations,product,product_manage,pricelists,pricelists_items,pricelists_manage,catalog,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_contracts_billing,report_healthindex,report_usage,config,settings,logfile,changelog,language,translations,translations_details,translation_manage,media,media_manage,application,maintenance,profiles,vin');
define('adminplus_profile','dashboard,profile,buildtool,sales,accounts,account,contracts,contract,contract_manage,billing,cartests,cartest,cartest_manage,assets,equipments,equipment,equipment_healthindex,equipment_data,equipment_manage,equipment_manage_edit,equipments_mass_update,histories,history,history_manage,firmwaretool,rmas,rma,rma_manage,rma_history,rma_history_manage,buildtool,products,products_versions,products_software,products_attributes,products_attributes_items,products_attributes_manage,products_configurations,product,product_manage,pricelists,pricelists_items,pricelists_manage,catalog,categories,category,servicereports,servicereport,admin,partners,partner,users,user,user_manage,communications,communication,communication_send,marketing,reporting,report_build,report_contracts_billing,report_healthindex,report_usage,config,settings,logfile,changelog,language,translations,translations_details,translation_manage,media,media_manage,application,maintenance,profiles,vin');
/*Build*/
define('build','dashboard,profile,buildtool,firmwaretool,buildtool,products_software,application');
/*Distribution*/

View File

@@ -42,6 +42,7 @@ $all_views = [
"products_attributes_items",
"products_attributes_manage",
"products_configurations",
"products_categories",
"product",
"product_manage",
"pricelists",
@@ -49,6 +50,7 @@ $all_views = [
"pricelists_manage",
"catalog",
"categories",
"category",
"servicereports",
"servicereport",
"admin",

View File

@@ -731,6 +731,16 @@ main .form .multiselect > .item {
justify-content: center;
align-items: center;
}
main .multiselect > .item {
display: inline-flex;
border: 1px solid #dedfe1;
padding: 0 10px;
height: 40px;
margin: 0 5px 5px 0;
font-size: 14px;
justify-content: center;
align-items: center;
}
main .form .multiselect > .item .remove {
font-style: normal;