
PK 
<?php
ob_start();
//error_reporting(E_ALL ^ E_NOTICE);
@session_start();
ini_set('allow_url_include',1);
date_default_timezone_set("Asia/Kolkata");
set_time_limit(600);
ini_set('max_execution_time',600);
require_once '../includes/settings/PDODB.php';
include '../includes/modules/functions.php';
if(empty($_SESSION['creoadminId'])){
header("Location: ../index.php");
exit();
}
$function = new FUNCTIONS();
$parentscategorydata = $function->getCat($cat_id=NULL,$parents_id=0,$isactive=1);
$productdata = $function->getProduct($id=$_GET['id'],$cat_id=NULL,$isactive=1,$orderBy='DESC');
//print_r($productdata); exit();
function CategoryTree(&$output=null, $parents_id=0, $indent=null){
// conection to the database
$db = new PDO("mysql:host=localhost;dbname=questend_gsfashion", 'root', '');
// select the categories that have on the parent column the value from $parent
$r = $db->prepare("SELECT * FROM category WHERE parents_id=:parentid");
$r->execute(array(
'parentid' => $parents_id
));
// show the categories one by one
while($c = $r->fetch(PDO::FETCH_ASSOC)){
$function = new FUNCTIONS();
$productdata = $function->getProduct($id=$_GET['id'],$cat_id=NULL,$isactive=1,$orderBy='DESC');
$output .= '<option '
. ( $productdata[0]['cat_id'] == $c['cat_id'] ? 'selected="selected"' : '' ) .'value='.$c['cat_id']. '>'
. $indent . $c['cat_name']
. '</option>';
//print_r($categorydata[0]['parents_id']); exit;
if($c['cat_id'] != $parents_id){
// in case the current category's id is different that $parent
// we call our function again with new parameters
CategoryTree($output, $c['cat_id'], $indent . " ");
}
}
// return the list of categories
return $output;
}
if(isset($_POST['btnEditProduct']) && !empty($_POST)){
//print_r($_POST); exit;
$cat_id = !empty($_POST['cat_id'])?trim($_POST['cat_id']):"";
$product_name = !empty($_POST['product_name'])?trim($_POST['product_name']):"";
$description = !empty($_POST['description'])?trim($_POST['description']):"";
$error_msg = "";
$oldfile = $_POST['oldfile'];
$id=$_GET['id'];
$file = $_FILES['file'];
if (!empty($file['name'])) {
$newfilename = uniqid('product-',false);
$foldername = "../uploads/product/";
$imggg = $function->uploadFile($newfilename, $foldername, 'file');
if($imggg[2]){
unlink($foldername.$oldfile); //remove the file
}
$oldfile = $imggg[2];
}
$pdodb = PDODB::getInstance();
$sql = "UPDATE product SET cat_id='".$cat_id."',product_name='".$product_name."',description='".$description."',file='".$oldfile."' WHERE id = '".$id."'";
//exit;
$result = $pdodb->query($sql);
//echo "vinay3"; exit;
PDODB::closeInstance();
if($result) {
header("Location: index.php");
}else{
header("Location: index.php");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>INSPINIA | Basic Form</title>
<?php include_once '../layout/style.php'; ?>
</head>
<body>
<div id="wrapper">
<nav class="navbar-default navbar-static-side" role="navigation">
<div class="sidebar-collapse">
<ul class="nav metismenu" id="side-menu">
<li class="nav-header">
<div class="dropdown profile-element"> <span>
<img alt="image" class="img-circle" src="../img/profile_small.jpg" />
</span>
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">Vinay</strong>
</span> <span class="text-muted text-xs block">Art Director <b class="caret"></b></span> </span> </a>
<ul class="dropdown-menu animated fadeInRight m-t-xs">
<li><a href="#">Profile</a></li>
<li class="divider"></li>
<li><a href="#">Logout</a></li>
</ul>
</div>
<div class="logo-element">Vinay</div>
</li>
<li>
<a href="#"><i class="fa fa-th-large"></i> <span class="nav-label">Dashboards</span> <span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li><a href="../dashboard/index.php">Dashboard</a></li>
</ul>
</li>
<li>
<a href="#"><i class="fa fa-list"></i><span class="nav-label">Category</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level collapse">
<li><a href="../category/create.php">Create Category</a></li>
<li><a href="../category/index.php">List of Category</a></li>
<li><a href="../category/inactive.php">Off Category List</a></li>
</ul>
</li>
<li class="active">
<a href="#"><i class="fa fa-file-image-o"></i> <span class="nav-label">Product</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level collapse">
<li><a href="../product/index.php">Product List</a></li>
<li class="active"><a href="../product/create.php">Add Product</a></li>
</ul>
</li>
</ul>
</div>
</nav>
<div id="page-wrapper" class="gray-bg">
<?php include_once '../layout/header.php'; ?>
<div class="row wrapper border-bottom white-bg page-heading">
<div class="col-lg-10">
<h2>Add Product Form</h2>
<ol class="breadcrumb">
<li>
<a href="index.php">Home</a>
</li>
<li>
<a>Forms</a>
</li>
<li class="active">
<strong>Add Product</strong>
</li>
</ol>
</div>
<div class="col-lg-2">
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title back-change">
</div>
<div class="ibox-content">
<div class="row">
<form method="POST" action="" enctype="multipart/form-data" id="addProduct">
<div class="col-sm-12">
<div class="form-group">
<label>Category*</label>
<?php
echo "<select name='cat_id' class='form-control'>
<option value='0'>Select a category</option>" .
CategoryTree() .
"</select>";
?>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label>Product Name*</label>
<input type="text" value="<?=$productdata[0]['product_name'];?>" name="product_name" id="product_name" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label>Description*</label>
<textarea name="description" id="description" class="tinymce">
<?=!empty($productdata[0]['description'])?$productdata[0]['description']:'';?>
</textarea>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<h4>Preview image</h4>
<div class="img-preview img-preview-sm">
<img alt="Image Display Here" id="test" src="../uploads/product/<?=$productdata[0]['file'];?>" style="min-width: 0px !important; min-height: 0px !important; max-width: none !important; max-height: none !important; width: 200px;">
</div>
<form id="form1" runat="server">
<input type="file" id="file" class="btn btn-primary" onchange="readURL(this);" name="file">
<p>Image Dimensions 1024 x 300 pixels.</p>
<input type="hidden" name="oldfile" id="oldfile" value="<?=$productdata[0]['file'];?>">
</form>
</div>
<div class="form-group">
<div>
<button class="btn btn-sm btn-primary pull-right m-t-n-xs" name="btnEditProduct" id="btnEditProduct" type="submit"><strong>UPDATE</strong></button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include_once '../layout/script.php'; ?>
<script type="text/javascript" src="../js/plugins/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="../js/plugins/tinymce/init-tinymce.js"></script>
<script>
function tossterMsgAlert(msg='Welcome',title='') {
toastr.options = {
closeButton: true,
//debug: false,
newestOnTop: false,
//progressBar: false,
positionClass: 'toast-top-center',
preventDuplicates: true,
//onclick: null,
//showDuration: 300,
//hideDuration: 1000,
timeOut: 2000,
//extendedTimeOut: 1000,
//showEasing: 'swing',
//hideEasing: 'linear',
//showMethod: 'fadeIn',
hideMethod: 'fadeOut'
};
toastr.warning(title,msg);
}
</script>
<script type="text/javascript">
$("#addProduct").validate({
rules: {
product_name: {
required: true
}
},
messages: {
product_name: {
required: "Please Enter Product Name"
}
},
submitHandler: function(form) {
form.submit();
}
});
</script>
<!-- <script type="text/javascript">
$('#parents').on('change', function() {
var cat_id = $('select#parents').find(':selected').data('parents');
//$('#category option').find(':selected').attr("data-service");
//console.log(cat_id);
$("#cat_id").val(cat_id);
});
</script> -->
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#test').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
};
</script>
</body>
</html>


PK 99