From a669b2fadfa3ed8ecf2b04b7df9faa22774f8db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Thu, 30 Jan 2025 09:28:50 +0100 Subject: [PATCH] CMXX - Catalog API --- api/v1/get/equipments.php | 2 +- api/v2/get/catalog.php | 141 ++++++++++++++++++++++ api/v2/get/equipments.php | 2 +- api/v2/get/pricelists.php | 24 +++- api/v2/get/products.php | 31 ++++- api/v2/get/products_attributes_items.php | 31 +++-- api/v2/get/products_configurations.php | 28 +++-- assets/functions.php | 22 ++++ catalog.php | 89 ++++++++++++++ equipment.php | 15 ++- equipments.php | 27 +++-- product.php | 27 ++++- product_manage.php | 86 ++++++++++++-- products.php | 21 +++- products_attributes.php | 4 +- products_attributes_manage.php | 2 +- products_configurations.php | 142 ++++++++++++++--------- settings/settingsprofiles.php | 2 +- settings/settingsviews.php | 1 + 19 files changed, 579 insertions(+), 118 deletions(-) create mode 100644 api/v2/get/catalog.php create mode 100644 catalog.php diff --git a/api/v1/get/equipments.php b/api/v1/get/equipments.php index 27915d1..68d1246 100644 --- a/api/v1/get/equipments.php +++ b/api/v1/get/equipments.php @@ -272,7 +272,7 @@ else { } //SQL for Paging - $sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_products'; + $sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname, p.product_media from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_products'; } $stmt = $pdo->prepare($sql); diff --git a/api/v2/get/catalog.php b/api/v2/get/catalog.php new file mode 100644 index 0000000..98ccdc2 --- /dev/null +++ b/api/v2/get/catalog.php @@ -0,0 +1,141 @@ + $item['version'], + 'config_setting' => $item['config'], + 'configurations' => [] + ]; + } + + if ($item['type'] == 'product') { + $version_configurations[$item['version']]['configurations'][] = $item; + } + + if ($item['type'] == 'group') { + $api_url = '/v2/products_attributes_items/item_status=1&list=catalog&group_id='.$item['assignment']; + $attributes = ioApi($api_url,'',$clientsecret); + $attributes = json_decode($attributes,true); + + // Add attributes to the group item + $item['attributes'] = $attributes; + $version_configurations[$item['version']]['configurations'][] = $item; + } + } + } + + // Add all version configurations to the catalog + $catalog[$product['rowID']]['versions'] = array_values($version_configurations); + } +} + +//------------------------------------------ +// Lookup pricing (active pricelist and pricelistitems only) +//------------------------------------------ +$api_url = '/v2/pricelists/status=1&item_status=1&list=price'; +$pricelist = ioApi($api_url,'',$clientsecret); +$pricelist = json_decode($pricelist,true); + +foreach ($pricelist as $price) { + + // Add price to product level + if (isset($catalog[$price['product_id']])) { + $catalog[$price['product_id']]['price'] = $price['price']; + $catalog[$price['product_id']]['rrp'] = $price['rrp']; + $catalog[$price['product_id']]['price_modifier'] = $price['price_modifier']; + } + + //Check for configuration (can also include products as above) + foreach ($catalog as &$items) { + if (!empty($items['versions'])) { + foreach ($items['versions'] as &$version) { + foreach ($version['configurations'] as &$config) { + //UPDATE PRODUCT PRICES IN CONFIGURATION + if ($config['type'] == 'product' && $config['assignment'] == $price['product_id']) { + $config['price'] = $price['price']; + $config['rrp'] = $price['rrp']; + $config['price_modifier'] = $price['price_modifier']; + } + + //UPDATE PRICES OF ATTRIBUTES IN GROUPS + if ($config['type'] == 'group') { + //check all attributes + foreach($config['attributes'] as &$attribute) { + if ($attribute['attribute_id'] == $price['product_id']) { + $attribute['price'] = $price['price']; + $attribute['rrp'] = $price['rrp']; + $attribute['price_modifier'] = $price['price_modifier']; + } + } + } + } + } + } + } +} +//------------------------------------------ +//REMOVE KEYS FROM OUTPUT +//------------------------------------------ +$keys_to_remove = ['status','item_status','group_status','version','config','sn','build','softwareversion','healthindex','salesflag','configurable','updatedby','createdby','updated','created']; +removeKeysRecursive($catalog,$keys_to_remove); + +//------------------------------------------ +//JSON_ENCODE +//------------------------------------------ +$messages = json_encode($catalog, JSON_UNESCAPED_UNICODE); + +//------------------------------------------ +//Send results +//------------------------------------------ +echo $messages; + +?> \ No newline at end of file diff --git a/api/v2/get/equipments.php b/api/v2/get/equipments.php index a31b9de..008513c 100644 --- a/api/v2/get/equipments.php +++ b/api/v2/get/equipments.php @@ -267,7 +267,7 @@ else { } //SQL for Paging - $sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_products'; + $sql = 'SELECT e.rowID as equipmentID, e.*, p.productcode, p.productname, p.product_media from equipment e LEFT JOIN products p ON e.productrowid = p.rowID '.$whereclause.' ORDER BY '.$sort.' LIMIT :page,:num_products'; } $stmt = $pdo->prepare($sql); diff --git a/api/v2/get/pricelists.php b/api/v2/get/pricelists.php index 6379912..4ed1645 100644 --- a/api/v2/get/pricelists.php +++ b/api/v2/get/pricelists.php @@ -23,7 +23,7 @@ switch ($permission) { break; default: $condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search; - $whereclause = 'WHERE accounthierarchy like "'.$condition.'"'; + $whereclause = 'WHERE pls.accounthierarchy like "'.$condition.'"'; break; } @@ -46,10 +46,14 @@ if(isset($get_content) && $get_content!=''){ } elseif ($v[0] == 'name') { //build up search - $clause .= ' AND name like :'.$v[0]; + $clause .= ' AND pls.name like :'.$v[0]; + } + elseif ($v[0] == 'item_status') { + //build up search + $clause .= ' AND pli.status = :'.$v[0]; } else {//create clause - $clause .= ' AND '.$v[0].' = :'.$v[0]; + $clause .= ' AND pls.'.$v[0].' = :'.$v[0]; } } if ($whereclause == '' && $clause !=''){ @@ -61,11 +65,15 @@ if(isset($get_content) && $get_content!=''){ //Define Query if(isset($criterias['totals']) && $criterias['totals'] ==''){ //Request for total rows - $sql = 'SELECT count(*) as count FROM pricelists '.$whereclause.''; + $sql = 'SELECT count(*) as count FROM pricelists pls '.$whereclause.''; } +elseif (isset($criterias['list']) && $criterias['list'] =='price'){ + $sql = 'SELECT pls.*,pli.* FROM pricelists pls JOIN pricelists_items pli ON pls.rowID = pli.pricelist_ID '.$whereclause; + +} else { //SQL for Paging - $sql = 'SELECT * FROM pricelists '.$whereclause.' LIMIT :page,:num_products'; + $sql = 'SELECT * FROM pricelists pls '.$whereclause.' LIMIT :page,:num_products'; } $stmt = $pdo->prepare($sql); @@ -96,6 +104,12 @@ if(isset($criterias['totals']) && $criterias['totals']==''){ $messages = $stmt->fetch(); $messages = $messages[0]; } +elseif(isset($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_pricelists, PDO::PARAM_INT); diff --git a/api/v2/get/products.php b/api/v2/get/products.php index c195307..b66e52e 100644 --- a/api/v2/get/products.php +++ b/api/v2/get/products.php @@ -48,6 +48,11 @@ if(isset($get_content) && $get_content!=''){ //build up search $clause .= ' AND productcode like :'.$v[0]; } + elseif ($v[0] == 'list' && $v[1] == 'price') { + //Add default selection criteria for LIST + $clause .= ' AND salesflag = 1'; + $clause .= ' AND item_status = 1'; + } else {//create clause $clause .= ' AND '.$v[0].' = :'.$v[0]; } @@ -68,8 +73,32 @@ elseif (isset($criterias['list']) && $criterias['list'] =='') { $sql = 'SELECT * FROM products '.$whereclause.''; } elseif (isset($criterias['list']) && $criterias['list'] =='price'){ + + //SET SPECIFIC WHERECLAUSE + if ($whereclause == ''){ + $whereclause_1 = 'WHERE salesflag = 1'; + $whereclause_2 = 'WHERE item_status = 1'; + } else { + $whereclause_1 = $whereclause .' AND salesflag = 1 AND status = 1 '; + $whereclause_2 = $whereclause .' AND item_status = 1'; + } + //GET ALL PRODUCTS AND PRODUCT ATTRIBUTES FOR PRICING - $sql = '(SELECT rowID as product_id, productname as product_name FROM products where salesflag = 1 '.$whereclause.' ) UNION (SELECT attribute_id as product_id, item_name as product_name FROM `products_attributes_items` WHERE item_status = 1 '.$whereclause.' )'; + $sql = '(SELECT rowID as product_id, productname as product_name FROM products '.$whereclause_1.' ) UNION (SELECT attribute_id as product_id, item_name as product_name FROM `products_attributes_items` '.$whereclause_2.' )'; +} +elseif (isset($criterias['list']) && $criterias['list'] =='config'){ + + //SET SPECIFIC WHERECLAUSE + if ($whereclause == ''){ + $whereclause_1 = 'WHERE salesflag = 1 AND status = 1 AND configurable = 0 '; + $whereclause_2 = 'WHERE group_status = 1'; + } else { + $whereclause_1 = $whereclause .' AND salesflag = 1 AND status = 1 AND configurable = 0 '; + $whereclause_2 = $whereclause .' AND group_status = 1'; + } + + //GET ALL PRODUCTS AND PRODUCT ATTRIBUTES FOR PRICING + $sql = '(SELECT rowID as product_id, productname as product_name FROM products '.$whereclause_1.' ) UNION (SELECT group_id as product_id, group_name as product_name FROM `products_attributes_groups` '.$whereclause_2.' )'; } else { //SQL for Paging diff --git a/api/v2/get/products_attributes_items.php b/api/v2/get/products_attributes_items.php index 4122bdf..94ca0e4 100644 --- a/api/v2/get/products_attributes_items.php +++ b/api/v2/get/products_attributes_items.php @@ -43,15 +43,16 @@ if(isset($get_content) && $get_content!=''){ if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='media'|| $v[0] =='success_msg'){ //do nothing - } - elseif ($v[0] == 'search') { - //build up search - $clause .= ' AND translation like :'.$v[0]; } else {//create clause - $clause .= ' AND '.$v[0].' = :'.$v[0]; + $clause .= ' AND pat.'.$v[0].' = :'.$v[0]; } } + //WHEN LIST = CATALOG change select based on GROUPS instead of ITEMS + if ($criterias['list'] && $criterias['list'] == 'catalog'){ + $clause = str_replace('pat.group_id','pag.group_id',$clause); + } + //CREATE WHERE CLAUSE if ($whereclause == '' && $clause !=''){ $whereclause = 'WHERE '.substr($clause, 4); } else { @@ -60,14 +61,20 @@ if(isset($get_content) && $get_content!=''){ } //Define Query if(isset($criterias['totals']) && $criterias['totals'] ==''){ -//Request for total rows + //Request for total rows $sql = 'SELECT count(*) as count FROM products_attributes_items '.$whereclause.''; + } elseif ($criterias['media'] && $criterias['media'] =='all'){ + //GET ALL MEDIA ITEMS RELATED TO ATTRIBUTES $sql = 'SELECT pat.*, m.full_path FROM products_attributes_items pat LEFT JOIN media m ON pat.item_media = m.rowID '.$whereclause; -} -else { + +} elseif ($criterias['list'] && $criterias['list'] =='catalog'){ + //GET ALL ATTRIBUTE DATA FOR CATALOG GROUPS,ITEMS,MEDIA + $sql = 'SELECT pag.*, pat.*, m.title, m.full_path FROM products_attributes_groups pag JOIN products_attributes_items pat ON pag.rowID = pat.group_id LEFT JOIN media m ON pat.item_media = m.rowID '.$whereclause; + +} else { //SQL for Paging - $sql = 'SELECT * FROM products_attributes_items '.$whereclause.' LIMIT :page,:num_products'; + $sql = 'SELECT * FROM products_attributes_items pat '.$whereclause.' LIMIT :page,:num_products'; } $stmt = $pdo->prepare($sql); @@ -104,6 +111,12 @@ elseif($criterias['media'] && $criterias['media'] =='all'){ //Get results $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); } +elseif($criterias['list'] && $criterias['list'] =='catalog'){ + //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_attributes, PDO::PARAM_INT); diff --git a/api/v2/get/products_configurations.php b/api/v2/get/products_configurations.php index 51bf815..77aef66 100644 --- a/api/v2/get/products_configurations.php +++ b/api/v2/get/products_configurations.php @@ -23,7 +23,7 @@ switch ($permission) { break; default: $condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search; - $whereclause = 'WHERE accounthierarchy like "'.$condition.'"'; + $whereclause = 'WHERE pc.accounthierarchy like "'.$condition.'"'; break; } @@ -43,13 +43,11 @@ if(isset($get_content) && $get_content!=''){ 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 productcode like :'.$v[0]; + } elseif($v[0] == 'version_status'){ + $clause .= ' AND pv.status = :'.$v[0]; } else {//create clause - $clause .= ' AND '.$v[0].' = :'.$v[0]; + $clause .= ' AND pc.'.$v[0].' = :'.$v[0]; } } if ($whereclause == '' && $clause !=''){ @@ -75,15 +73,25 @@ if (isset($criterias['productrowid']) && $criterias['productrowid'] != ''){ //Define Query if(isset($criterias['totals']) && $criterias['totals'] ==''){ //Request for total rows - $sql = 'SELECT count(*) as count FROM products_configurations '.$whereclause.''; + $sql = 'SELECT count(*) as count FROM products_configurations pc '.$whereclause.''; } elseif (isset($criterias['list']) && $criterias['list'] =='') { //SQL for Paging - $sql = 'SELECT * FROM products_configurations '.$whereclause.''; + $sql = 'SELECT * FROM products_configurations pc '.$whereclause.''; } else { - //SQL for Paging - $sql = 'SELECT * FROM products_configurations '.$whereclause.''; + //SQL for Paging include name from different tables + $sql = 'SELECT pc.*, pv.config, + CASE WHEN p.rowID IS NOT NULL THEN p.productname + WHEN pag.group_id IS NOT NULL THEN pag.group_name + END AS assignment_name, + CASE WHEN p.rowID IS NOT NULL THEN "product" + WHEN pag.group_id IS NOT NULL THEN "group" + END AS type + FROM products_configurations pc + LEFT JOIN products p ON p.rowID = pc.assignment + LEFT JOIN products_attributes_groups pag ON pag.group_id = pc.assignment + LEFT JOIN products_versions pv ON pv.rowID = pc.version '.$whereclause.''; } $stmt = $pdo->prepare($sql); diff --git a/assets/functions.php b/assets/functions.php index 0b99d13..62ec1e8 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -2961,4 +2961,26 @@ function generateLanguageFile($language_key,$token){ } } +} +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// Removekeys from array ++++++++++++++ +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +function removeKeysRecursive(array &$array, array $keysToRemove): void { + foreach ($array as $key => &$value) { + // Remove the key if it exists in our removal list + if (in_array($key, $keysToRemove, true)) { + unset($array[$key]); + continue; + } + + // If value is an array, recursively process it + if (is_array($value)) { + removeKeysRecursive($value, $keysToRemove); + + // If array is empty after processing, remove it + if (empty($value)) { + unset($array[$key]); + } + } + } } \ No newline at end of file diff --git a/catalog.php b/catalog.php new file mode 100644 index 0000000..175b259 --- /dev/null +++ b/catalog.php @@ -0,0 +1,89 @@ + +
+ +
+

