Manage Products - Initial
This commit is contained in:
398
product.php
398
product.php
@@ -1,207 +1,249 @@
|
||||
<?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 = 'product';
|
||||
|
||||
//create backbutton to prev_origin
|
||||
$back_btn_orgin = ($prev_page != '')? '<a href="'.$prev_page.'" class="btn alt mar-right-2">'.$button_back.'</a>':'';
|
||||
|
||||
//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 ='
|
||||
<form action="" method="post">
|
||||
template_header('Product', 'product', 'view');
|
||||
$view = '
|
||||
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
|
||||
<h2 class="responsive-width-100">'.$product_h2.'</h2>
|
||||
<a href="index.php?page=products" class="btn alt mar-right-2">'.$button_cancel.'</a>
|
||||
<h2 class="responsive-width-100">'.$responses->productcode.' - '.$responses->productname.'</h2>
|
||||
<a href="index.php?page='.$_SESSION['origin'].'&p='.$_SESSION['p'].'" 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 product?\')">';
|
||||
|
||||
//------------------------------------
|
||||
//
|
||||
//------------------------------------
|
||||
if ($update_allowed_edit === 1){
|
||||
$view .= '<a href="index.php?page=product_manage&id='.$_GET['rowID'].'" class="btn">Edit</a>';
|
||||
}
|
||||
if ($update_allowed === 1){
|
||||
$view .= '<input type="submit" name="submit" value="Save" class="btn">';
|
||||
}
|
||||
|
||||
|
||||
$view .= '</div>';
|
||||
|
||||
$view .= '<div class="tabs">
|
||||
<a href="#" class="active">'.$tab1.'</a>
|
||||
<a href="#">'.$tab4.'</a>
|
||||
<a href="#">'.$tab3.'</a>
|
||||
</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-block tab-content active">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="status">'.$product_status.'</label>
|
||||
<select id="status" name="status">
|
||||
<option value="1" '.($product['status']==1?' selected':'').'>'.$prod_status_1 .'</option>
|
||||
<option value="0" '.($product['status']==0?' selected':'').'>'.$prod_status_0 .'</option>
|
||||
</select>
|
||||
<label for="parttype">'.$product_parttype.'</label>
|
||||
<select id="status" name="parttype">
|
||||
<option value="1" '.($product['parttype']==1?' selected':'').'>'.$part_type1.'</option>
|
||||
<option value="2" '.($product['parttype']==2?' selected':'').'>'.$part_type2.'</option>
|
||||
<option value="3" '.($product['parttype']==3?' selected':'').'>'.$part_type3.'</option>
|
||||
</select>
|
||||
<label for="parttype">'.$product_category.'</label>
|
||||
<select id="status" name="product_category">
|
||||
<option value="0" '.($product['product_category']==0?' selected':'').'>'.$product_category0.'</option>
|
||||
<option value="1" '.($product['product_category']==1?' selected':'').'>'.$product_category1.'</option>
|
||||
<option value="2" '.($product['product_category']==2?' selected':'').'>'.$product_category2.'</option>
|
||||
<option value="3" '.($product['product_category']==3?' selected':'').'>'.$product_category3.'</option>
|
||||
</select>
|
||||
<label for="productcode"><i class="required">*</i>'.$product_code.'</label>
|
||||
<input id="name" type="text" name="productcode" placeholder="'.$product_code.'" value="'.$product['productcode'].'" required>
|
||||
<label for="productname"><i class="required">*</i>'.$product_name.'</label>
|
||||
<input id="name" type="text" name="productname" placeholder="'.$product_name.'" value="'.$product['productname'].'" required>
|
||||
<label for="productdescription">'.$product_description.'</label>
|
||||
<textarea id="description" name="productdescription" placeholder="'.$product_description.'">'.$product['productdescription'].'</textarea>
|
||||
<label for="softwareversion">'.$product_software.'</label>
|
||||
<input id="name" type="text" name="softwareversion" placeholder="'.$product_software.'" value="'.$product['softwareversion'].'">
|
||||
<label for="price"><i class="required">*</i> '.$product_price.' </label>
|
||||
<input id="price" type="number" name="price" placeholder="'.$product_price.'" min="0" step=".01" value="'.$product['price'].'" required>
|
||||
<input type="hidden" name="rowID" value="'.$product['rowID'].'">
|
||||
$view .= '<div class="content-block-wrapper">';
|
||||
|
||||
$view .= ' <div class="content-block order-details">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-circle-info"></i></i>'.($product_data ?? '').'
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$product_status.'</h3>
|
||||
<p><span class="status id'.$responses->status.'">'.$$status_text.'</span></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$product_category.'</h3>
|
||||
<p><span class="status id'.$responses->product_category.'">'.$$product_category_text.'</span></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$product_parttype.'</h3>
|
||||
<p><span class="status id'.$responses->parttype.'">'.$$parttype_text.'</span></p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$product_code.'</h3>
|
||||
<p>'.$responses->productcode.'</p>
|
||||
</div>
|
||||
<div class="order-detail">
|
||||
<h3>'.$product_name.'</h3>
|
||||
<p>'.$responses->productname.'</p>
|
||||
</div>';
|
||||
|
||||
$view .='
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
|
||||
$view .= '<div class="content-block tab-content">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="serialized">'.$product_serialized.'</label>
|
||||
<select id="status" name="sn">
|
||||
<option value="1" '.($product['sn']==1?' selected':'').'>'.$enabled.'</option>
|
||||
<option value="0" '.($product['sn']==0?' selected':'').'>'.$disabled.'</option>
|
||||
</select>
|
||||
<label for="build">'.$product_build.'</label>
|
||||
<select id="status" name="build">
|
||||
<option value="1" '.($product['build']==1?' selected':'').'>'.$enabled.'</option>
|
||||
<option value="0" '.($product['build']==0?' selected':'').'>'.$disabled.'</option>
|
||||
</select>
|
||||
<label for="sales">'.$product_sales.'</label>
|
||||
<select id="status" name="salesflag">
|
||||
<option value="1" '.($product['salesflag']==1?' selected':'').'>'.$enabled.'</option>
|
||||
<option value="0" '.($product['salesflag']==0?' selected':'').'>'.$disabled.'</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
$view .= '<div class="content-block tab-content">
|
||||
<div class="form responsive-width-100">
|
||||
<label for="productcode">'.$general_created.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$product['created'].'" readonly>
|
||||
<label for="productcode">'.$general_createdby.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$product['createdby'].'" readonly>
|
||||
<label for="productcode">'.$general_updated.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.$product['updated'].'" readonly>
|
||||
<label for="productcode">'.$general_updatedby.'</label>
|
||||
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$product['updatedby'].'" readonly>
|
||||
</div>
|
||||
</div>';
|
||||
$view .= '</form>';
|
||||
|
||||
$view .= '<form action="" method="post" style="padding: 20px;" enctype="multipart/form-data">
|
||||
<input type="hidden" value="'.$product['rowID'].'" name="file_upload" />
|
||||
<input type="hidden" name="productcode" value="'.$product["productcode"].'"/>
|
||||
<input type="file" name="fileToUpload" id="fileToUpload" onchange="this.form.submit()" accept=".jpg, .jpeg, .png">
|
||||
</form>
|
||||
';
|
||||
|
||||
//Output
|
||||
echo $view;
|
||||
template_footer()?>
|
||||
$view .='<div class="content-block order-details">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-user fa-sm"></i>
|
||||
</div>';
|
||||
$picture = glob("./assets/images/products/".$responses->productcode.".{jpg,jpeg,png,gif}", GLOB_BRACE);
|
||||
if (!empty($picture)){
|
||||
$view .='
|
||||
<div class="order-detail">
|
||||
<img style="border-radius: 4px;height: 200px;margin: auto;" src="'.$picture[0].'" alt="">
|
||||
</div>
|
||||
';
|
||||
}
|
||||
$view .='
|
||||
</div>
|
||||
';
|
||||
$view .= '</div>';
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.$product_description.'
|
||||
</div>
|
||||
<div class="table order-table">
|
||||
'.$responses->productdescription.'
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.($product_version ?? '').'
|
||||
<a href="index.php?page=products_versions&productrowid='.$_GET['rowID'].'" class="btn2"> + </a>
|
||||
</div>';
|
||||
if (!empty($product_versions)){
|
||||
$view .= '
|
||||
<div class="table">
|
||||
<table class="sortable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>'.$product_version_number.'</th>
|
||||
<th>'.$product_version_version.'</th>
|
||||
<th>'.$product_version_software .'</th>
|
||||
<th>'.$general_actions.'</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
foreach ($product_versions as $version){
|
||||
$view .= '<tr>
|
||||
<td>'.$version->rowID.'</td>
|
||||
<td>'.$version->version.'</td>
|
||||
<td>'.$version->software.'</td>
|
||||
<td><a href="index.php?page=products_versions&productrowid='.$_GET['rowID'].'&rowID='.$version->rowID.'" class="btn_link">'.$general_view.'</a></td>
|
||||
</tr>';
|
||||
}
|
||||
$view .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
$view .= '
|
||||
</div>
|
||||
';
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.$tab4.'
|
||||
</div>
|
||||
<div class="table order-table">
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width:25%;">'.$product_serialized.'</td>
|
||||
<td>'.(($responses->sn == 1)? $enabled : $disabled).'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width:25%;">'.$product_sales.'</td>
|
||||
<td>'.(($responses->salesflag == 1)? $enabled : $disabled).'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width:25%;">'.$product_build.'</td>
|
||||
<td>'.(($responses->build == 1)? $enabled : $disabled).'</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$view .= '<div class="content-block">
|
||||
<div class="block-header">
|
||||
<i class="fa-solid fa-bars fa-sm"></i>'.$tab3.'
|
||||
</div>
|
||||
<div class="table order-table">
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width:25%;">'.$general_created.'</td>
|
||||
<td>'.$responses->created.'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width:25%;">'.$general_createdby.'</td>
|
||||
<td>'.$responses->createdby.'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width:25%;">'.$general_updated.'</td>
|
||||
<td>'.$responses->updated.'</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width:25%;">'.$general_updatedby.'</td>
|
||||
<td>'.$responses->updatedby.'</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
$view .='</div>';
|
||||
|
||||
//OUTPUT
|
||||
echo $view;
|
||||
|
||||
template_footer()
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user