|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/dev.outerorbittech.com/oot/admin/ | |
|
Path: /home2/outerorb/dev.outerorbittech.com/oot/admin/manage_products.php
Size: 23.03 KB
Permissions: 0644
<?php
include_once("../include/main.inc.php");
check_session('MyCpanel', 'index.php');
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start) == 0 or $start == "") ? $start = 0 : $start;
$pagesize = intval($pagesize) == 0 ? $pagesize = 100 : $pagesize;
if ($parentID == "") {
$parentID = 1;
}
$heading = "Manage Products";
$record_type = "Products";
$script_name = "manage_products.php";
$table_name = "product_tbl";
if ($id == "add_record") {
$cats = implode(',',$cats);
// print_r($_FILES);
// exit;
$sql = db_query("insert into $table_name set product_title='$product_title', product_code='$product_code', product_specfi='$product_specfi', product_cat='$cats'");
$last_inserted_product_id = mysqli_insert_id($dbconn);
if (!empty($_FILES['product_image']['name'][0])) {
foreach($_FILES['product_image']['name'] as $key => $image)
{
$file_extension = strtolower(getExtension($image));
$extensionArray = ['jpg','jpeg','png','gif','webp'];
if(!in_array($file_extension,$extensionArray))
{
$_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' only jpg,jpeg,png,gif,webp file allowed </div>';
header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&pagesize=" . $pagesize);
exit;
}
$_FILES['multiPro']['name'] = $image;
$_FILES['multiPro']['type'] = $_FILES['product_image']['type'][$key];
$_FILES['multiPro']['tmp_name'] = $_FILES['product_image']['tmp_name'][$key];
$_FILES['multiPro']['error'] = $_FILES['product_image']['error'][$key];
$_FILES['multiPro']['size'] = $_FILES['product_image']['size'][$key];
$pname = str_replace(" ", "-", $product_title);
$img_name = $pname.uniqid();
$img = upload_file($img_name,"multiPro", "uploaded-files/product-images");
$sql = db_query("insert into product_images set p_id='$last_inserted_product_id', p_image='$img'");
}
}
$_SESSION['session_message'] = '<div class="btn btn-success">New ' . $record_type . ' has been added successfully</div>';
header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&pagesize=" . $pagesize);
exit;
}
if (isset($_REQUEST['id']) && $_REQUEST['id'] == 'delete') {
$name = $_REQUEST['name'];
$cat_id = $_REQUEST['cat_id'];
$delete_sql = mysqli_query($dbconn, "SELECT * FROM $table_name WHERE product_id='$cat_id'");
$result = mysqli_fetch_array($delete_sql);
if (count($result) > 0) {
$image_array = explode(',', $result['product_image']);
if (in_array($name, $image_array)) {
$new_array = array_diff($image_array, [$name]);
$file_name = implode(',', $new_array);
$table = mysqli_query($dbconn, "UPDATE $table_name SET product_image='$file_name' WHERE product_id='$cat_id'");
}
}
}
if ($id == "update_record") {
$cats = implode(',',$cats);
if (!empty($_FILES['product_image']['name'][0])) {
foreach($_FILES['product_image']['name'] as $key => $image)
{
$file_extension = strtolower(getExtension($image));
$extensionArray = ['jpg','jpeg','png','gif','webp'];
if(!in_array($file_extension,$extensionArray))
{
$_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' only jpg,jpeg,png,gif,webp file allowed </div>';
header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&pagesize=" . $pagesize);
exit;
}
$_FILES['multiPro']['name'] = $image;
$_FILES['multiPro']['type'] = $_FILES['product_image']['type'][$key];
$_FILES['multiPro']['tmp_name'] = $_FILES['product_image']['tmp_name'][$key];
$_FILES['multiPro']['error'] = $_FILES['product_image']['error'][$key];
$_FILES['multiPro']['size'] = $_FILES['product_image']['size'][$key];
$pname = str_replace(" ", "-", $product_title);
$img_name = $pname.uniqid();
$img = upload_file($img_name,"multiPro", "uploaded-files/product-images");
$sql = db_query("insert into product_images set p_id='".$_GET['recordID']."', p_image='$img'");
}
}
updateTable($table_name, "product_title='$product_title', product_code='$product_code', product_cat='$cats', product_specfi='$product_specfi' where product_id='".$_GET['recordID']."'");
$_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been updated successfully</div>';
header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&pagesize=" . $pagesize);
exit;
}
if ($id == "delete_record") {
$pQuery = mysqli_query($GLOBALS['dbconn'],"select * from product_images where p_id='$recordID'");
while($pRes = mysqli_fetch_assoc($pQuery))
{
$filename = $pRes['p_image'];
if ($filename != "") {
$file = SITE_DIR_PATH . "/uploaded-files/product-images/" . $filename;
if (file_exists($file)) {
unlink($file);
}
$file_thumb = SITE_DIR_PATH . "/uploaded-files/product-images/thumbs/" . $filename;
if (file_exists($file_thumb)) {
unlink($file_thumb);
}
}
}
db_query("delete from $table_name where product_id='$recordID'");
db_query("delete from product_images where p_id='$recordID'");
$_SESSION['session_message'] = '<div class="alert alert-danger" role="alert">' . $record_type . ' has been deleted successfully</div>';
header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&pagesize=" . $pagesize);
exit;
}
if ($id == "delete_record_image") {
$pRes = getResult('product_images', " where id='$imgID'");
$filename = $pRes['p_image'];
if ($filename != "") {
$file = SITE_DIR_PATH . "/uploaded-files/product-images/" . $filename;
if (file_exists($file)) {
unlink($file);
}
$file_thumb = SITE_DIR_PATH . "/uploaded-files/product-images/thumbs/" . $filename;
if (file_exists($file_thumb)) {
unlink($file_thumb);
}
}
db_query("delete from product_images where id='$imgID'");
$_SESSION['session_message'] = '<div class="alert alert-danger" role="alert">' . $record_type . ' has been deleted successfully</div>';
header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?id=edit_record&recordID=" . $proID);
exit;
}
if (isset($feature_pro)) {
foreach ($pro_arr as $id) {
mysqli_query($dbconn, "UPDATE $table_name SET product_theme = '1' where product_id='$id'");
}
$_SESSION['session_message'] = '<div class="btn btn-warning">' . $record_type . ' has been set as Feature Product</div>';
header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?start=" . $start . "&parentID=" . $parentID . "&catID=" . $catID . "&pagesize=" . $pagesize);
exit;
}
admin_header();
$qry1 = mysqli_query($dbconn, "select * from $table_name");
$reccnt = mysqli_num_rows($qry1);
$qry = mysqli_query($dbconn, "select * from $table_name order by product_id desc");
// echo pageNavigation($reccnt,$pagesize,$start);
//print_message();
?>
<style>
select[multiple],
select[size] {
height: 200px;
}
</style>
<div class="content-wrapper">
<div class="page-header">
<h3 class="page-title">
<?=$heading;?>
</h3>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="<?admin_url?>welcome.php">Admin</a></li>
<li class="breadcrumb-item active" aria-current="page"><?=$heading;?></li>
</ol>
</nav>
</div>
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-12">
<div class="table-responsive">
<table id="order-listing" class="table table-bordered table-hover">
<thead>
<tr>
<th>S.No.</th>
<th>Product Name</th>
<th>Category Name</th>
<!-- <th>Image</th> -->
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$sl=$start+1;
while($arr=mysqli_fetch_array($qry)) {
$ImageQuqery = mysqli_query($dbconn, "SELECT p_image from product_images where p_id='".$arr['product_id']."'");
$prod_image = mysqli_fetch_array($ImageQuqery);
//$category_name = ($arr['category_id'] == 0)?'Home':get_category_name($arr['category_id']); ?>
<tr>
<td><?=$sl?></td>
<!-- <td><p class="ordern"><=$category_name;?></p></td>-->
<?php
$categoryQry = mysqli_query($dbconn, "SELECT catName from category_tbl where catID='".$arr['product_cat']."'");
$resCat = mysqli_fetch_assoc($categoryQry);
?>
<td><p class="dongle-dcs"> <?=$arr['product_title'];?></p></td>
<td><?=$resCat['catName'];?></td>
<!-- <td>
<?php
if ($prod_image['p_image'] != "") {
$file1 = SITE_DIR_PATH . "/uploaded-files/product-images/" . $prod_image['p_image'];
$dimens = GetImageSize($file1);
if ($dimens[0] > 130) {
$dimens[0] = $dimens[0] + 30;
$dimens[1] = $dimens[1] + 80;
} else {
$dimens[0] = 200;
$dimens[1] = 200;
}
?>
<a href="javascript:void(0);" onClick="openwin('<?= SITE_ADMIN_URL; ?>/popup_new.php?img=product-images/<?= $prod_image['p_image']; ?>', '<?= $dimens[0]; ?>', '<?= $dimens[1]; ?>')" class="pay-status-dcs">
<span class="adminThumb">
<img src="<?=site_url?>/uploaded-files/product-images/<?= $prod_image['p_image']; ?>">
</span>
</a>
<?php } ?>
</td> -->
<td><p class="download-dcs">
<a href="<?=$script_name;?>?id=edit_record&recordID=<?=$arr['product_id'];?>#bot">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-3"><path d="M12 20h9"></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path></svg>
</a>
<a href="<?=$script_name;?>?id=delete_record&recordID=<?=$arr['product_id'];?>" onClick="return confirm('Are you sure to delete this record...');">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16"> <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/> <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/> </svg></a></p>
</td>
</tr>
<?php $sl++; }?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="content-wrapper">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-12">
<form name="bannerFrm" method=post action="" enctype="multipart/form-data" onSubmit="return validate('bannerFrm') && chk_valid_date();">
<?php
if((!isset($_GET['recordID']) || $_GET['recordID'] == "") || $id != "edit_record") {
// if($_GET['recordID']=="" || $id!="edit_record") {
?>
<div class="text-center">
<h3>Add New <?=$record_type;?></h3>
</div>
<?php
}
else {
?>
<div align="left" height="20">
<h3>Edit <?=$record_type;?></h3>
</div>
<div align="right" height="20"><a class="btn btn-primary text-light" href="<?=$script_name.'?category_id='.$category_id;?>"><b>Add New <?=$record_type;?></b></a></div>
<br />
<?php
$gid = $_GET['recordID'];
}
$gid = isset($gid) ? $gid : null;
$res=getResult($table_name," where product_id='$gid'");
$resCatIds = explode(',',$res['product_cat']);
// print_r($res); die;
// $location_sql = mysqli_query($dbconn,"SELECT * FROM location_tbl WHERE parentID ='0' order by locationName asc");
// $category_name = ($category_id == 0)?'Home':get_category_name($category_id);
?>
<!-- <div class="form-group">
<label>Category<span>*</span></label>
<input type="text" name="category_name" value="<?= $category_name ?>" readonly class="form-control" />
</div> -->
<div class="form-group">
<div class="slt-cate">
<ul>
<?php
$cat_query = mysqli_query($GLOBALS['dbconn'], "select catName,catID,parentID from category_tbl where parentID='0' and status='Y' order by catOrder");
while ($res_cat = mysqli_fetch_assoc($cat_query)) {
if(in_array($res_cat['catID'],$resCatIds))
{
$sel = 'checked';
}
else{
$sel =" ";
}
?>
<li>
<input type="checkbox" name="cats[]" <?=$sel;?> id="<?=$res_cat['catID'];?>" value="<?=$res_cat['catID'];?>">
<label><?=$res_cat['catName'];?></label>
<ul>
<?php $cat_query_sub = mysqli_query($GLOBALS['dbconn'], "select catName,catID,parentID from category_tbl where parentID='".$res_cat['catID']."' and status='Y' order by catOrder");
while ($res_cat_sub = mysqli_fetch_assoc($cat_query_sub)) {
if(in_array($res_cat_sub['catID'],$resCatIds))
{
$sel = 'checked';
}
else{
$sel =" ";
}
?>
<li>
<input type="checkbox" name="cats[]" <?=$sel;?> id="<?=$res_cat_sub['catID'];?>" value="<?=$res_cat_sub['catID'];?>">
<label><?=$res_cat_sub['catName'];?></label>
<ul>
<?php $cat_query_sub_sub = mysqli_query($GLOBALS['dbconn'], "select catName,catID,parentID from category_tbl where parentID='".$res_cat_sub['catID']."' and status='Y' order by catOrder");
while ($res_cat_sub_sub = mysqli_fetch_assoc($cat_query_sub_sub)) {
if(in_array($res_cat_sub_sub['catID'],$resCatIds))
{
$sel = 'checked';
}
else{
$sel =" ";
}
?>
<li>
<input type="checkbox" <?=$sel;?> name="cats[]" id="<?=$res_cat_sub_sub['catID'];?>" value="<?=$res_cat_sub_sub['catID'];?>">
<label><?=$res_cat_sub_sub['catName'];?></label>
</li>
<?php }?>
</ul>
</li>
<?php } ?>
</ul>
</li>
<?php }?>
</ul>
</div>
<div class="form-group">
<label>Product Name <span>*</span></label>
<input type="text" name="product_title" value="<?= isset($res['product_title']) ? $res['product_title'] : ''; ?>" class="form-control" required />
</div>
<div class="form-group">
<label>Product Code<span>*</span></label>
<input type="text" name="product_code" value="<?= isset($res['product_code']) ? $res['product_code'] : ''; ?>" class="form-control" />
</div>
<div class="form-group">
<label>Product Specification<span>*</span></label>
<textarea rows="5" cols="60" name="product_specfi" class="form-control editor"><?= isset($res['product_specfi']) ? $res['product_specfi'] : ''; ?></textarea>
</div>
<div class="form-group row">
<div class="col">
<label for="exampleTextarea1">Product Image (Multiple)</label>
<input type="file" class="dropify" name="product_image[]" multiple>
</div>
<?php
$ImageQuqery = mysqli_query($dbconn, "SELECT p_image,id from product_images where p_id='".$res['product_id']."'");
while($prod_image = mysqli_fetch_array($ImageQuqery))
{
if($prod_image['p_image']!='')
{?>
<div class="col">
<img src="<?= site_url . "/uploaded-files/product-images/" . $prod_image['p_image'] ?>"
alt="Product Image" width="200" height="200">
<p> <a style="color:red;" href="<?=$script_name;?>?id=delete_record_image&imgID=<?=$prod_image['id']."&proID=".$res['product_id'];?>" onClick="return confirm('Are you sure to delete this record...');">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16"> <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/> <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/> </svg></a>
</p>
</div>
<?php }}?>
</div>
<div class="form-group">
<?php
$recordID = isset($recordID) ? $recordID : ''; // Default to an empty string if not set
if ($recordID != "") {
// if($recordID !="") {
?>
<input type="submit" name="submit" value="Update <?=$record_type;?>" class="button btn btn-success">
<input type="hidden" name="recordID" value="<?=$res['id'];?>">
<input type="hidden" name="id" value="update_record">
<?php
}
else{
?>
<input type="submit" name="submit" value="Add New <?=$record_type;?>" class="button btn btn-success">
<input type="hidden" name="id" value="add_record">
<?php
}
?>
<input type="hidden" name="start" value="<?=$start;?>">
<input type="hidden" name="pagesize" value="<?=$pagesize;?>">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="jquery.min.js"></script>
<script type="text/javascript">
$("#quickCity").change(function() {
var cityid = $('#quickCity').val();
$.ajax({
url: "ajax99.php", //The url where the server req would we made.
async: false,
type: "POST", //The type which you want to use: GET/POST
data: "cityid=" + cityid, //The variables which are going.
dataType: "html", //Return data type (what we expect).
//This is the function which will be called if ajax call is successful.
success: function(data) {
//data is the html of the page where the request is made.
$('#locatity').html(data);
}
})
});
// $(document).ready(function(){
// $('#checkAll').change(function() {
// if (this.checked) {
// $('.location-cls > input:checkbox').attr('checked', 'checked');
// }else{
// $('.location-cls > input:checkbox').attr('checked', '');
// }
// });
// $('#checkHalf').change(function(){
// if(this.checked){
// $('.checked-loca > input:checkbox').attr('checked', 'checked');
// }else{
// $('.checked-loca > input:checkbox').attr('checked', '');
// }
// })
// })
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#checkAll').change(function() {
$('.location-cls > input:checkbox').prop('checked', this.checked);
});
$('#checkHalf').change(function() {
const totalLocations = $('.location-cls > input:checkbox').length;
const halfLocations = Math.ceil(totalLocations / 2);
if (this.checked) {
$('.location-cls > input:checkbox').prop('checked', false); // Uncheck all first
$('.location-cls > input:checkbox').slice(0, halfLocations).prop('checked', true); // Check half
} else {
$('.location-cls > input:checkbox').prop('checked', false); // Uncheck all if unchecked
}
});
});
</script>
<?php define('SITE_URL_PATH', 'https://www.navnidhiferromet.com'); ?>
<iframe width=174 height=189 name="gToday:normal:agenda.js" id="gToday:normal:agenda.js"
src="<?=SITE_URL_PATH;?>/js/calendar/themes/Normal/ipopeng.htm"
scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;">
</iframe>
<?php
admin_footer();
exit;