diff --git a/Dockerfile b/Dockerfile index 89ccbdd15a898962a2d72616099eb60ed7ea16f7..9ef737b105279fa8e77508b757ee207b3de5286d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM php:8.0-apache WORKDIR /var/www/html -COPY src/App/. /var/www/html -RUN docker-php-ext-install mysqli pdo pdo_mysql +COPY src/. /var/www/html +RUN docker-php-ext-install mysqli RUN a2enmod rewrite -RUN apt-get -y update && apt-get -y upgrade && apt-get install -y ffmpeg +RUN apt-get -y update && apt-get -y upgrade EXPOSE 8080 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5fd9ca08725c4bd982084e15e13235c1efc6d52f..0054d0bc93e872955c74a753380b41a7db3c578e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: dockerfile: Dockerfile env_file: .env volumes: - - ./src/App:/var/www/html + - ./src:/var/www/html mysql: image: mysql:latest diff --git a/src/App/.htaccess b/src/.htaccess similarity index 100% rename from src/App/.htaccess rename to src/.htaccess diff --git a/src/App/controller/home/NotFoundController.php b/src/App/controller/home/NotFoundController.php deleted file mode 100644 index eeb4b0a6db517d5ee342952a8c1aa62cfeb650b6..0000000000000000000000000000000000000000 --- a/src/App/controller/home/NotFoundController.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -class NotFoundController extends Controller{ - public function index() { - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName); - - $view->render(); - } -} \ No newline at end of file diff --git a/src/App/controller/login/LogoutController.php b/src/App/controller/login/LogoutController.php deleted file mode 100644 index cc4b9b40b903b11c46ac0b6960951874693a9d2e..0000000000000000000000000000000000000000 --- a/src/App/controller/login/LogoutController.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -class LogoutController extends Controller{ - public function index() { - if($this->userRole === 0) { - throw new Exception("You are not allowed to view this page", 405); - } - - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName); - - $view->render(); - } -} \ No newline at end of file diff --git a/src/App/controller/profile/ProfileController.php b/src/App/controller/profile/ProfileController.php deleted file mode 100644 index e052a4b61054264d000baba9da0b5d87e6fa0969..0000000000000000000000000000000000000000 --- a/src/App/controller/profile/ProfileController.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -class ProfileController extends Controller -{ - public function index() - { - if($this->userRole === 0) { - header("Location: /login"); - exit(); - } - - $userModel = $this->model("UserModel"); - - $data = []; - - if (isset($_SESSION['user_id'])) { - $data = $userModel->getCurrentUser(); - } - - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName, $data); - - $view->render(); - } -} diff --git a/src/App/components/cart/Cart.php b/src/components/cart/Cart.php similarity index 90% rename from src/App/components/cart/Cart.php rename to src/components/cart/Cart.php index 811bd29559286d119793edf7285f791ac574ab43..445572302e99a112c5d4d5d58868407bfc622a3d 100644 --- a/src/App/components/cart/Cart.php +++ b/src/components/cart/Cart.php @@ -4,10 +4,10 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/Global.css"> - <link rel="stylesheet" href="../../public/styles/cart/Cart.css"> + <link rel="stylesheet" href="../../styles/Global.css"> + <link rel="stylesheet" href="../../styles/cart/Cart.css"> <title>Shopping Cart</title> - <script src="../../public/scripts/Cart/cart.js"></script> + <script src="../../scripts/cart/cart.js"></script> </head> <body> @@ -30,7 +30,7 @@ $itemDetail = $this->data['cartItems'][$item['product_id']]; $productFile = $this->data['productFileModel']->getProductFile($itemDetail['id'])->fetch_assoc(); $total = $itemDetail['price'] * $item['quantity']; - $imagePath = '../../public/storage/image/'. $productFile['file_name']; + $imagePath = '../../storage/image/'. $productFile['file_name']; $cartTable .= " <tr> diff --git a/src/App/components/category/Category.php b/src/components/category/Category.php similarity index 86% rename from src/App/components/category/Category.php rename to src/components/category/Category.php index 0cb4bad59babed65e16172323d636a369bc34c9e..313439dd212486a973bb0bfd1d440fe2bc61bf8f 100644 --- a/src/App/components/category/Category.php +++ b/src/components/category/Category.php @@ -3,10 +3,10 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/Global.css"> - <link rel="stylesheet" href="../../public/styles/category/category.css"> - <link rel="stylesheet" href="../../public/styles/category/addCategory.css"> - <script src="../../public/scripts/Category/category.js"></script> + <link rel="stylesheet" href="../../styles/Global.css"> + <link rel="stylesheet" href="../../styles/category/Category.css"> + <link rel="stylesheet" href="../../styles/category/AddCategory.css"> + <script src="../../scripts/category/category.js"></script> <title>Kategori</title> </head> <body> diff --git a/src/App/components/home/Home.php b/src/components/home/Home.php similarity index 88% rename from src/App/components/home/Home.php rename to src/components/home/Home.php index b156231f298f437c8e94002f09746924064a2051..fc80fee39d4e0c53a2f246b92cf2d4c81c8f85e1 100644 --- a/src/App/components/home/Home.php +++ b/src/components/home/Home.php @@ -5,10 +5,10 @@ <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- global CSS --> - <link rel="stylesheet" href="../../public/styles/product/ProductCard.css"> - <link rel="stylesheet" href="../../public/styles/home/Home.css"> - <link rel="stylesheet" href="../../public/styles/Global.css"> - <script src="../../public/scripts/functions/debounce.js"></script> + <link rel="stylesheet" href="../../styles/product/ProductCard.css"> + <link rel="stylesheet" href="../../styles/home/Home.css"> + <link rel="stylesheet" href="../../styles/Global.css"> + <script src="../../scripts/functions/debounce.js"></script> <title>Home Page</title> </head> @@ -85,7 +85,7 @@ foreach($this->data['product'] as $product){ foreach($this->data['productFile'] as $productFile){ if($product[0] == $productFile[1]){ - $path = '../../public/storage/image/'. $productFile[2]; + $path = '../../storage/image/'. $productFile[2]; product_card_template( $path, $product[2], @@ -108,5 +108,5 @@ </body> </html> -<script src="../../public/scripts/home/paginateForm.js"></script> -<script src="../../public/scripts/home/search.js"></script> \ No newline at end of file +<script src="../../scripts/home/paginateForm.js"></script> +<script src="../../scripts/home/search.js"></script> \ No newline at end of file diff --git a/src/App/components/home/NotFound.php b/src/components/home/NotFound.php similarity index 73% rename from src/App/components/home/NotFound.php rename to src/components/home/NotFound.php index 8342c036631d39786973f592d666ad4218432e16..13dc244d0f691b18e3dd68d75f2422aa2dfdf330 100644 --- a/src/App/components/home/NotFound.php +++ b/src/components/home/NotFound.php @@ -3,8 +3,8 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/home/Home.css"> - <link rel="stylesheet" href="../../public/styles/Global.css"> + <link rel="stylesheet" href="../../styles/home/Home.css"> + <link rel="stylesheet" href="../../styles/Global.css"> <title>404 Not Found</title> </head> diff --git a/src/App/components/login/Login.php b/src/components/login/Login.php similarity index 87% rename from src/App/components/login/Login.php rename to src/components/login/Login.php index 1c30a98e9aa2d154b1b6b1fd93cc171656a32703..b9f37f56164a31ef4104d1ca3b2715f03849a4d7 100644 --- a/src/App/components/login/Login.php +++ b/src/components/login/Login.php @@ -9,8 +9,8 @@ if (isset($_SESSION["user_id"])) { <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/login/Login.css"> - <link rel="stylesheet" href="../../public/styles/Global.css"> + <link rel="stylesheet" href="../../styles/login/Login.css"> + <link rel="stylesheet" href="../../styles/Global.css"> <title>Login</title> </head> diff --git a/src/App/components/login/Logout.php b/src/components/login/Logout.php similarity index 100% rename from src/App/components/login/Logout.php rename to src/components/login/Logout.php diff --git a/src/App/components/login/Register.php b/src/components/login/Register.php similarity index 91% rename from src/App/components/login/Register.php rename to src/components/login/Register.php index e35f79b8214cc80f29e74cd5aca4050d4bbeafc3..e52d4d9b14049508fdf2a0904d2e15456a62c2e6 100644 --- a/src/App/components/login/Register.php +++ b/src/components/login/Register.php @@ -9,8 +9,8 @@ if (isset($_SESSION["user_id"])) { <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/login/Login.css"> - <link rel="stylesheet" href="../../public/styles/Global.css"> + <link rel="stylesheet" href="../../styles/login/Login.css"> + <link rel="stylesheet" href="../../styles/Global.css"> <title>register</title> </head> diff --git a/src/App/components/product/AddProduct.php b/src/components/product/AddProduct.php similarity index 92% rename from src/App/components/product/AddProduct.php rename to src/components/product/AddProduct.php index aa4f1a81e307d3eafdfb7a85ac70d4a5f6d42cf7..e3bb4bfce63bebd85eb4703153a6505b7eb96610 100644 --- a/src/App/components/product/AddProduct.php +++ b/src/components/product/AddProduct.php @@ -3,8 +3,8 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/product/addProduct.css"> - <link rel="stylesheet" href="../../public/styles/Global.css"> + <link rel="stylesheet" href="../../styles/product/AddProduct.css"> + <link rel="stylesheet" href="../../styles/Global.css"> <title>Tambah Produk</title> </head> <body> diff --git a/src/App/components/product/EditProduct.php b/src/components/product/EditProduct.php similarity index 87% rename from src/App/components/product/EditProduct.php rename to src/components/product/EditProduct.php index 202587e6465dc1207e19d1de9f492c29d2c1b7f9..9856d3ec4e997f0ea019c5081a3520727b22243d 100644 --- a/src/App/components/product/EditProduct.php +++ b/src/components/product/EditProduct.php @@ -3,9 +3,9 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/product/addProduct.css"> - <link rel="stylesheet" href="../../public/styles/Global.css"> - <script src="../../public/scripts/popup.js"></script> + <link rel="stylesheet" href="../../styles/product/AddProduct.css"> + <link rel="stylesheet" href="../../styles/Global.css"> + <script src="../../scripts/popup.js"></script> <title>Edit Produk</title> </head> <body> @@ -44,14 +44,14 @@ <label for="product_image">Gambar Produk:</label> <div class="product-image"> - <img src= <?php echo "../../public/storage/image/". $this->data['productFile'][0][2] ?> alt="Product Image"> + <img src= <?php echo "../../storage/image/". $this->data['productFile'][0][2] ?> alt="Product Image"> </div> <input type="file" id="product_image" name="product_image" accept="image/*" title="Ganti Produk"> <label for="product_video">Video Produk:</label> <?php if(sizeof($this->data['productFile'])>1){ - $src = '../../public/storage/video/'.$this->data['productFile'][1][2]; + $src = '../../storage/video/'.$this->data['productFile'][1][2]; echo " <video width='320' height='240' controls> <source src=$src type='video/mp4'> diff --git a/src/App/components/product/Product.php b/src/components/product/Product.php similarity index 80% rename from src/App/components/product/Product.php rename to src/components/product/Product.php index 418aa833beb47eb86329c6f327987ea70a01158d..66843eb1c1af8e7dfd721e117a2045d835cabad4 100644 --- a/src/App/components/product/Product.php +++ b/src/components/product/Product.php @@ -3,8 +3,8 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/product/product.css"> - <link rel="stylesheet" href="../../public/styles/Global.css"> + <link rel="stylesheet" href="../../styles/product/Product.css"> + <link rel="stylesheet" href="../../styles/Global.css"> <title><?php echo $this->data['product']['name']; ?></title> </head> <body> @@ -14,10 +14,10 @@ <div class="product-container"> <div class="product-image"> - <img src= <?php echo "../../public/storage/image/". $this->data['productFile'][0][2] ?> alt="Product Image"> + <img src= <?php echo "../../storage/image/". $this->data['productFile'][0][2] ?> alt="Product Image"> <?php if(sizeof($this->data['productFile']) > 1){ - $src = '../../public/storage/video/'.$this->data['productFile'][1][2]; + $src = '../../storage/video/'.$this->data['productFile'][1][2]; echo " <video controls> <source src=$src type='video/mp4'> diff --git a/src/App/components/profile/EditProfile.php b/src/components/profile/EditProfile.php similarity index 92% rename from src/App/components/profile/EditProfile.php rename to src/components/profile/EditProfile.php index 263508f21f4fd12a1e506667dd57d7bf70b86f8d..f9a45cab9e37caa68ce7d8ab292ef5cc228310b7 100644 --- a/src/App/components/profile/EditProfile.php +++ b/src/components/profile/EditProfile.php @@ -4,8 +4,8 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/profile/Profile.css"> - <link rel="stylesheet" href="../../public/styles/Global.css"> + <link rel="stylesheet" href="../../styles/profile/Profile.css"> + <link rel="stylesheet" href="../../styles/Global.css"> <title>Profile</title> </head> diff --git a/src/App/components/profile/Profile.php b/src/components/profile/Profile.php similarity index 90% rename from src/App/components/profile/Profile.php rename to src/components/profile/Profile.php index e8ea4307fa8f38fe45faf3cc80f2138bbb0303cb..7ad277b83406df1f1c0ce9db2e2d1578be601f4c 100644 --- a/src/App/components/profile/Profile.php +++ b/src/components/profile/Profile.php @@ -4,8 +4,8 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="stylesheet" href="../../public/styles/profile/Profile.css"> - <link rel="stylesheet" href="../../public/styles/Global.css"> + <link rel="stylesheet" href="../../styles/profile/Profile.css"> + <link rel="stylesheet" href="../../styles/Global.css"> <title>Profile</title> </head> diff --git a/src/App/components/template/Navbar.php b/src/components/template/Navbar.php similarity index 95% rename from src/App/components/template/Navbar.php rename to src/components/template/Navbar.php index 100ecfca7a64edc4fcd360ecc369707c517a92e3..93e3767e96ba52e103dccfbd0db106118feffb62 100644 --- a/src/App/components/template/Navbar.php +++ b/src/components/template/Navbar.php @@ -3,7 +3,7 @@ $title = basename($_SERVER['PHP_SELF']); $title = str_replace('.php', '', $title); ?> -<link rel="stylesheet" href="../../public/styles/template/Navbar.css"> +<link rel="stylesheet" href="../../styles/template/Navbar.css"> <header> <nav id="site-menu"> <ul> diff --git a/src/App/components/template/Pagination.php b/src/components/template/Pagination.php similarity index 100% rename from src/App/components/template/Pagination.php rename to src/components/template/Pagination.php diff --git a/src/App/components/template/ProductCard.php b/src/components/template/ProductCard.php similarity index 100% rename from src/App/components/template/ProductCard.php rename to src/components/template/ProductCard.php diff --git a/src/App/controller/Controller.php b/src/controller/Controller.php similarity index 64% rename from src/App/controller/Controller.php rename to src/controller/Controller.php index a90d2d96434bfe80076f6c50ab72877ebfc52310..199b8767a33d4bb5eedbb2d67fb6cd47653ec503 100644 --- a/src/App/controller/Controller.php +++ b/src/controller/Controller.php @@ -20,4 +20,15 @@ class Controller{ require_once __DIR__. "/../models/$model.php"; return new $model(); } + + protected function render($data = []) { + require __DIR__ . '/../views/Routes.php'; + $className = static::class; + $fileName = str_replace('Controller', '', $className); + $folderName = $routes[$fileName]; + + $view = $this->view($folderName, $fileName, $data); + + $view->render(); + } } \ No newline at end of file diff --git a/src/App/controller/cart/AddCartController.php b/src/controller/cart/AddCartController.php similarity index 100% rename from src/App/controller/cart/AddCartController.php rename to src/controller/cart/AddCartController.php diff --git a/src/App/controller/cart/CartController.php b/src/controller/cart/CartController.php similarity index 82% rename from src/App/controller/cart/CartController.php rename to src/controller/cart/CartController.php index ab3c256b539ef5b8c1de7d37bc5b71b60aa2eb79..7f395f31712c11a41f47d0860e9c8f0804e24caf 100644 --- a/src/App/controller/cart/CartController.php +++ b/src/controller/cart/CartController.php @@ -40,15 +40,6 @@ class CartController extends Controller { "productFileModel" => $productFileModel ]; - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName, $data); - - $view->render(); + $this->render($data); } - - } diff --git a/src/App/controller/cart/CheckoutController.php b/src/controller/cart/CheckoutController.php similarity index 100% rename from src/App/controller/cart/CheckoutController.php rename to src/controller/cart/CheckoutController.php diff --git a/src/App/controller/cart/DeleteCartController.php b/src/controller/cart/DeleteCartController.php similarity index 100% rename from src/App/controller/cart/DeleteCartController.php rename to src/controller/cart/DeleteCartController.php diff --git a/src/App/controller/cart/UpdateCartController.php b/src/controller/cart/UpdateCartController.php similarity index 91% rename from src/App/controller/cart/UpdateCartController.php rename to src/controller/cart/UpdateCartController.php index e641df8ad42744f5476ca4194c89f2011614d55d..290177b81525a26ff157d445673d6fd56f242adc 100644 --- a/src/App/controller/cart/UpdateCartController.php +++ b/src/controller/cart/UpdateCartController.php @@ -6,8 +6,6 @@ $product_id = $_POST['product_id']; $new_quantity = $_POST['new_quantity']; - echo $new_quantity; - $cartModel = $this->model("CartModel"); $cartModel = $cartModel->updateProductFromCart($user_id, $product_id, $new_quantity); diff --git a/src/App/controller/category/AddCategoryController.php b/src/controller/category/AddCategoryController.php similarity index 100% rename from src/App/controller/category/AddCategoryController.php rename to src/controller/category/AddCategoryController.php diff --git a/src/App/controller/category/CategoryController.php b/src/controller/category/CategoryController.php similarity index 73% rename from src/App/controller/category/CategoryController.php rename to src/controller/category/CategoryController.php index 7ce39dd54f6ebe74c77a5c56a73a6639f13893d3..2fe9dbcd70922db61722e3efb6303f665ee7fa7d 100644 --- a/src/App/controller/category/CategoryController.php +++ b/src/controller/category/CategoryController.php @@ -21,13 +21,6 @@ class CategoryController extends Controller{ "pageLimit" => $this->pageLimit ]; - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName, $data); - - $view->render(); + $this->render($data); } } \ No newline at end of file diff --git a/src/App/controller/category/DeleteCategoryController.php b/src/controller/category/DeleteCategoryController.php similarity index 100% rename from src/App/controller/category/DeleteCategoryController.php rename to src/controller/category/DeleteCategoryController.php diff --git a/src/App/controller/category/EditCategoryController.php b/src/controller/category/EditCategoryController.php similarity index 100% rename from src/App/controller/category/EditCategoryController.php rename to src/controller/category/EditCategoryController.php diff --git a/src/App/controller/function/arrayPagination.php b/src/controller/function/arrayPagination.php similarity index 100% rename from src/App/controller/function/arrayPagination.php rename to src/controller/function/arrayPagination.php diff --git a/src/App/controller/function/getUserRole.php b/src/controller/function/getUserRole.php similarity index 100% rename from src/App/controller/function/getUserRole.php rename to src/controller/function/getUserRole.php diff --git a/src/App/controller/home/HomeController.php b/src/controller/home/HomeController.php similarity index 86% rename from src/App/controller/home/HomeController.php rename to src/controller/home/HomeController.php index cf7df83cd1eeb1dce0dec9ac1f7a4293d3fe461a..f68fb0ecf68a6af4390755e9a7628dc3d81a9c0f 100644 --- a/src/App/controller/home/HomeController.php +++ b/src/controller/home/HomeController.php @@ -59,13 +59,6 @@ class HomeController extends Controller{ "max-price" => $maxPrice ]; - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName, $data); - - $view->render(); + $this->render($data); } } \ No newline at end of file diff --git a/src/controller/home/NotFoundController.php b/src/controller/home/NotFoundController.php new file mode 100644 index 0000000000000000000000000000000000000000..bf4a3a25f304fd928a6f91530d7e013fc54bbece --- /dev/null +++ b/src/controller/home/NotFoundController.php @@ -0,0 +1,7 @@ +<?php + +class NotFoundController extends Controller{ + public function index() { + $this->render(); + } +} \ No newline at end of file diff --git a/src/App/controller/login/LoginController.php b/src/controller/login/LoginController.php similarity index 58% rename from src/App/controller/login/LoginController.php rename to src/controller/login/LoginController.php index a97677a180d35b05b7d590e53aeba6fdce7019d5..3e1a25937fa7fcf901029045227189a6ee1d66f2 100644 --- a/src/App/controller/login/LoginController.php +++ b/src/controller/login/LoginController.php @@ -7,14 +7,7 @@ class LoginController extends Controller{ exit(); } - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName); - - $view->render(); + $this->render(); } public function post() { diff --git a/src/controller/login/LogoutController.php b/src/controller/login/LogoutController.php new file mode 100644 index 0000000000000000000000000000000000000000..f758634f7a6832b30fdc84947ba5bd0f22d48f52 --- /dev/null +++ b/src/controller/login/LogoutController.php @@ -0,0 +1,11 @@ +<?php + +class LogoutController extends Controller{ + public function index() { + if($this->userRole === 0) { + throw new Exception("You are not allowed to view this page", 405); + } + + $this->render(); + } +} \ No newline at end of file diff --git a/src/App/controller/login/RegisterController.php b/src/controller/login/RegisterController.php similarity index 66% rename from src/App/controller/login/RegisterController.php rename to src/controller/login/RegisterController.php index 864670e1c5eebb137e95a870083a291745c5ec29..1337379ca9117146c92e2e3b1c04eca6da13e84c 100644 --- a/src/App/controller/login/RegisterController.php +++ b/src/controller/login/RegisterController.php @@ -7,14 +7,7 @@ class RegisterController extends Controller{ exit(); } - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName); - - $view->render(); + $this->render(); } public function post() { diff --git a/src/App/controller/product/AddProductController.php b/src/controller/product/AddProductController.php similarity index 89% rename from src/App/controller/product/AddProductController.php rename to src/controller/product/AddProductController.php index 9fdbede3530c066ec4b86c088dd733b13cec245f..e5312a9a263d6c81046e908764566f4bb0158227 100644 --- a/src/App/controller/product/AddProductController.php +++ b/src/controller/product/AddProductController.php @@ -13,15 +13,7 @@ class AddProductController extends Controller{ $data = $categoryModel->getCategory()->fetch_all(); - // print_r($data); - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName, $data); - - $view->render(); + $this->render($data); } public function post(){ @@ -41,11 +33,6 @@ class AddProductController extends Controller{ $pict_temp = $_FILES["product_image"]["tmp_name"]; $pict_size = $_FILES["product_image"]["size"]; $pict_error = $_FILES["product_image"]["error"]; - - // echo "a".$pict_name; - // echo "a".$pict_temp; - // echo "a".$pict_size; - // echo "a".$pict_error; $vid_name = $_FILES["product_video"]["name"]; $vid_temp = $_FILES["product_video"]["tmp_name"]; @@ -63,9 +50,9 @@ class AddProductController extends Controller{ } if (in_array($pict_extension, $allowed_extensions) ) { if ($pict_error === 0) { - $uploadPict_directory = __DIR__ . "/../../public/storage/image/"; + $uploadPict_directory = __DIR__ . "/../../storage/image/"; - $uploadVid_directory = __DIR__ . "/../../public/storage/video/"; + $uploadVid_directory = __DIR__ . "/../../storage/video/"; if (!is_dir($uploadPict_directory)) { mkdir($uploadPict_directory, 0755, true); @@ -118,7 +105,7 @@ class AddProductController extends Controller{ } if($pict_error === 4){ - $uploadVid_directory = __DIR__ . "/../../public/storage/video/"; + $uploadVid_directory = __DIR__ . "/../../storage/video/"; if (!is_dir($uploadVid_directory)) { mkdir($uploadVid_directory, 0755, true); diff --git a/src/App/controller/product/DeleteProductController.php b/src/controller/product/DeleteProductController.php similarity index 100% rename from src/App/controller/product/DeleteProductController.php rename to src/controller/product/DeleteProductController.php diff --git a/src/App/controller/product/EditProductController.php b/src/controller/product/EditProductController.php similarity index 91% rename from src/App/controller/product/EditProductController.php rename to src/controller/product/EditProductController.php index 1626fb32b101a543914e53975d798212eadcbc9a..d032d4f88a3e0439c234566cf31039a7ae9b3c04 100644 --- a/src/App/controller/product/EditProductController.php +++ b/src/controller/product/EditProductController.php @@ -28,14 +28,7 @@ class EditProductController extends Controller{ 'productFile' => $product_file ]; - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName, $data); - - $view->render(); + $this->render($data); } public function post($id){ @@ -67,7 +60,7 @@ class EditProductController extends Controller{ if($pict_error === 0){ $pict_extension = strtolower(pathinfo($pict_name, PATHINFO_EXTENSION)); if(in_array($pict_extension, $allowed_extensions)){ - $uploadPict_directory = __DIR__ . "/../../public/storage/image/"; + $uploadPict_directory = __DIR__ . "/../../storage/image/"; if (!is_dir($uploadPict_directory)) { mkdir($uploadPict_directory, 0755, true); @@ -97,7 +90,7 @@ class EditProductController extends Controller{ if($vid_error === 0){ $vid_extension = strtolower(pathinfo($vid_name, PATHINFO_EXTENSION)); if(in_array($vid_extension, $allowed_extensions)){ - $uploadVid_directory = __DIR__ . "/../../public/storage/video/"; + $uploadVid_directory = __DIR__ . "/../../storage/video/"; if (!is_dir($uploadVid_directory)) { mkdir($uploadVid_directory, 0755, true); diff --git a/src/App/controller/product/ProductController.php b/src/controller/product/ProductController.php similarity index 72% rename from src/App/controller/product/ProductController.php rename to src/controller/product/ProductController.php index 748453e0e98477062d0e917ba4cfec326a2d130e..3454b17a403cd29b4286190089a66a63415d4fd3 100644 --- a/src/App/controller/product/ProductController.php +++ b/src/controller/product/ProductController.php @@ -24,13 +24,6 @@ class ProductController extends Controller{ 'productFile' => $productFile ]; - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName, $data); - - $view->render(); + $this->render($data); } } \ No newline at end of file diff --git a/src/App/controller/profile/EditProfileController.php b/src/controller/profile/EditProfileController.php similarity index 65% rename from src/App/controller/profile/EditProfileController.php rename to src/controller/profile/EditProfileController.php index e27fec2bfa19687359d0e686ea34ae84aa2a53cc..54ff6c13559a17c78d93ae5094fa8e8bcbfc8b36 100644 --- a/src/App/controller/profile/EditProfileController.php +++ b/src/controller/profile/EditProfileController.php @@ -8,20 +8,9 @@ class EditProfileController extends Controller { $userModel = $this->model("UserModel"); - $data = []; + $data = $userModel->getCurrentUser(); - if (isset($_SESSION['user_id'])) { - $data = $userModel->getCurrentUser(); - } - - $dir = __DIR__; - $dir = explode("/", $dir); - $folderName = end($dir); - $className = get_class(); - $fileName = str_replace('Controller', '', $className); - $view = $this->view($folderName, $fileName, $data); - - $view->render(); + $this->render($data); } public function post() { diff --git a/src/controller/profile/ProfileController.php b/src/controller/profile/ProfileController.php new file mode 100644 index 0000000000000000000000000000000000000000..b103d6d135980ff08f1fd0bf4fc4b980074be928 --- /dev/null +++ b/src/controller/profile/ProfileController.php @@ -0,0 +1,18 @@ +<?php + +class ProfileController extends Controller +{ + public function index() + { + if($this->userRole === 0) { + header("Location: /login"); + exit(); + } + + $userModel = $this->model("UserModel"); + + $data = $userModel->getCurrentUser(); + + $this->render($data); + } +} diff --git a/src/App/database.php b/src/database.php similarity index 88% rename from src/App/database.php rename to src/database.php index 51dd758d563265704bf60d3b62b2e28123d0d367..ad464331d9c4dbf9a36371d77099433e129f7de7 100644 --- a/src/App/database.php +++ b/src/database.php @@ -66,14 +66,4 @@ class Database{ public function getConn(){ return $this->conn; } - function bindParameters(mysqli_stmt $stmt, $types, ...$values) { - $bindParams = []; - $bindParams[] = $types; - - foreach ($values as &$value) { - $bindParams[] = &$value; - } - - return call_user_func_array([$stmt, 'bind_param'], $bindParams); - } } \ No newline at end of file diff --git a/src/App/index.php b/src/index.php similarity index 100% rename from src/App/index.php rename to src/index.php diff --git a/src/App/models/CartModel.php b/src/models/CartModel.php similarity index 100% rename from src/App/models/CartModel.php rename to src/models/CartModel.php diff --git a/src/App/models/CategoryModel.php b/src/models/CategoryModel.php similarity index 100% rename from src/App/models/CategoryModel.php rename to src/models/CategoryModel.php diff --git a/src/App/models/Model.php b/src/models/Model.php similarity index 100% rename from src/App/models/Model.php rename to src/models/Model.php diff --git a/src/App/models/ProductFileModel.php b/src/models/ProductFileModel.php similarity index 100% rename from src/App/models/ProductFileModel.php rename to src/models/ProductFileModel.php diff --git a/src/App/models/ProductModel.php b/src/models/ProductModel.php similarity index 100% rename from src/App/models/ProductModel.php rename to src/models/ProductModel.php diff --git a/src/App/models/UserModel.php b/src/models/UserModel.php similarity index 100% rename from src/App/models/UserModel.php rename to src/models/UserModel.php diff --git a/src/App/public/scripts/Cart/cart.js b/src/scripts/cart/cart.js similarity index 100% rename from src/App/public/scripts/Cart/cart.js rename to src/scripts/cart/cart.js diff --git a/src/App/public/scripts/Category/category.js b/src/scripts/category/category.js similarity index 100% rename from src/App/public/scripts/Category/category.js rename to src/scripts/category/category.js diff --git a/src/App/public/scripts/functions/debounce.js b/src/scripts/functions/debounce.js similarity index 100% rename from src/App/public/scripts/functions/debounce.js rename to src/scripts/functions/debounce.js diff --git a/src/App/public/scripts/home/paginateForm.js b/src/scripts/home/paginateForm.js similarity index 100% rename from src/App/public/scripts/home/paginateForm.js rename to src/scripts/home/paginateForm.js diff --git a/src/App/public/scripts/home/search.js b/src/scripts/home/search.js similarity index 100% rename from src/App/public/scripts/home/search.js rename to src/scripts/home/search.js diff --git a/src/App/public/scripts/popup.js b/src/scripts/popup.js similarity index 100% rename from src/App/public/scripts/popup.js rename to src/scripts/popup.js diff --git a/src/App/public/storage/image/default.jpg b/src/storage/image/default.jpg similarity index 100% rename from src/App/public/storage/image/default.jpg rename to src/storage/image/default.jpg diff --git a/src/App/public/styles/Global.css b/src/styles/Global.css similarity index 100% rename from src/App/public/styles/Global.css rename to src/styles/Global.css diff --git a/src/App/public/styles/cart/Cart.css b/src/styles/cart/Cart.css similarity index 100% rename from src/App/public/styles/cart/Cart.css rename to src/styles/cart/Cart.css diff --git a/src/App/public/styles/category/addCategory.css b/src/styles/category/AddCategory.css similarity index 100% rename from src/App/public/styles/category/addCategory.css rename to src/styles/category/AddCategory.css diff --git a/src/App/public/styles/category/category.css b/src/styles/category/Category.css similarity index 100% rename from src/App/public/styles/category/category.css rename to src/styles/category/Category.css diff --git a/src/App/public/styles/home/Home.css b/src/styles/home/Home.css similarity index 100% rename from src/App/public/styles/home/Home.css rename to src/styles/home/Home.css diff --git a/src/App/public/styles/login/Login.css b/src/styles/login/Login.css similarity index 100% rename from src/App/public/styles/login/Login.css rename to src/styles/login/Login.css diff --git a/src/App/public/styles/product/addProduct.css b/src/styles/product/AddProduct.css similarity index 100% rename from src/App/public/styles/product/addProduct.css rename to src/styles/product/AddProduct.css diff --git a/src/App/public/styles/product/product.css b/src/styles/product/Product.css similarity index 100% rename from src/App/public/styles/product/product.css rename to src/styles/product/Product.css diff --git a/src/App/public/styles/product/ProductCard.css b/src/styles/product/ProductCard.css similarity index 100% rename from src/App/public/styles/product/ProductCard.css rename to src/styles/product/ProductCard.css diff --git a/src/App/public/styles/profile/Profile.css b/src/styles/profile/Profile.css similarity index 100% rename from src/App/public/styles/profile/Profile.css rename to src/styles/profile/Profile.css diff --git a/src/App/public/styles/template/Navbar.css b/src/styles/template/Navbar.css similarity index 100% rename from src/App/public/styles/template/Navbar.css rename to src/styles/template/Navbar.css diff --git a/src/App/views/Routes.php b/src/views/Routes.php similarity index 100% rename from src/App/views/Routes.php rename to src/views/Routes.php diff --git a/src/App/views/Routing.php b/src/views/Routing.php similarity index 100% rename from src/App/views/Routing.php rename to src/views/Routing.php diff --git a/src/App/views/View.php b/src/views/View.php similarity index 100% rename from src/App/views/View.php rename to src/views/View.php