From e139b91c3050691dd09272960ab3ff5d67f34dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Wed, 18 Sep 2024 12:07:03 +0200 Subject: [PATCH] Manage Products - Initial --- api/v1/get/products_versions.php | 140 +++++ api/v1/post/equipments.php | 31 +- api/v1/post/products_versions.php | 105 ++++ api/v1/post/users.php | 31 +- api/v2/get/products_versions.php | 142 ++++++ api/v2/post/products_versions.php | 105 ++++ assets/functions.php | 104 +++- dev.php | 88 +++- equipments.php | 3 +- product.php | 398 ++++++++------- product_manage.php | 214 ++++++++ products.php | 10 +- products_versions.php | 160 ++++++ report_build.php | 12 +- settings.php | 6 + settings/translations/translations_DE.php | 595 ++++++++++------------ settings/translations/translations_NL.php | 8 + settings/translations/translations_US.php | 8 + style/admin.css | 19 + 19 files changed, 1625 insertions(+), 554 deletions(-) create mode 100644 api/v1/get/products_versions.php create mode 100644 api/v1/post/products_versions.php create mode 100644 api/v2/get/products_versions.php create mode 100644 api/v2/post/products_versions.php create mode 100644 product_manage.php create mode 100644 products_versions.php diff --git a/api/v1/get/products_versions.php b/api/v1/get/products_versions.php new file mode 100644 index 0000000..e5b0fd0 --- /dev/null +++ b/api/v1/get/products_versions.php @@ -0,0 +1,140 @@ +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 productcode like :'.$v[0]; + } + else {//create clause + $clause .= ' AND '.$v[0].' = :'.$v[0]; + } + } + if ($whereclause == '' && $clause !=''){ + $whereclause = 'WHERE '.substr($clause, 4); + } else { + $whereclause .= $clause; + } +} + +//ENSURE PRODUCTROWID IS SEND +if (isset($criterias['productrowid']) && $criterias['productrowid'] != ''){ + + //CHECK IF ALLOWED TO CRUD VERSIONS + $sql = "SELECT * FROM products WHERE rowID = ? '.$whereclause.'"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$criterias['productrowid']]); + $product_data = $stmt->fetch(); + $product_owner = ($product_data['rowID'])? 1 : 0; + + //IF PRODUCT IS OWNED THEN CRUD is ALLOWED + if ($product_owner === 1 ){ + + //Define Query + if(isset($criterias['totals']) && $criterias['totals'] ==''){ + //Request for total rows + $sql = 'SELECT count(*) as count FROM products_versions '.$whereclause.''; + } + elseif (isset($criterias['list']) && $criterias['list'] =='') { + //SQL for Paging + $sql = 'SELECT * FROM products_versions '.$whereclause.''; + } + else { + //SQL for Paging + $sql = 'SELECT * FROM products_versions '.$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); + } + //Encrypt results + $messages = generate_payload($messages); + + //Send results + echo $messages; + } +} +?> \ No newline at end of file diff --git a/api/v1/post/equipments.php b/api/v1/post/equipments.php index 42a231e..b985e06 100644 --- a/api/v1/post/equipments.php +++ b/api/v1/post/equipments.php @@ -62,8 +62,8 @@ if ($id != ''){ $owner_equipment = (($equipment_data['createdby'] == $username)? 1 : 0); - if ($permission == 3 || $permission == 4){ - //ADMIN ONLY ARE ALLOWED TO CHANGE SALES AND SOLD + if ($permission == 4){ + //ADMIN+ ONLY ARE ALLOWED TO CHANGE SALES AND SOLD $account = array( "salesid"=>$salesid_new, "soldto"=>$soldto_new, @@ -71,7 +71,18 @@ if ($id != ''){ "location"=>$location_new, "section"=>$section_new ); - } else { + } + elseif ($permission == 3) { + //ADMIN ONLY ARE ALLOWED TO CHANGE SOLD + $account = array( + "salesid"=>$equipment_old->salesid, + "soldto"=>$soldto_new, + "shipto"=>$shipto_new, + "location"=>$location_new, + "section"=>$section_new + ); + } + else { $account = array( "salesid"=>$equipment_old->salesid, "soldto"=>$equipment_old->soldto, @@ -83,7 +94,7 @@ if ($id != ''){ } else { //ID is empty => INSERT / NEW RECORD - if ($permission == 3 || $permission == 4){ + if ($permission == 4){ $account = array( "salesid"=>$post_content['salesid'], "soldto"=>$post_content['soldto'], @@ -92,7 +103,17 @@ else { "section"=>$post_content['section'] ); - } else { + } + elseif ($permission == 3){ + $account = array( + "salesid"=>$partner->salesid, + "soldto"=>$post_content['soldto'], + "shipto"=>$post_content['shipto'], + "location"=>$post_content['location'], + "section"=>$post_content['section'] + + ); + }else { $account = array( "salesid"=>$partner->salesid, "soldto"=>$partner->soldto, diff --git a/api/v1/post/products_versions.php b/api/v1/post/products_versions.php new file mode 100644 index 0000000..beda5a3 --- /dev/null +++ b/api/v1/post/products_versions.php @@ -0,0 +1,105 @@ +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; +} + +//ENSURE PRODUCTROWID IS SEND +if (isset($post_content['productrowid']) && $post_content['productrowid'] != ''){ + + //CHECK IF ALLOWED TO CRUD VERSIONS + $sql = 'SELECT * FROM products WHERE rowID = ? '.$whereclause.''; + $stmt = $pdo->prepare($sql); + $stmt->execute([$post_content['productrowid']]); + $product_data = $stmt->fetch(); + $product_owner = ($product_data['rowID'])? 1 : 0; + + //IF PRODUCT IS OWNED THEN CRUD is ALLOWED + if ($product_owner === 1 ){ + //SET PARAMETERS FOR QUERY + $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 == 'insert'){ + $post_content['created'] = $date; + $post_content['createdby'] = $username; + } + + //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('products_versions',$profile,$permission,'U') === 1){ + $sql = 'UPDATE products_versions SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); + } + elseif ($command == 'insert' && isAllowed('products_versions',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO products_versions ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); + } + elseif ($command == 'delete' && isAllowed('products_versions',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM products_versions WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'products_versions',$id,'Delete','Delete',$username); + } else + { + //do nothing + } + } +} +?> \ No newline at end of file diff --git a/api/v1/post/users.php b/api/v1/post/users.php index 2c898fd..993256d 100644 --- a/api/v1/post/users.php +++ b/api/v1/post/users.php @@ -64,15 +64,24 @@ $soldto_new = ((isset($post_content['soldto']) && $post_content['soldto'] != '' $shipto_new = (($post_content['shipto'] != '' && $post_content['shipto'] != $partnerhierarchy_old->shipto)? $post_content['shipto'] : $partnerhierarchy_old->shipto); $location_new = (($post_content['location'] != '' && $post_content['location'] != $partnerhierarchy_old->location)? $post_content['location'] : $partnerhierarchy_old->location); -if ($permission == 3 || $permission == 4){ - //ADMIN ONLY ARE ALLOWED TO CHANGE SALES AND SOLD + if ($permission == 4){ + //ADMIN+ ONLY ARE ALLOWED TO CHANGE SALES AND SOLD $account = array( "salesid"=>$salesid_new, "soldto"=>$soldto_new, "shipto"=>$shipto_new, "location"=>$location_new ); - } else { + }elseif ($permission == 3) { + //ADMIN ONLY ARE ALLOWED TO CHANGE SOLD + $account = array( + "salesid"=>$partner->salesid, + "soldto"=>$soldto_new, + "shipto"=>$shipto_new, + "location"=>$location_new + ); + } + else { $account = array( "salesid"=>$partner->salesid, "soldto"=>$partner->soldto, @@ -82,15 +91,25 @@ if ($permission == 3 || $permission == 4){ } } elseif ($command == 'insert') { //ID is empty => INSERT / NEW RECORD - if ($permission == 3 || $permission == 4){ - //ADMIN ONLY ARE ALLOWED TO CHANGE SALES AND SOLD + if ($permission == 4){ + //ADMIN+ ONLY ARE ALLOWED TO CHANGE SALES AND SOLD $account = array( "salesid"=>$post_content['salesid'], "soldto"=>$post_content['soldto'], "shipto"=>$post_content['shipto'], "location"=>$post_content['location'] ); - } else { + } + elseif ($permission == 3){ + //ADMIN ONLY ARE ALLOWED TO CHANGE SOLD + $account = array( + "salesid"=>$partner->salesid, + "soldto"=>$post_content['soldto'], + "shipto"=>$post_content['shipto'], + "location"=>$post_content['location'] + ); + } + else { $account = array( "salesid"=>$partner->salesid, "soldto"=>$partner->soldto, diff --git a/api/v2/get/products_versions.php b/api/v2/get/products_versions.php new file mode 100644 index 0000000..e7702fa --- /dev/null +++ b/api/v2/get/products_versions.php @@ -0,0 +1,142 @@ +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 productcode like :'.$v[0]; + } + else {//create clause + $clause .= ' AND '.$v[0].' = :'.$v[0]; + } + } + if ($whereclause == '' && $clause !=''){ + $whereclause = 'WHERE '.substr($clause, 4); + } else { + $whereclause .= $clause; + } +} + +//ENSURE PRODUCTROWID IS SEND +if (isset($criterias['productrowid']) && $criterias['productrowid'] != ''){ + + //CHECK IF ALLOWED TO CRUD VERSIONS + $sql = "SELECT * FROM products WHERE rowID = ? '.$whereclause.'"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$criterias['productrowid']]); + $product_data = $stmt->fetch(); + $product_owner = ($product_data['rowID'])? 1 : 0; + + //IF PRODUCT IS OWNED THEN CRUD is ALLOWED + if ($product_owner === 1 ){ + + //Define Query + if(isset($criterias['totals']) && $criterias['totals'] ==''){ + //Request for total rows + $sql = 'SELECT count(*) as count FROM products_versions '.$whereclause.''; + } + elseif (isset($criterias['list']) && $criterias['list'] =='') { + //SQL for Paging + $sql = 'SELECT * FROM products_versions '.$whereclause.''; + } + else { + //SQL for Paging + $sql = 'SELECT * FROM products_versions '.$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_DECODE + //------------------------------------------ + $messages = json_encode($messages, JSON_UNESCAPED_UNICODE); + + //Send results + echo $messages; + } +} +?> \ No newline at end of file diff --git a/api/v2/post/products_versions.php b/api/v2/post/products_versions.php new file mode 100644 index 0000000..2355dd3 --- /dev/null +++ b/api/v2/post/products_versions.php @@ -0,0 +1,105 @@ +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; +} + +//ENSURE PRODUCTROWID IS SEND +if (isset($post_content['productrowid']) && $post_content['productrowid'] != ''){ + + //CHECK IF ALLOWED TO CRUD VERSIONS + $sql = "SELECT * FROM products WHERE rowID = ? '.$whereclause.'"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$post_content['productrowid']]); + $product_data = $stmt->fetch(); + $product_owner = ($product_data['rowID'])? 1 : 0; + + //IF PRODUCT IS OWNED THEN CRUD is ALLOWED + if ($product_owner === 1 ){ + //SET PARAMETERS FOR QUERY + $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 == 'insert'){ + $post_content['created'] = $date; + $post_content['createdby'] = $username; + } + + //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('products_versions',$profile,$permission,'U') === 1){ + $sql = 'UPDATE products_versions SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); + } + elseif ($command == 'insert' && isAllowed('products_versions',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO products_versions ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); + } + elseif ($command == 'delete' && isAllowed('products_versions',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM products_versions WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'products_versions',$id,'Delete','Delete',$username); + } else + { + //do nothing + } + } +} +?> \ No newline at end of file diff --git a/assets/functions.php b/assets/functions.php index 2e9f181..c8565af 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -1968,20 +1968,20 @@ function changeLogVisual($totals,$details){ $totalcount += $total['total']; } - //GET SERIALNUMBERS - $url_input = ''; //used to collect serialnumber for onclick event - foreach ($details as $detail){ - $url_input .= $detail['serialnumber'].','; - } - - $view = '
"; -//print_r($total_measurement); -//print ""; - -foreach ($total_measurement as $key => $value){ - $total_results[$key]['average'] = average($value); - $total_results[$key]['median'] = calculateMedian($value); - $total_results[$key]['stdev'] = standDeviation($value); +//GET WATCHLIST SUMMARY +foreach ($watchlist_bytest as $test => $value){ + $watchlist_totals[$test]['n_deviation'] = count($value); + //calculate percentage + //$watchlist_totals[$test]['percentage'] = ($watchlist_totals[$test]['n_deviation'] / $watchlist_totals[$test]['n_total'])*100; } + print "
"; print_r($total_results); print ""; + +/*MAIN STATISCAL FUNCTION function standDeviation($arr) { $num_of_elements = count($arr); @@ -72,6 +116,6 @@ function calculateMedian($array) { return ($lowMiddle + $highMiddle) / 2; } } - +*/ ?> \ No newline at end of file diff --git a/equipments.php b/equipments.php index 67ce204..e4ae432 100644 --- a/equipments.php +++ b/equipments.php @@ -37,12 +37,13 @@ $servicedate = $_SESSION['servicedate'] = isset($_GET['servicedate']) ? '&servic $warrantydate = $_SESSION['warrantydate'] = isset($_GET['warrantydate']) ? '&warrantydate='.$_GET['warrantydate'] : ''; $partnerid = $_SESSION['partnerid'] = isset($_GET['partnerid']) ? '&partnerid='.$_GET['partnerid'] : ''; $productselected = $_SESSION['productcode'] = isset($_GET['productcode']) ? '&productcode='.$_GET['productcode'] : ''; +$serialnumber_input = $_SESSION['serialnumber'] = isset($_GET['serialnumber']) ? '&serialnumber='.$_GET['serialnumber'] : ''; //GET PARAMETERS FOR FILTERS $filter = urlGETdetailsFilter($_GET) ?? ''; // Determine the URL -$url = 'index.php?page=equipments'.$status.$search.$software.$servicedate.$warrantydate.$partnerid.$sort.$productselected; +$url = 'index.php?page=equipments'.$status.$search.$software.$servicedate.$warrantydate.$partnerid.$sort.$productselected.$serialnumber_input; //GET Details from URL $GET_VALUES = urlGETdetails($_GET) ?? ''; //CALL TO API diff --git a/product.php b/product.php index 147ad87..e87f31b 100644 --- a/product.php +++ b/product.php @@ -1,207 +1,249 @@ '.$button_back.'':''; + //Check if allowed if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){ header('location: index.php'); exit; } + +//GET PARAMETERS && STORE in SESSION for FURTHER USE/NAVIGATION +$pagination_page = $_SESSION['p'] = isset($_GET['p']) ? $_GET['p'] : 1; + //PAGE Security +$page_manage = 'product_manage'; $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'); +$update_allowed_edit = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'U'); +$delete_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'D'); +$create_allowed = isAllowed($page_manage ,$_SESSION['profile'],$_SESSION['permission'],'C'); -// Default input product values -$product = [ - 'rowID' => '', - 'productcode' => '', - 'productname' => '', - 'productdescription' => '', - 'softwareversion' => 'v1.0', - 'created' => '', - 'createdby' => $_SESSION['username'], - 'parttype' => 1, - 'price' => '0', - 'salesflag' => 0, - 'updated' => '', - 'updatedby' => $_SESSION['username'], - 'product_category' => '', - 'status' => 1, - 'build' => 1, - 'partnerhierarchy' => '', - 'sn' =>'' -]; +//GET Details from URL +$GET_VALUES = urlGETdetails($_GET) ?? ''; -if (isset($_GET['id'])) { - // ID param exists, edit an existing product - //CALL TO API - $api_url = '/v1/products/rowID='.$_GET['id']; - $responses = ioServer($api_url,''); - //Decode Payload - if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} - - $product = json_decode(json_encode($responses[0]), true); - - if ($update_allowed === 1){ - if (isset($_POST['file_upload'])){ - uploadProduct($_POST['productcode']); - } - if (isset($_POST['submit'])) { - //GET ALL POST DATA - $data = json_encode($_POST, JSON_UNESCAPED_UNICODE); - //Secure data - $payload = generate_payload($data); - //API call - $responses = ioServer('/v1/products', $payload); - if ($responses === 'NOK'){ +//CALL TO API FOR General information +$api_url = '/v1/products/'.$GET_VALUES; +$responses = ioServer($api_url,''); +//Decode Payload +if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} +$responses = $responses[0]; - } else { - header('Location: index.php?page=products&status=1&success_msg=2'); - exit; - - } - } +//CALL TO API FOR Product_versions +$api_url = '/v1/products_versions/productrowid='.$_GET['rowID']; +$product_versions = ioServer($api_url,''); +//Decode Payload +if (!empty($product_versions)){$product_versions = decode_payload($product_versions);}else{$product_versions = null;} + +//------------------------------ +//Variables +//------------------------------ +$status_text = 'prod_status_'.$responses->status ?? ''; +$product_category_text = 'product_category'.$responses->product_category ?? ''; +$parttype_text = 'part_type'.$responses->parttype ?? ''; + +// Handle success messages +if (isset($_GET['success_msg'])) { + if ($_GET['success_msg'] == 1) { + $success_msg = $message_pr_1; } - - if ($delete_allowed === 1){ - if (isset($_POST['delete'])) { - //GET ALL POST DATA - $data = json_encode($_POST, JSON_UNESCAPED_UNICODE); - //Secure data - $payload = generate_payload($data); - //API call - $responses = ioServer('/v1/products', $payload); - if ($responses === 'NOK'){ - - } else { - // Redirect and delete product - header('Location: index.php?page=products&status=1&success_msg=3'); - exit; - } - } + if ($_GET['success_msg'] == 2) { + $success_msg = $message_pr_2; } - -} else { - // Create a new product - if (isset($_POST['submit']) && $create_allowed === 1) { - //GET ALL POST DATA - $data = json_encode($_POST , JSON_UNESCAPED_UNICODE); - //Secure data - $payload = generate_payload($data); - //API call - $responses = ioServer('/v1/products', $payload); - if ($responses === 'NOK'){ - - } - else { - header('Location: index.php?page=products&success_msg=1'); - exit; - } + if ($_GET['success_msg'] == 3) { + $success_msg = $message_pr_3; } } -template_header('Product', 'product', 'manage'); - -$view =' -
'.$query_total_sfg.'
+'.$query_total_fg.'