'', 'productcode' => '', 'productname' => '', 'productdescription' => '', 'softwareversion' => 'v1.0', 'product_media' =>'', 'url_slug' => '', 'full_path' =>'', 'created' => '', 'createdby' => $_SESSION['authorization']['clientID'], 'parttype' => 1, 'price' => '0', 'salesflag' => 0, 'quantity' => 1, 'updated' => '', 'updatedby' => $_SESSION['authorization']['clientID'], 'product_category' => '', 'status' => 1, 'build' => 1, 'partnerhierarchy' => '', 'sn' =>'', 'healthindex' =>'', '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 $api_url = '/v2/products/rowID='.$_GET['id']; $responses = ioServer($api_url,''); //Decode Payload if (!empty($responses)){$responses = json_decode($responses);}else{$responses = null;} $product = json_decode(json_encode($responses[0]), true); //CALL TO API $api_url = '/v2/media/list=product_image'; $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']; } } //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']); } if (isset($_POST['submit'])) { //GET ALL POST DATA $payload = json_encode($_POST, JSON_UNESCAPED_UNICODE); //API call $responses = ioServer('/v2/products', $payload); if ($responses === 'NOK'){ } else { header('Location: index.php?page=product&rowID='.$_GET['id'].'&success_msg=2'); exit; } } } if ($delete_allowed === 1){ if (isset($_POST['delete'])) { //GET ALL POST DATA $payload = json_encode($_POST, JSON_UNESCAPED_UNICODE); //API call $responses = ioServer('/v2/products', $payload); if ($responses === 'NOK'){ } else { // Redirect and delete product header('Location: index.php?page=products&success_msg=3'); exit; } } } } else { // Create a new product if (isset($_POST['submit']) && $create_allowed === 1) { //GET ALL POST DATA $payload = json_encode($_POST , JSON_UNESCAPED_UNICODE); //API call $responses = ioServer('/v2/products', $payload); if ($responses === 'NOK'){ } else { header('Location: index.php?page=products&success_msg=1'); exit; } } } template_header('Product', 'product', 'manage'); $view ='

'.$product_h2.'

'; if ($delete_allowed === 1){ $view .= ''; } if ($update_allowed === 1){ $view .= ''; } $view .= '
'; $view .= '
'.$tab1.'
'; $view .= '
'; foreach ($product['categories'] as $cat){ $view .= ' ×'.$cat['name'].' '; } $view .= '
'; foreach ($categories as $cat) { $view .= ' '.$cat['name'].''; } $view .= '
'; $view .= '
'.$tab4.'
'; $view .= '
'.$tab3.'
'; $view .= '
'; $view .= '

Select an Image

'; if ($media_responses && is_array($media_responses)){ foreach ($media_responses as $media_response){ $view .= ' '.$media_response['title'].' '; } } $view .= '
'; $view .= ''; //Output echo $view; template_footer()?>