'.($catalog_h2 ?? 'Catalog').' ('.$query_total.')

+

'.($catalog_p ?? '').'

+
+
+'; + +if (isset($success_msg)){ +$view .= '
+ +

'.$success_msg.'

+ +
'; +} +$description = json_encode($catalog, JSON_PRETTY_PRINT); +$view .= ' +
+
' . $description . '
+
+'; + +$view.=''; +//OUTPUT +echo $view; + +template_footer(); +?> \ No newline at end of file diff --git a/equipment.php b/equipment.php index 8557d4b..0c27655 100644 --- a/equipment.php +++ b/equipment.php @@ -38,6 +38,14 @@ $responses = ioServer($api_url,''); if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} $responses = $responses[0]; +//CALL TO API FOR RELATED +$api_url = '/v2/media/rowID='.$responses->product_media; +$media_responses = ioServer($api_url,''); + +//Decode Payload +if (!empty($media_responses)){$media_responses = json_decode($media_responses,true);}else{$media_responses = null;} +$media_responses = $media_responses[0]; + //CALL TO API FOR History $api_url = '/v1/equipments/equipmentID='.$responses->equipmentID.'&type=ServiceReport&history=1'; $history = ioServer($api_url,''); @@ -172,15 +180,14 @@ $view .= '

'.$product_name.'

