Пример #1
0
function updateProduct_action()
{
    $product_id = $_GET['product_id'];
    $name = $_POST['name'];
    $type = $_POST['type'];
    $price = $_POST['price'];
    $list_url = 'http://' . HOST . '/' . APPLICATION . '/index.php?page=home';
    $edit_url = 'http://' . HOST . '/' . APPLICATION . '/index.php?page=editProduct';
    $product = new product($name, $type, $price);
    $result = $product->updateProduct($product_id);
    if ($result) {
        header("Location: {$list_url}");
    } else {
        header("Location: {$edit_url}" . '&product_id=' . $product_id);
    }
}
Пример #2
0
         for ($i = 0; $i < count($_POST['thongso']); $i++) {
             $key = $_POST['thongso'][$i];
             $thongsokythuat[$key] = $_POST['giatri'][$i];
         }
         $image_phu = array();
         $ma_sp = $_POST['ma_sp'];
         $soluong = $_POST['soluong'];
         $position = isset($_POST['position']) ? $_POST['position'] : 0;
         $hot = $_POST['hot'];
         $status = $_POST['active'];
         $id = $_POST['id'];
         if (!empty($_FILES['file']['name'])) {
             $temp_name = explode(".", $_FILES["file"]["name"]);
             $newfilename = microtime() . '.' . end($temp_name);
             if (upload_image($_FILES['file'], $newfilename)) {
                 if ($pro_obj->updateProduct($pro_name, $newfilename, $tomtat, $description, $price_niemyet, $price_sale, $thongsokythuat, $image_phu, $ma_sp, $soluong, $position, $hot, $status, $cat_id, $mausac, $id)) {
                     header("Location: ../index.php?view=list-product&stt=success");
                 } else {
                     header("Location: ../index.php?view=list-product&stt=fail");
                 }
             }
         } else {
             if ($pro_obj->updateProduct($pro_name, '', $tomtat, $description, $price_niemyet, $price_sale, $thongsokythuat, $image_phu, $ma_sp, $soluong, $position, $hot, $status, $cat_id, $mausac, $id)) {
                 header("Location: ../index.php?view=list-product&stt=success");
             } else {
                 header("Location: ../index.php?view=list-product&stt=fail");
             }
         }
     }
     break;
 case "xoa":
Пример #3
0
// Products
$app->get('/products', function () {
    $product = new product();
    $response = $product->getAllProduct();
    echoResponse(200, $response);
});
$app->post('/products', function () use($app) {
    $product = new product();
    $data = json_decode($app->request->getBody(), TRUE);
    $id = $product->AddProduct($data);
    echoResponse(200, $id);
});
$app->put('/products/:id', function ($id) use($app) {
    $product = new product();
    $data = json_decode($app->request->getBody(), TRUE);
    $result = $product->updateProduct($id, $data);
    // $rows["message"] = "Product information updated successfully.";
    echoResponse(200, $result);
});
$app->delete('/products/:id', function ($id) {
    $product = new product();
    $id = $product->deleteProduct($id);
    echoResponse(200, $id);
});
function echoResponse($status_code, $response)
{
    global $app;
    $app->status($status_code);
    $app->contentType('application/json');
    echo json_encode($response, JSON_NUMERIC_CHECK);
}
Пример #4
0
        exit;
    } else {
        if ($product->addProduct($data)) {
            header('Location: ' . FRONTEND . 'inventory.php');
            exit;
        }
    }
} elseif (isset($_POST['action']) && $_POST['action'] == 'update') {
    $file = $_FILES;
    $data = $_POST['data']['Item'];
    if (isset($file['name'])) {
        $data['image'] = $file['name'];
    } else {
        $data['image'] = '';
    }
    if ($product->updateProduct($data)) {
        $_SESSION['message'] = 'Product has been updated successfully.';
        header('Location: ' . FRONTEND . 'inventory.php');
        exit;
    }
} elseif (isset($_GET['action']) && $_GET['action'] == 'delete') {
    $id = $_GET['id'];
    if ($product->deleteProduct($id)) {
        $_SESSION['message'] = 'Product has been deleted successfully.';
        header('Location: ' . FRONTEND . 'inventory.php');
        exit;
    }
} elseif (isset($_GET['action']) && $_GET['action'] == 'search') {
    $keyword = $_POST['keywords'];
    $products = $product->getSearchProducts($keyword);
    $smarty->assign('productcount', count($products));