'', 'productrowid' => '', 'created' => '', 'createdby' => $_SESSION['username'], 'status' => 1, 'accounthierarchy' => $_SESSION['partnerhierarchy'], 'serialnumber' => '', 'hw_version' => '', 'sw_version' => '', 'service_date' => $date, 'warranty_date' => $date, 'order_ref' => '', 'geolocation' => [], 'updated' =>'', 'updatedby' =>'' ]; $equipment_ID = $_GET['equipmentID'] ?? ''; if ($equipment_ID !=''){ $url = 'index.php?page=equipment&equipmentID='.$equipment_ID.''; } else { $url = 'index.php?page=equipments'; //ALLOW UPDATES AT CREATION $update_allowed_special = 1; } //GET PRODUCTS $api_url = '/v2/products/list='; $responses = ioServer($api_url,''); //Decode Payload if (!empty($responses)){$products = json_decode($responses);}else{$products = null;} if (isset($_GET['equipmentID'])) { // ID param exists, edit an existing product //CALL TO API $api_url = '/v2/equipments/equipmentID='.$equipment_ID; $responses = ioServer($api_url,''); //Decode Payload if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;} $equipment = $responses[0]; //GET PRODUCTS_SOFTWARE_VERSIONS $api_url = '/v2/products_software_versions/hw_version='.$equipment['hw_version'].'&status=1'; $products_software = ioServer($api_url,''); //Decode Payload if (!empty($products_software)){$products_software = json_decode($products_software);}else{$products_software = null;} //------------------------------------ //CHECK IF USER IS ALSO CREATOR OF RECORD THEN OVERRIDE UPDATE_ALLOWED //------------------------------------ $equipment_owner = (($equipment['createdby'] == $_SESSION['username'])? 1 : 0); if ($update_allowed === 1 || $equipment_owner === 1 || $update_allowed_special === 1){ if (isset($_POST['submit'])) { //GEOLOCATION ARRAY convert to JSON $_POST['geolocation'] = json_encode($_POST['geolocation'],JSON_UNESCAPED_UNICODE); //GET ALL POST DATA $data = json_encode($_POST, JSON_UNESCAPED_UNICODE); //Secure data $payload = generate_payload($data); //API call $responses = ioServer('/v1/equipments', $payload); if ($responses === 'NOK'){ } else { header('Location: index.php?page=equipment&equipmentID='.$equipment_ID.'&success_msg=2'); exit; } } } if ($delete_allowed === 1 || $equipment_owner === 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/equipments', $payload); // Redirect and delete equipment if ($responses === 'NOK'){ } else { header('Location: index.php?page=equipments&success_msg=3'); exit; } } } } else { // Create a new equipment if (isset($_POST['submit']) && $create_allowed === 1) { //GEOLOCATION ARRAY convert to JSON $_POST['geolocation'] = json_encode($_POST['geolocation'],JSON_UNESCAPED_UNICODE); //GET ALL POST DATA $data = json_encode($_POST, JSON_UNESCAPED_UNICODE); //Secure data $payload = generate_payload($data); //API call $responses = ioServer('/v1/equipments', $payload); if ($responses === 'NOK'){ } else { header('Location: index.php?page=equipments&success_msg=1'); exit; } } } template_header('Equipment', 'equipment', 'manage'); $label_h2 = (($equipment_ID !='')? $manage_asset_h2 : $button_create_asset); $view ='

'.$label_h2.'

'; if ($delete_allowed === 1 || $equipment_owner === 1){ $view .= ''; } if ($update_allowed === 1 || $equipment_owner === 1){ $view .= ''; } $view .= '
'; //create product option list $product_option_list =''; foreach ($products as $product){ $product_option_list .= ' '; } //create products_software list $product_software_list =''; if (isset($products_software) && $products_software !=''){ $product_software_list = ' '; } $view .= '
'.$tab1.'
'.$product_software_list.'
'; //GET PARTNERDATA $partner_data = json_decode($equipment['accounthierarchy']); //BUID UP DROPDOWNS $salesid_dropdown = listPartner('salesid',$_SESSION['permission'],$partner_data->salesid,''); $soldto_dropdown = listPartner('soldto',$_SESSION['permission'],$partner_data->soldto,''); $shipto_dropdown = listPartner('shipto',$_SESSION['permission'],$partner_data->shipto,''); $location_dropdown = listPartner('location',$_SESSION['permission'],$partner_data->location,''); if (isset($partner_data->section)){$section = getPartnerName($partner_data->section) ?? 'Not specified';} else {$section = 'Not specified';} //DISPLAY TAB 2 $view .= '
'.$tab2.'
'; $view .= ''; $view .= $salesid_dropdown; $view .= ''; $view .= $soldto_dropdown; $view .= ''; $view .= $shipto_dropdown; $view .= ''; $view .= $location_dropdown; $view .= ' '; $view .= '
'; $changelog = showlog('equipment',$equipment_ID)?? ''; //GEOLOCATION $geo_details = (is_string($equipment['geolocation']))? json_decode($equipment['geolocation']) : ''; if (is_array($geo_details)) { $geodetails_lat = $geo_details[0]; $geodetails_lon = $geo_details[1]; } else{ $geodetails_lat = ''; $geodetails_lon = ''; } //DISPLAY TAB 3 $view .= '
'.$tab3.'
'.($update_allowed_special==1? $changelog:'').'
'; $view .= '
'; //Output echo $view; template_footer()?>