diff --git a/.gitignore b/.gitignore index 03c4c38..9a5ad6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ config/config.php +config/conf.php .idea /public/uploads /tmp diff --git a/config/conf.php b/config/conf.php index 32e0b2d..b8c7df8 100644 --- a/config/conf.php +++ b/config/conf.php @@ -1,5 +1,7 @@ prepare($req_search); - //$antenne_id = $stmt->execute($params1); - // Récupération des informations du formulaire $params = array(); $params['name'] = $params['slug'] = $_POST['produit']; @@ -25,8 +19,6 @@ ini_set('display_errors', 0); $params['content'] = ''; // Insertion dans la base - /*$requete = "INSERT INTO products(name, user_id, quantite, prix, created_at, antenne_id) - VALUES(':nom_produit', ':vendeur', ':quantite', :prix, ':created_at', ':antenne_id')";*/ $fields = array_keys($params); $values = join(', ', array_map(function ($field) { diff --git a/public/ajax/addRecord2.php b/public/ajax/addRecord2.php index 88deb2a..5e886d9 100644 --- a/public/ajax/addRecord2.php +++ b/public/ajax/addRecord2.php @@ -11,12 +11,7 @@ $cle_pub_r = $_POST['cle_pub_r']; $prix_r = $_POST['prix_r']; - $query = "INSERT INTO recherches(produit, vendeur, cle_pub, prix) VALUES('$produit_r', '$vendeur_r', '$cle_pub_r', $prix_r)"; - //echo "Query = ".$query."////"; - //exit; - if (!$result = mysqli_query($db,$query)) { - exit(mysqli_connect_error()); - } - echo "1 enregistrement ajouté !"; + $query = "INSERT INTO souhaits(produit, vendeur, cle_pub, prix) VALUES('$produit_r', '$vendeur_r', '$cle_pub_r', $prix_r)"; + } ?> diff --git a/public/ajax/readRecherchesDetails.php b/public/ajax/readRecherchesDetails.php index a9f1d4e..e5358cf 100644 --- a/public/ajax/readRecherchesDetails.php +++ b/public/ajax/readRecherchesDetails.php @@ -1,34 +1,32 @@ 0) { - while ($row = mysqli_fetch_assoc($result)) { - $response = $row; - } - } - else - { +try { + + $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password); + if (isset($_POST['id_r']) && isset($_POST['id_r']) != "") { + + $souhait_id = $_POST['id_r']; + $params["souhait_id"] = $souhait_id; + + $requete = "SELECT souhaits.*, users.username + FROM souhaits + LEFT JOIN users + ON users.id = souhaits.user_id + WHERE souhaits.id = :souhait_id"; + $query = $bdd->prepare($requete); + $query->execute($params); + $results = array(); + while ($row = $query->fetch(PDO::FETCH_ASSOC)) { + $results = $row; + }; + echo json_encode($results); + } else { $response['status'] = 200; - $response['message'] = "Data not found!"; + $response['message'] = "Invalid Request!"; } - // display JSON data - echo json_encode($response); -} -else -{ - $response['status'] = 200; - $response['message'] = "Invalid Request!"; +} catch (PDOException $e) { + echo "Erreur : " . $e->getMessage() . "
"; } + diff --git a/public/ajax/readRecords2.php b/public/ajax/readRecords2.php index e6503ce..45f48a9 100644 --- a/public/ajax/readRecords2.php +++ b/public/ajax/readRecords2.php @@ -1,54 +1,94 @@ +$bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password); + +// Design initial table header +$data = ' - + + - - - + + + '; - $query = "SELECT * FROM recherches"; +$params["antenne_slug"] = $antenne_slug; - if (!$result = mysqli_query($db,$query)) { - exit(mysqli_connect_error()); - } +$requete = "SELECT souhaits.*, users.username + FROM souhaits + LEFT JOIN antennes + ON antennes.id = souhaits.antenne_id + LEFT JOIN users + ON users.id = souhaits.user_id + WHERE antennes.slug = :antenne_slug"; +$stmt = $bdd->prepare($requete); +$stmt->execute($params); +$count = $stmt->rowCount(); - // if query results contains rows then fetch those rows - if(mysqli_num_rows($result) > 0) - { - $number = 1; - while($row = mysqli_fetch_assoc($result)) - { - $data .= ' - - - - - - - - '; - $number++; - } - } - else - { - // records now found - $data .= ""; - } +if ($count > 0) +{ + $number = 1; + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $data .= '
No.Bien ou service recherchéBien/service recherchéPhoto Acheteur Clé publiquePrix en junesMise à jourSuppressionQuantitéPrix en Ğ1Actions
'.$number.''.$row['produit'].''.$row['vendeur'].''.$row['cle_pub'].''.$row['prix'].' - - - -
Pas d'enregistrement
'; + $data .= " + $number"; - echo $data; + $data .= ''.$row['name'].''; + $data .= ''; + $data .= ''.$row['username'].''; + $data .= ''; + $data .= ''.$row['quantite'].''; + $data .= ''.$row['prix'].''; + $data .= ''; + $data .= ' + + + + + '; + $number++; + } + } + else + { + // records now found + $data .= "Pas d'enregistrement"; + } + + $data .= ''; + + echo $data; +?> diff --git a/public/ajax/updateRecherchesDetails.php b/public/ajax/updateRecherchesDetails.php index a937ba2..3b2dd61 100644 --- a/public/ajax/updateRecherchesDetails.php +++ b/public/ajax/updateRecherchesDetails.php @@ -1,20 +1,19 @@ prepare($requete); + $query->execute($params); } diff --git a/public/css/style.css b/public/css/style.css index 4767eb5..47952b5 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -43,8 +43,8 @@ li { background-attachment:fixed; background-position: center; background-size: 100% auto; - font-family: Bree serif,"Helvetica Neue", Helvetica, Arial, sans-serif; - font-size: 18px; + font-family: Bree Serif, Arial, sans-serif; + font-size: 14px; } header.header { width: 389px; @@ -92,9 +92,9 @@ header.header img { font-size: 24px; } .container { - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + font-family: Arial, sans-serif; } -.records_content th { +.records_content th, .records_content2 th { background-color: lightgray; color: rgba(0,0,0,0.85); } diff --git a/public/js/script.js b/public/js/script.js index 066fa22..b379aa1 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -52,7 +52,7 @@ function addRecord2() { prix_r: prix_r }, function (data, status) { // close the popup - $("#add_new_record_modal2").modal("hide"); + $("#add_new_record_modal").modal("hide"); // read records again readRecords2(); @@ -76,8 +76,11 @@ function readRecords(antenne_slug, nom_connecte) { }); } // READ records2 -function readRecords2() { - $.get("ajax/readRecords2.php", {}, function (data, status) { +function readRecords2(antenne_slug, nom_connecte) { + $.get("/ajax/readRecords2.php", { + antenne_slug: antenne_slug, + nom_connecte: nom_connecte + }, function (data, status) { $(".records_content2").html(data); }); } @@ -104,12 +107,12 @@ function DeleteProduits(id, antenne_slug, nom_image) { function DeleteRecherches(id) { var conf = confirm("Etes-vous sûr(e) de vouloir supprimer ce bien ou service ?"); if (conf == true) { - $.post("ajax/deleteRecherches.php", { + $.post("/ajax/deleteRecherches.php", { id_r: id }, function (data, status) { // reload Recherches by using readRecords2(); - readRecords2(); + readRecords2(antenne_slug, nom_connecte); } ); } @@ -138,7 +141,7 @@ function GetProduitsDetails(id, antenne_slug, nom_image) { function GetRecherchesDetails(id) { // Champ caché de l'id $("#hidden_user_id_r").val(id); - $.post("ajax/readRecherchesDetails.php", { + $.post("/ajax/readRecherchesDetails.php", { id_r: id }, function (data, status) { @@ -152,7 +155,7 @@ function GetRecherchesDetails(id) { } ); // Ouverture de la fenêtre modale - $("#update_user_modal2").modal("show"); + $("#update_user_modal").modal("show"); } function UpdateProduitsDetails(nom_connecte) { @@ -191,7 +194,7 @@ function UpdateRecherchesDetails() { var id = $("#hidden_user_id_r").val(); // Update the details by requesting to the server using ajax - $.post("ajax/updateRecherchesDetails.php", { + $.post("/ajax/updateRecherchesDetails.php", { id_r: id, produit_r: produit, image_r: image, @@ -201,9 +204,9 @@ function UpdateRecherchesDetails() { }, function (data, status) { // hide modal popup - $("#update_user_modal2").modal("hide"); + $("#update_user_modal").modal("hide"); // reload Recherches by using readRecords2(); - readRecords2(); + readRecords2(antenne_slug, nom_connecte); } ); } @@ -212,11 +215,16 @@ $(document).ready(function () { // On récupère le nom de l'antenne dans l'url pour afficher les biens/services de celle-ci var url = document.location.href; var antenne_slug = url.split('/')[5]; + var affichage_slug = url.split('/')[6]; + var nom_connecte = $("#nom_connecte").text(); $("#hidden_antenne_slug").val(antenne_slug); // READ records on page load - readRecords(antenne_slug, nom_connecte); - //readRecords2(); + if (affichage_slug == 'produits') { + readRecords(antenne_slug, nom_connecte); + } else { + readRecords2(antenne_slug, nom_connecte); + } $('#add_image').change(function(){ var fd_add = new FormData(); diff --git a/src/Framework/Middleware/NotFoundMiddleware.php b/src/Framework/Middleware/NotFoundMiddleware.php index 0d92466..125d19b 100644 --- a/src/Framework/Middleware/NotFoundMiddleware.php +++ b/src/Framework/Middleware/NotFoundMiddleware.php @@ -11,10 +11,10 @@ class NotFoundMiddleware { return new Response(404, [], '
+ background:url(\'/images/bildreich_1275.jpg\') no-repeat;background-size: cover;">
-

Erreur 404


Cette url n\'existe pas.

- +

Erreur 404


Cette url n\'existe pas.

+
Retour à l\'accueil
'); } } \ No newline at end of file diff --git a/src/Framework/Router.php b/src/Framework/Router.php index dfd6ce7..d751812 100644 --- a/src/Framework/Router.php +++ b/src/Framework/Router.php @@ -20,8 +20,8 @@ class Router public function __construct(?string $cache = null) { $this->router = new FastRouteRouter(null, null, [ - // FastRouteRouter::CONFIG_CACHE_ENABLED => !is_null($cache), - // FastRouteRouter::CONFIG_CACHE_FILE => $cache + //FastRouteRouter::CONFIG_CACHE_ENABLED => !is_null($cache), + //FastRouteRouter::CONFIG_CACHE_FILE => $cache ]); } @@ -99,10 +99,6 @@ class Router */ public function match(ServerRequestInterface $request): ?Route { - //echo "
request = "; - //echo "
"; - //var_dump($request); - //die(); $result = $this->router->match($request); if ($result->isSuccess()) { return new Route( diff --git a/src/Product/Actions/RechIndexAction.php b/src/Product/Actions/RechIndexAction.php new file mode 100644 index 0000000..8cf48d5 --- /dev/null +++ b/src/Product/Actions/RechIndexAction.php @@ -0,0 +1,61 @@ +renderer = $renderer; + $this->rechTable = $rechTable; + $this->antenneTable = $antenneTable; + $this->regionTable = $regionTable; + $this->container = $container; + } + + public function __invoke(Request $request) + { + $params = $request->getQueryParams(); + $gmarchePrefix = $this->container->get('gmarche.prefix'); + $antenne_slug =$request->getAttribute('slug'); + $region_slug =$request->getAttribute('region'); + + $requete = $this->antenneTable->findBy('slug', $antenne_slug); + $antenne_name = $requete->name; + $antenne_id = $requete->id; + $requete_region = $this->regionTable->findBy('slug', $region_slug); + $region_name = $requete_region->name; + $page = $params['p'] ?? 1; + //$routePrefix = 'product.admin'; + //$routePrefix = 'product.index'; + $viewPath = '@product/admin/recherches'; + $items = $this->rechTable->findByAntenneId('antenne_id', $antenne_id)->paginate(20, $page); + + return $this->renderer->render($viewPath.'/index', compact('antenne_slug','gmarchePrefix','region_name','region_slug','antenne_id','antenne_name','viewPath', 'items' )); + } +} diff --git a/src/Product/Entity/Rech.php b/src/Product/Entity/Rech.php new file mode 100644 index 0000000..f5f9d37 --- /dev/null +++ b/src/Product/Entity/Rech.php @@ -0,0 +1,110 @@ +userId; + } + + /** + * @param mixed $userId + */ + public function setUserId(int $userId) + { + $this->userId = $userId; + } + + + public function getAntenneId(): ?int + { + return $this->antenneId; + } + + public function setAntenneId(int $antenneId): void + { + $this->antenneId = $antenneId; + } + + /** + * @return \DateTime|null + */ + public function getCreatedAt(): ?\DateTime + { + return $this->createdAt; + } + + public function setCreatedAt($datetime) + { + if (is_string($datetime)) { + $this->createdAt = new \DateTime($datetime); + } else { + $this->createdAt = $datetime; + } + } + + public function setUpdatedAt($datetime) + { + if (is_string($datetime)) { + $this->updatedAt = new \DateTime($datetime); + } else { + $this->updatedAt = $datetime; + } + } + + public function setSoldAt($datetime) + { + if (is_string($datetime)) { + $this->soldAt = new \DateTime($datetime); + } else { + $this->soldAt = $datetime; + } + } + + public function getThumb() + { + ['filename' => $filename, 'extension' => $extension] = pathinfo($this->image); + return '/uploads/recherches/' . $filename . '_thumb.' . $extension; + } + + public function getImageUrl() + { + return '/uploads/recherches/' . $this->image; + } +} diff --git a/src/Product/ProductModule.php b/src/Product/ProductModule.php index e9e0209..010edab 100644 --- a/src/Product/ProductModule.php +++ b/src/Product/ProductModule.php @@ -1,16 +1,11 @@ get(RendererInterface::class)->addPath('product', __DIR__ . '/views'); $router = $container->get(Router::class); - //$router->get("$gmarchePrefix/{region:[a-z\-0-9]+}/{antenne:[a-z\-0-9]+}", ProductIndexAction::class, 'product.index'); - //$router->get("$gmarchePrefix/{region:[a-z\-]+}/{slug:[a-z\-]+}", ProductIndexAction::class, 'product.ville'); - $router->get("/france/{region:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}/produits", ProductIndexAction::class, 'product.ville'); - // comb $router->get("$gmarchePrefix/{region:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}/produits", new CombinedMiddleware($container, [ProductIndexAction::class]), 'product.ville'); - - // $router->get("$gmarchePrefix/{region:[a-z\-0-9]+}/{antenne:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}", ProductIndexAction::class, 'product.admin'); - - // $router->crud("$gmarchePrefix/{region:[a-z\-]+}/{slug:[a-z\-0-9]+}/{antenne:[0-9]{1,}}",[LoggedInMiddleware::class, ProductCrudAction::class],'product.admin'); + $router->get("$gmarchePrefix/{region:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}/produits", ProductIndexAction::class, 'product.ville'); + $router->get("$gmarchePrefix/{region:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}/recherches", RechIndexAction::class, 'product.recherches'); + // $router->crud("$gmarchePrefix/{region:[a-z\-]+}/{slug:[a-z\-0-9]+}/{antenne:[0-9]{1,}}",[LoggedInMiddleware::class, ProductCrudAction::class],'product.admin'); } } // $router->get("$gmarchePrefix/{region:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}/{antenne:[0-9]{1,}}", ProductIndexAction::class, 'product.index'); diff --git a/src/Product/Table/RechTable.php b/src/Product/Table/RechTable.php new file mode 100644 index 0000000..46db35c --- /dev/null +++ b/src/Product/Table/RechTable.php @@ -0,0 +1,45 @@ +pdo); + $antenne = new AntenneTable($this->pdo); + $region = new RegionTable($this->pdo); + return $this->makeQuery() + ->join($user->getTable().' as u' , 'u.id = rech.user_id') + ->join($antenne->getTable().' as a' , 'a.id = rech.antenne_id') + ->join($region->getTable().' as reg' , 'reg.id = a.region_id') + ->select('rech.*, u.username, a.name as antenne_name, reg.name as region_name' ) + ->order('rech.created_at DESC'); + } + + public function findByAntenneId($field, $value): Query + { + $user = new UserTable($this->pdo); + $antenne = new AntenneTable($this->pdo); + $region = new RegionTable($this->pdo); + return $this->makeQuery() + ->join($user->getTable().' as u' , 'u.id = rech.user_id') + ->join($antenne->getTable().' as a' , 'a.id = rech.antenne_id') + ->join($region->getTable().' as reg' , 'reg.id = rech.region_id') + ->select('rech.*, u.username, a.name as antenne_name, reg.name as region_name' ) + ->where("$field = $value" ) + ->order('rech.created_at DESC'); + } +} diff --git a/src/Product/views/admin/products/index.twig b/src/Product/views/admin/products/index.twig index e5f0654..20fbea8 100644 --- a/src/Product/views/admin/products/index.twig +++ b/src/Product/views/admin/products/index.twig @@ -53,7 +53,6 @@ } .toggle_radio input[type=radio]{ display: none; - /*position: fixed;*/ } .toggle_radio label{ /* font: 90%/1.618 "Source Sans Pro";*/ @@ -66,10 +65,7 @@ border-radius: 50px; cursor: pointer; z-index: 1; - /*background: rgba(0,0,0,.1);*/ text-align: center; - /*margin: 0 2px;*/ - /*background: blue;*/ /*make it blue*/ } .toggle_option_slider{ width: 100px; @@ -91,191 +87,191 @@ - - -
- - {% if antenne_name == 'Paris' %} - - {% endif %} -
- -
-
-
- Tous les mois, la Toile Francilienne organise des rencontres entre utilisateurs de la Monnaie Libre. - C'est l'occasion rêvée d'échanger avec d'autres membres ! - {{ annonce_ligne1 }} - {{ annonce_ligne2 }} - {{ annonce_ligne3 }} -

- Consultez, rajoutez, modifiez vos propositions dans la liste du mois. - Mettez bien le pseudo, la clé publique, le bien ou service, et le prix en june. -
-

- {% if current_user() %} - -

- -
-
-
-
- - -
-