ok
Direktori : /proc/thread-self/root/home2/selectio/www/ramali.in/dashboard/public/ |
Current File : //proc/thread-self/root/home2/selectio/www/ramali.in/dashboard/public/edit-category-form.php |
<?php include_once('includes/functions.php'); include_once('includes/custom-functions.php'); $fn = new custom_functions; ?> <?php error_reporting(E_ALL); ini_set('display_errors', 1); $ID = (isset($_GET['id'])) ? $db->escapeString($fn->xss_clean($_GET['id'])) : ""; $category_data = array(); $sql_query = "SELECT image FROM category WHERE id =" . $ID; $db->sql($sql_query); $res = $db->getResult(); if (isset($_POST['btnEdit'])) { if (ALLOW_MODIFICATION == 0 && !defined(ALLOW_MODIFICATION)) { echo '<label class="alert alert-danger">This operation is not allowed in demo panel!.</label>'; return false; } if ($permissions['categories']['update'] == 1) { $name = $db->escapeString($fn->xss_clean($_POST['name'])); $subtitle = $db->escapeString($fn->xss_clean($_POST['subtitle'])); $menu_image = $db->escapeString($fn->xss_clean($_FILES['image']['name'])); $image_error = $db->escapeString($fn->xss_clean($_FILES['image']['error'])); $image_type = $db->escapeString($fn->xss_clean($_FILES['image']['type'])); $error = array(); if (empty($name)) { $error['name'] = " <span class='label label-danger'>Required!</span>"; } if (empty($subtitle)) { $error['subtitle'] = " <span class='label label-danger'>Required!</span>"; } // get image file extension error_reporting(E_ERROR | E_PARSE); $extension = end(explode(".", $_FILES["image"]["name"])); /*if (!empty($menu_image)) { $result = $fn->validate_image($_FILES["image"]); if ($result) { $error['image'] = " <span class='label label-danger'>Image type must jpg, jpeg, gif, or png!</span>"; } }*/ if (!empty($name) && !empty($subtitle) && empty($error['image'])) { if (!empty($menu_image)) { $string = '0123456789'; $file = preg_replace("/\s+/", "_", $_FILES['image']['name']); $function = new functions; $image = $function->get_random_string($string, 4) . "-" . date("Y-m-d") . "." . $extension; // delete previous image // error_log($res[0]['image']); if(is_dir($res[0]['image'])) { unlink($res[0]['image']); } $date = date('Y-m-d', time()); if(isset($_FILES['banner_image']) && $_FILES['banner_image']['name']!="") { $file_name = $_FILES['banner_image']['name']; $tmp = explode('.', $file_name); $extension = end($tmp); $image = rand(10,1000000000)."-".$date."-profile." . $extension; $upload = move_uploaded_file($_FILES['banner_image']['tmp_name'], '../images/banner/' . $image); $banner_photo = 'images/banner/' . $image; } else { $banner_photo=''; } // upload new image $upload = move_uploaded_file($_FILES['image']['tmp_name'], 'upload/images/' . $image); $upload_image = 'upload/images/' . $image; $sql_query = "UPDATE category SET name = ' $name', subtitle = '$subtitle',image = '$upload_image' WHERE id = $ID"; if ($db->sql($sql_query)) { $db->sql($sql_query); $update_result = $db->getResult(); } } else { $sql_query = "UPDATE category SET name = '" . $name . "', subtitle = '" . $subtitle . "', image = '" . $res[0]['image'] . "', banner = '" .$banner_photo. "' WHERE id =" . $ID; $db->sql($sql_query); $update_result = $db->getResult(); } if (!empty($update_result)) { $update_result = 0; } else { $update_result = 1; } // check update result if ($update_result == 1) { $error['update_category'] = " <section class='content-header'><span class='label label-success'>Category updated Successfully</span></section>"; } else { $error['update_category'] = " <span class='label label-danger'>Failed update category</span>"; } } } else { $error['check_permission'] = " <section class='content-header'><span class='label label-danger'>You have no permission to update category</span></section>"; } } // create array variable to store previous data $data = array(); $sql_query = "SELECT * FROM category WHERE id =" . $ID; $db->sql($sql_query); $res = $db->getResult(); if (isset($_POST['btnCancel'])) { ?> <script> window.location.href = "categories.php"; </script> <?php } ?> <section class="content-header"> <h1> Edit Category<small><a href='categories.php'><i class='fa fa-angle-double-left'></i> Back to Categories</a></small></h1> <small><?php echo isset($error['update_category']) ? $error['update_category'] : ''; ?></small> <ol class="breadcrumb"> <li><a href="home.php"><i class="fa fa-home"></i> Home</a></li> </ol> </section> <section class="content"> <!-- Main row --> <div class="row"> <div class="col-md-6"> <?php if ($permissions['categories']['update'] == 0) { ?> <div class="alert alert-danger topmargin-sm">You have no permission to update category.</div> <?php } ?> <!-- general form elements --> <div class="box box-primary"> <div class="box-header with-border"> <h3 class="box-title">Edit Category</h3> </div><!-- /.box-header --> <!-- form start --> <form id="edit_category_form" method="post" enctype="multipart/form-data"> <div class="box-body"> <div class="form-group"> <label for="exampleInputEmail1">Category Name</label><?php echo isset($error['name']) ? $error['name'] : ''; ?> <input type="text" class="form-control" name="name" value="<?php echo $res[0]['name']; ?>"> </div> <div class="form-group"> <label for="exampleInputEmail1">Category Subtitle</label><?php echo isset($error['subtitle']) ? $error['subtitle'] : ''; ?> <input type="text" class="form-control" name="subtitle" value="<?php echo $res[0]['subtitle']; ?>"> </div> <div class="form-group"> <label for="exampleInputFile">Image *Please choose square image of larger than 350px*350px & smaller than 550px*550px.</label><?php echo isset($error['image']) ? $error['image'] : ''; ?> <input type="file" name="image" id="image" title="Please choose square image of larger than 350px*350px & smaller than 550px*550px." value="<img src='<?php echo $data['image']; ?>'/>"> <p class="help-block"><img src="<?php echo $res[0]['image']; ?>" width="280" height="190" /></p> </div> <div class="form-group"> <label for="exampleInputFile">Image *Please choose square image of larger than 1240px*300px </label><?php echo isset($error['image']) ? $error['image'] : ''; ?> <input type="file" name="banner_image" id="banner_image" title="Please choose square image of larger than 350px*350px" value="<img src='<?php echo $data['banner']; ?>'/>"> <p class="help-block"><img src="<?php echo '../'.$res[0]['banner']; ?>" width="280" height="190" /></p> </div> </div><!-- /.box-body --> <div class="box-footer"> <button type="submit" class="btn btn-primary" name="btnEdit">Update</button> <button type="submit" class="btn btn-danger" name="btnCancel">Cancel</button> </div> </form> </div><!-- /.box --> </div> </div> </section> <div class="separator"> </div> <?php $db->disconnect(); ?> <script src="dist/js/jquery.validate.min.js"></script> <script> $('#edit_category_form').validate({ rules: { name: "required", subtitle: "required", } }); </script> <script> // var changeCheckbox = document.querySelector('#product_rating_btn'); // var init = new Switchery(changeCheckbox); // changeCheckbox.onchange = function() { // if ($(this).is(':checked')) { // $('#product_rating').val(1); // } else { // $('#product_rating').val(0); // } // }; </script>