'.(($view_product == 1)? ''.(${$responses->productname} ?? $responses->productname).'':(${$responses->productname} ?? $responses->productname)).'

'; - - $picture = glob("./assets/images/products/".$responses->productcode.".{jpg,jpeg,png,gif}", GLOB_BRACE); - if (!empty($picture)){ + if (!empty($media_responses['full_path'])){ $view .='
- +
'; } + $view .=' '; diff --git a/equipments.php b/equipments.php index bb143ff..ec3335c 100644 --- a/equipments.php +++ b/equipments.php @@ -77,6 +77,14 @@ if ($query_products != null){ $product_list .= ''; } +//CALL TO API +$api_url = '/v2/media/'; +$media_responses = ioServer($api_url,''); + +//Decode Payload +if (!empty($media_responses)){$media_responses = json_decode($media_responses,true);}else{$media_responses = null;} + + // Handle success messages if (isset($_GET['success_msg'])) { if ($_GET['success_msg'] == 1) { @@ -223,7 +231,14 @@ if ($response->productcode == 0 && $response->status == 2) {$location = $product //Check for Section if (isset($partner_data->section)){$section = getPartnerName($partner_data->section) ?? $not_specified;} else {$section = $not_specified;} -$picture = glob("./assets/images/products/".$response->productcode.".{jpg,jpeg,png,gif}", GLOB_BRACE); +//GET PATH OF ASSIGNED MEDIA +$full_path = ''; + +foreach ($media_responses as $media){ + if($response->product_media == $media['rowID']){ + $full_path = $media['full_path']; + } +} $indicators = overviewIndicators($response->warranty_date,$response->service_date,$response->sw_version, $response->sw_version_latest); @@ -231,14 +246,8 @@ $view .= ' '.$indicators.' '.$response->serialnumber.' '.$$status_text.' - '.$response->productcode.'-'.(${$response->productname} ?? $response->productname).''; -$view .= ' '; - if (!empty($picture)){ - $view .=' - - '; - } -$view .= ' + '.$response->productcode.'-'.(${$response->productname} ?? $response->productname).' + '.(($full_path !='')?'' : '').' '.$location.' '.$section.' '.$general_view .' diff --git a/product.php b/product.php index b551c01..9b14e3c 100644 --- a/product.php +++ b/product.php @@ -42,6 +42,14 @@ $responses = ioServer($api_url,''); if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} $responses = $responses[0]; +//CALL TO API FOR RELATED +$api_url = '/v2/media/rowID='.$responses->product_media; +$media_responses = ioServer($api_url,''); + +//Decode Payload +if (!empty($media_responses)){$media_responses = json_decode($media_responses,true);}else{$media_responses = null;} +$media_responses = $media_responses[0]; + //CALL TO API FOR Product_versions $api_url = '/v1/products_versions/productrowid='.$_GET['rowID']; $product_versions = ioServer($api_url,''); @@ -61,7 +69,7 @@ $products_configurations = ioServer($api_url,''); if (!empty($products_configurations)){$products_configurations = json_decode($products_configurations,true);}else{$products_configurations = null;} //------------------------------ -//Variables +// Variables //------------------------------ $status_text = 'prod_status_'.$responses->status ?? ''; $product_category_text = 'product_category'.$responses->product_category ?? ''; @@ -130,6 +138,10 @@ $view .= '

'.$product_name.'

'.(${$responses->productname} ?? $responses->productname).'

+
+
+

'.($product_slug ?? 'Product_slug').'

+

'.(${$responses->url_slug} ?? $responses->url_slug).'

'; $view .=' @@ -140,11 +152,10 @@ $view .='
'; - $picture = glob("./assets/images/products/".$responses->productcode.".{jpg,jpeg,png,gif}", GLOB_BRACE); - if (!empty($picture)){ + if (!empty($media_responses['full_path'])){ $view .='
- +
'; } @@ -175,6 +186,8 @@ if ($responses->configurable == 1){ '.($product_configuration_version ?? 'Config-version').' + '.($product_configuration_assignment ?? 'Code').' + '.($product_configuration_assignment ?? 'Name').' '.$general_actions.' @@ -182,8 +195,10 @@ if ($responses->configurable == 1){ foreach ($products_configurations as $product_config){ $view .= ' - - + '.$product_config['version'].' + '.$product_config['assignment'].' + '.(${$product_config['assignment_name']} ?? $product_config['assignment_name']).' + '.$general_view.' '; } $view .= ' diff --git a/product_manage.php b/product_manage.php index 974a711..cdd6072 100644 --- a/product_manage.php +++ b/product_manage.php @@ -26,6 +26,8 @@ $product = [ 'productname' => '', 'productdescription' => '', 'softwareversion' => 'v1.0', + 'product_media' =>'', + 'full_path' =>'', 'created' => '', 'createdby' => $_SESSION['username'], 'parttype' => 1, @@ -52,6 +54,20 @@ if (isset($_GET['id'])) { $product = json_decode(json_encode($responses[0]), true); + //CALL TO API + $api_url = '/v2/media/'; + $media_responses = ioServer($api_url,''); + + //Decode Payload + if (!empty($media_responses)){$media_responses = json_decode($media_responses,true);}else{$media_responses = null;} + + //GET PATH OF ASSIGNED MEDIA + foreach ($media_responses as $media){ + if($media['rowID'] == $product['product_media']){ + $product['full_path'] = $media['full_path']; + } + } + if ($update_allowed === 1){ if (isset($_POST['file_upload'])){ uploadProduct($_POST['productcode']); @@ -161,17 +177,21 @@ $view .= '
+ + - + + + +
'; - $view .= '
@@ -216,13 +236,65 @@ $view .= '
'; $view .= ''; -$view .= '
- - - -
+$view .= ' + +

Select an Image

+
'; + + foreach ($media_responses as $media_response){ + $view .= ' + + '; + } +$view .= '
+ +
'; + +$view .= ''; + //Output echo $view; template_footer()?> \ No newline at end of file diff --git a/products.php b/products.php index 7359b37..5bc3fc3 100644 --- a/products.php +++ b/products.php @@ -41,6 +41,13 @@ $query_total = ioServer($api_url,''); //Decode Payload if (!empty($query_total)){$query_total = decode_payload($query_total);}else{$query_total = null;} +//CALL TO API +$api_url = '/v2/media/'; +$media_responses = ioServer($api_url,''); + +//Decode Payload +if (!empty($media_responses)){$media_responses = json_decode($media_responses,true);}else{$media_responses = null;} + // Handle success messages if (isset($_GET['success_msg'])) { if ($_GET['success_msg'] == 1) { @@ -125,15 +132,23 @@ $view .= ' } else { foreach ($responses as $response){ - $picture = glob('./assets/images/products/'.$response->productcode.'.{jpg,jpeg,png,gif}', GLOB_BRACE); - + + //GET PATH OF ASSIGNED MEDIA + $full_path = ''; + + foreach ($media_responses as $media){ + if($response->product_media == $media['rowID']){ + $full_path = $media['full_path']; + } + } + $view .= ' '.$response->productcode.' '.${'part_type'.$response->parttype}.' '.${'product_category'.$response->product_category}.' - '.(($picture)?'' : '').' + '.(($full_path !='')?'' : '').' '.(${$response->productname} ?? $response->productname).' '.$general_view .' diff --git a/products_attributes.php b/products_attributes.php index 1cb8530..03a825a 100644 --- a/products_attributes.php +++ b/products_attributes.php @@ -117,9 +117,9 @@ $view .= ' foreach ($responses as $response){ $view .= ' - '.$response['rowID'].' + '.$response['group_id'].' '.${'general_status_'.$response['group_status']}.' - '.$response['group_name'].' + '.(${$response['group_name']} ?? $response['group_name']).' '.${'general_form_'.$response['group_type']}.' '.getRelativeTime($response['created']).' '.$general_view .' diff --git a/products_attributes_manage.php b/products_attributes_manage.php index f4daa0d..5a0f34c 100644 --- a/products_attributes_manage.php +++ b/products_attributes_manage.php @@ -191,7 +191,7 @@ $view .='
- +
diff --git a/products_configurations.php b/products_configurations.php index 047c476..09b4b94 100644 --- a/products_configurations.php +++ b/products_configurations.php @@ -18,15 +18,30 @@ $products_configurations = [ 'productrowid' => '', 'status' => '', 'version' => '', - 'config' => '', + 'assignment' => '', 'created' => '', 'createdby' => $_SESSION['username'], - 'measurement' => '', + 'updated' => '', + 'updatedby' => '' ]; //productrowid is required by api $productrowid = $_GET['productrowid'] ?? ''; +//GET PRODUCTS AND ATTRIBUTES +$api_url = '/v2/products/list=config'; +$products = ioServer($api_url,''); +//Decode Payload +if (!empty($products)){$products = json_decode($products,true);}else{$products = null;} + +//GET RELATED PRODUCT VERSIONS +$api_url = '/v2/products_versions/productrowid='.$productrowid; +$products_versions = ioServer($api_url,''); + +//Decode Payload +if (!empty($products_versions)){$products_versions = json_decode($products_versions,true);}else{$products_versions = null;} + + if (isset($_GET['rowID'])) { // ID param exists, edit an existing product //CALL TO API @@ -38,7 +53,23 @@ if (isset($_GET['rowID'])) { $products_configurations = json_decode(json_encode($responses[0]), true); - + //------------------------------------------ + //CALL TO API FOR RELATED ATTTRIBUTES_ITEMS + //GET rowID of group from assignment + //------------------------------------------ + $api_url = '/v2/products_attributes/group_id='.$products_configurations['assignment']; + $group_id = ioServer($api_url,''); + + if (!empty($group_id) && strlen($group_id) > 3){ + $group_id = json_decode($group_id,true); + //get the related attributes + $api_url = '/v2/products_attributes_items/media=all&group_id='.$group_id[0]['rowID']; + $products_attributes_items = ioServer($api_url,''); + //Decode Payload + if (!empty($products_attributes_items)){$products_attributes_items = json_decode($products_attributes_items,true);}else{$products_attributes_items = null;} + + } + if ($update_allowed === 1){ if (isset($_POST['submit'])) { @@ -77,9 +108,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_configurations', $payload); if ($responses === 'NOK'){ @@ -97,7 +126,7 @@ template_header('Products configurations', 'products configurations', 'manage'); $view ='
-

'.$product_version_version.'

+

'.($product_configuration ?? 'Product configuration').'

'.$button_cancel.' '; @@ -123,58 +152,19 @@ $view .= '
- - - - '; - //VIEW FOR PRODUCT CONFIGURATION - if (isset($_GET['rowID']) && $_GET['rowID'] !=''){ - - $view .= ' - -
- - -
'; + + + + '; - } - - if (isset($_GET['rowID']) && $_GET['rowID'] !='' && !empty($products_configurations['measurement'])){ - $measurements = json_decode($products_configurations['measurement'],true); - - $view .= ' - -
- - - - - - - - - - - - '; - foreach ($measurements as $name => $measurement){ - $view .=' - - - - - - - - '; - } - - - $view .= ' -
TestNAverageMedianSTdev
'.$name.''.$measurement['n'].''.$measurement['average'].''.$measurement['median'].''.$measurement['stdev'].'
-
'; - - } $view .= ' @@ -191,6 +181,42 @@ $view .= '
'; $view .= ''; +if (!empty($products_attributes_items)){ + $view .= ' +
+

'.($products_attributes_group_items ?? 'Groupitems').'

+
+ + + + + + + + + + + + '; + foreach ($products_attributes_items as $item){ + $view .= ' + + + + + + + '; + } + $view .= ' + +
'.($products_attributes_item_name ?? 'name').''.($products_attributes_item_quantity ?? 'quantity').''.($products_attributes_item_media ?? 'media').''.$general_created.''.$general_actions.'
'.(${$item['item_name']} ?? $item['item_name']).''.$item['item_quantity'].' + '.getRelativeTime($item['created']).'
+
+
'; + +} + //Output echo $view; template_footer() diff --git a/settings/settingsprofiles.php b/settings/settingsprofiles.php index d1e4650..de44e6d 100644 --- a/settings/settingsprofiles.php +++ b/settings/settingsprofiles.php @@ -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,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,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*/ diff --git a/settings/settingsviews.php b/settings/settingsviews.php index 2194ce7..1ba2a6c 100644 --- a/settings/settingsviews.php +++ b/settings/settingsviews.php @@ -47,6 +47,7 @@ $all_views = [ "pricelists", "pricelists_items", "pricelists_manage", + "catalog", "servicereports", "servicereport", "admin",