Skip to content
Snippets Groups Projects
Commit ed85f517 authored by csauder's avatar csauder
Browse files

intialisation d'un magnifique projet

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 902 additions and 0 deletions
.idea/
.idea_modules/
### OSX ###
.DS_Store
.AppleDouble
.LSOverride
### Composer ###
composer.phar
vendor/
### Linux ###
*~
### Database ###
config/config.ini
config/db.ini
composer.lock
\ No newline at end of file
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
\ No newline at end of file
File added
File added
## Racoin
TODO: readme
\ No newline at end of file
-- phpMyAdmin SQL Dump
-- version 4.0.10deb1
-- http://www.phpmyadmin.net
--
-- Client: localhost
-- Généré le: Mar 03 Février 2015 à 17:46
-- Version du serveur: 5.5.41-0ubuntu0.14.04.1
-- Version de PHP: 5.5.9-1ubuntu4.5
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Base de données: `racoin`
--
-- --------------------------------------------------------
--
-- Structure de la table `apikey`
--
CREATE TABLE IF NOT EXISTS `apikey` (
`id_apikey` varchar(20) NOT NULL,
`name_key` varchar(255) NOT NULL,
PRIMARY KEY (`id_apikey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
bdd.sql 0 → 100644
# Affichage de la table annonce
# ------------------------------------------------------------
DROP TABLE IF EXISTS `annonce`;
CREATE TABLE `annonce` (
`id_annonce` int(11) NOT NULL AUTO_INCREMENT,
`id_categorie` int(11) DEFAULT NULL,
`id_sous_categorie` int(11) DEFAULT NULL,
`id_annonceur` int(11) DEFAULT NULL,
`id_departement` int(11) DEFAULT NULL,
`prix` float DEFAULT NULL,
`date` date DEFAULT NULL,
`titre` varchar(255) DEFAULT NULL,
`description` text,
`ville` varchar(255) DEFAULT NULL,
`mdp` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id_annonce`),
KEY `id_sous_categorie_idxfk` (`id_sous_categorie`),
KEY `id_annonceur_idxfk` (`id_annonceur`),
KEY `id_departement_idxfk` (`id_departement`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
# Affichage de la table annonceur
# ------------------------------------------------------------
DROP TABLE IF EXISTS `annonceur`;
CREATE TABLE `annonceur` (
`id_annonceur` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) DEFAULT NULL,
`nom_annonceur` varchar(255) DEFAULT NULL,
`telephone` varchar(13) DEFAULT NULL,
PRIMARY KEY (`id_annonceur`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
# Affichage de la table categorie
# ------------------------------------------------------------
DROP TABLE IF EXISTS `categorie`;
CREATE TABLE `categorie` (
`id_categorie` int(11) NOT NULL AUTO_INCREMENT,
`nom_categorie` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id_categorie`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
# Affichage de la table departement
# ------------------------------------------------------------
DROP TABLE IF EXISTS `departement`;
CREATE TABLE `departement` (
`id_departement` int(11) NOT NULL AUTO_INCREMENT,
`id_region` int(11) DEFAULT NULL,
`nom_departement` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id_departement`),
KEY `id_region_idxfk` (`id_region`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
# Affichage de la table photo
# ------------------------------------------------------------
DROP TABLE IF EXISTS `photo`;
CREATE TABLE `photo` (
`id_photo` int(11) NOT NULL AUTO_INCREMENT,
`id_annonce` int(11) DEFAULT NULL,
`url_photo` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id_photo`),
KEY `id_annonce_idxfk` (`id_annonce`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
# Affichage de la table region
# ------------------------------------------------------------
DROP TABLE IF EXISTS `region`;
CREATE TABLE `region` (
`id_region` int(11) NOT NULL AUTO_INCREMENT,
`nom_region` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id_region`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
\ No newline at end of file
{
"require": {
"slim/slim": "2.*",
"twig/twig": "~1.0",
"illuminate/database": "4.2.9"
},
"autoload":{
"psr-0":{
"controller":"",
"model":"",
"db":""
}
},
"config": {
"allow-plugins": {
"kylekatarnls/update-helper": true
}
}
}
<?php
namespace controller;
use model\ApiKey;
class KeyGenerator {
function show($twig, $menu, $chemin, $cat) {
$template = $twig->loadTemplate("key-generator.html.twig");
$menu = array(
array('href' => $chemin,
'text' => 'Acceuil'),
array('href' => $chemin."/search",
'text' => "Recherche")
);
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin, "categories" => $cat));
}
function generateKey($twig, $menu, $chemin, $cat, $nom) {
$nospace_nom = str_replace(' ', '', $nom);
if($nospace_nom === '') {
$template = $twig->loadTemplate("key-generator-error.html.twig");
$menu = array(
array('href' => $chemin,
'text' => 'Acceuil'),
array('href' => $chemin."/search",
'text' => "Recherche")
);
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin, "categories" => $cat));
} else {
$template = $twig->loadTemplate("key-generator-result.html.twig");
$menu = array(
array('href' => $chemin,
'text' => 'Acceuil'),
array('href' => $chemin."/search",
'text' => "Recherche")
);
// Génere clé unique de 13 caractères
$key = uniqid();
// Ajouter clé dans la base
$apikey = new ApiKey();
$apikey->id_apikey = $key;
$apikey->name_key = htmlentities($nom);
$apikey->save();
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin, "categories" => $cat, "key" => $key));
}
}
}
?>
\ No newline at end of file
<?php
namespace controller;
use model\Annonce;
use model\Categorie;
class Search {
function show($twig, $menu, $chemin, $cat) {
$template = $twig->loadTemplate("search.html.twig");
$menu = array(
array('href' => $chemin,
'text' => 'Acceuil'),
array('href' => $chemin."/search",
'text' => "Recherche")
);
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin, "categories" => $cat));
}
function research($array, $twig, $menu, $chemin, $cat) {
$template = $twig->loadTemplate("index.html.twig");
$menu = array(
array('href' => $chemin,
'text' => 'Acceuil'),
array('href' => $chemin."/search",
'text' => "Résultats de la recherche")
);
$nospace_mc = str_replace(' ', '', $array['motclef']);
$nospace_cp = str_replace(' ', '', $array['codepostal']);
$query = Annonce::select();
if( ($nospace_mc === "") &&
($nospace_cp === "") &&
(($array['categorie'] === "Toutes catégories" || $array['categorie'] === "-----")) &&
($array['prix-min'] === "Min") &&
( ($array['prix-max'] === "Max") || ($array['prix-max'] === "nolimit") ) ) {
$annonce = Annonce::all();
} else {
// A REFAIRE SEPARER LES TRUCS
if( ($nospace_mc !== "") ) {
$query->where('description', 'like', '%'.$array['motclef'].'%');
}
if( ($nospace_cp !== "") ) {
$query->where('ville', '=', $array['codepostal']);
}
if ( ($array['categorie'] !== "Toutes catégories" && $array['categorie'] !== "-----") ) {
$categ = Categorie::select('id_categorie')->where('id_categorie', '=', $array['categorie'])->first()->id_categorie;
$query->where('id_categorie', '=', $categ);
}
if ( $array['prix-min'] !== "Min" && $array['prix-max'] !== "Max") {
if($array['prix-max'] !== "nolimit") {
$query->whereBetween('prix', array($array['prix-min'], $array['prix-max']));
} else {
$query->where('prix', '>=', $array['prix-min']);
}
} elseif ( $array['prix-max'] !== "Max" && $array['prix-max'] !== "nolimit") {
$query->where('prix', '<=', $array['prix-max']);
} elseif ( $array['prix-min'] !== "Min" ) {
$query->where('prix', '>=', $array['prix-min']);
}
$annonce = $query->get();
}
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin, "annonces" => $annonce, "categories" => $cat));
}
}
?>
\ No newline at end of file
<?php
namespace controller;
use model\Annonce;
use model\Annonceur;
class addItem{
function addItemView($twig, $menu, $chemin, $cat, $dpt){
$template = $twig->loadTemplate("add.html.twig");
echo $template->render(array(
"breadcrumb" => $menu,
"chemin" => $chemin,
"categories" => $cat,
"departements" => $dpt)
);
}
function addNewItem($twig, $menu, $chemin, $allPostVars){
date_default_timezone_set('Europe/Paris');
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email));
}
/*
* On récupère tous les champs du formulaire en supprimant
* les caractères invisibles en début et fin de chaîne.
*/
$nom = trim($_POST['nom']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$ville = trim($_POST['ville']);
$departement = trim($_POST['departement']);
$categorie = trim($_POST['categorie']);
$title = trim($_POST['title']);
$description = trim($_POST['description']);
$price = trim($_POST['price']);
$password = trim($_POST['psw']);
$password_confirm = trim($_POST['confirm-psw']);
// Tableau d'erreurs personnalisées
$errors = array();
$errors['nameAdvertiser'] = '';
$errors['emailAdvertiser'] = '';
$errors['phoneAdvertiser'] = '';
$errors['villeAdvertiser'] = '';
$errors['departmentAdvertiser'] = '';
$errors['categorieAdvertiser'] = '';
$errors['titleAdvertiser'] = '';
$errors['descriptionAdvertiser'] = '';
$errors['priceAdvertiser'] = '';
$errors['passwordAdvertiser'] = '';
// $fileInfos = $_FILES["fichier"];
// $fileName = $fileInfos['name'];
// $type_mime = $fileInfos['type'];
// $taille = $fileInfos['size'];
// $fichier_temporaire = $fileInfos['tmp_name'];
// $code_erreur = $fileInfos['error'];
// switch ($code_erreur){
// case UPLOAD_ERR_OK :
// $destination = "$chemin/upload/$fileName";
//
// if (move_uploaded_file($fichier_temporaire, $destination)){
// $message = "Transfert terminé - Fichier = $nom - ";
// $message .= "Taille = $taille octets - ";
// $message .= "Type MIME = $type_mime";
// } else {
// $message = "Problème de copie sur le serveur";
// }
// break;
// case UPLOAD_ERR_NO_FILE :
// $message = "Pas de fichier saisi";
// break;
// case UPLOAD_ERR_INI_SIZE :
// $message = "Fichier '$fileName' non transféré ";
// $message .= ' (taille > upload_max_filesize.';
// break;
// case UPLOAD_ERR_FORM_SIZE :
// $message = "Fichier '$fileName' non transféré ";
// $message .= ' (taille > MAX_FILE_SIZE.';
// break;
// case UPLOAD_ERR_PARTIAL :
// $message = "Fichier '$fileName' non transféré ";
// $message .= ' (problème lors du transfert';
// break;
// case UPLOAD_ERR_NO_TMP_DIR :
// $message = "Fichier '$fileName' non transféré ";
// $message .= ' (pas de répertoire temporaire).';
// break;
// case UPLOAD_ERR_CANT_WRITE :
// $message = "Fichier '$fileName' non transféré ";
// $message .= ' (erreur lors de l\'écriture du fichier sur disque).';
// break;
// case UPLOAD_ERR_EXTENSION :
// $message = "Fichier '$fileName' non transféré ";
// $message .= ' (transfert stoppé par l\'extension).';
// break;
// default :
// $message = "Fichier '$fileName' non transféré ";
// $message .= ' (erreur inconnue : $code_erreur';
// }
// On teste que les champs ne soient pas vides et soient de bons types
if(empty($nom)) {
$errors['nameAdvertiser'] = 'Veuillez entrer votre nom';
}
if(!isEmail($email)) {
$errors['emailAdvertiser'] = 'Veuillez entrer une adresse mail correcte';
}
if(empty($phone) && !is_numeric($phone) ) {
$errors['phoneAdvertiser'] = 'Veuillez entrer votre numéro de téléphone';
}
if(empty($ville)) {
$errors['villeAdvertiser'] = 'Veuillez entrer votre ville';
}
if(!is_numeric($departement)) {
$errors['departmentAdvertiser'] = 'Veuillez choisir un département';
}
if(!is_numeric($categorie)) {
$errors['categorieAdvertiser'] = 'Veuillez choisir une catégorie';
}
if(empty($title)) {
$errors['titleAdvertiser'] = 'Veuillez entrer un titre';
}
if(empty($description)) {
$errors['descriptionAdvertiser'] = 'Veuillez entrer une description';
}
if(empty($price) || !is_numeric($price)) {
$errors['priceAdvertiser'] = 'Veuillez entrer un prix';
}
if(empty($password) || empty($password_confirm) || $password != $password_confirm) {
$errors['passwordAdvertiser'] = 'Les mots de passes ne sont pas identiques';
}
// On vire les cases vides
$errors = array_values(array_filter($errors));
// S'il y a des erreurs on redirige vers la page d'erreur
if (!empty($errors)) {
$template = $twig->loadTemplate("add-error.html.twig");
echo $template->render(array(
"breadcrumb" => $menu,
"chemin" => $chemin,
"errors" => $errors)
);
}
// sinon on ajoute à la base et on redirige vers une page de succès
else{
$annonce = new Annonce();
$annonceur = new Annonceur();
$annonceur->email = htmlentities($allPostVars['email']);
$annonceur->nom_annonceur = htmlentities($allPostVars['nom']);
$annonceur->telephone = htmlentities($allPostVars['phone']);
$annonce->ville = htmlentities($allPostVars['ville']);
$annonce->id_departement = $allPostVars['departement'];
$annonce->prix = htmlentities($allPostVars['price']);
$annonce->mdp = password_hash ($allPostVars['psw'], PASSWORD_DEFAULT);
$annonce->titre = htmlentities($allPostVars['title']);
$annonce->description = htmlentities($allPostVars['description']);
$annonce->id_categorie = $allPostVars['categorie'];
$annonce->date = date('Y-m-d');
$annonceur->save();
$annonceur->annonce()->save($annonce);
$template = $twig->loadTemplate("add-confirm.html.twig");
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin));
}
}
}
\ No newline at end of file
<?php
namespace controller;
use model\Categorie;
use model\Annonce;
use model\Photo;
use model\Annonceur;
class getCategorie {
protected $categories = array();
public function getCategories() {
return Categorie::orderBy('nom_categorie')->get()->toArray();
}
public function getCategorieContent($chemin, $n) {
$tmp = Annonce::with("Annonceur")->orderBy('id_annonce','desc')->where('id_categorie', "=", $n)->get();
$annonce = [];
foreach($tmp as $t) {
$t->nb_photo = Photo::where("id_annonce", "=", $t->id_annonce)->count();
if($t->nb_photo > 0){
$t->url_photo = Photo::select("url_photo")
->where("id_annonce", "=", $t->id_annonce)
->first()->url_photo;
}else{
$t->url_photo = $chemin.'/img/noimg.png';
}
$t->nom_annonceur = Annonceur::select("nom_annonceur")
->where("id_annonceur", "=", $t->id_annonceur)
->first()->nom_annonceur;
array_push($annonce, $t);
}
$this->annonce = $annonce;
}
public function displayCategorie($twig, $menu, $chemin, $cat, $n) {
$template = $twig->loadTemplate("index.html.twig");
$menu = array(
array('href' => $chemin,
'text' => 'Acceuil'),
array('href' => $chemin."/cat/".$n,
'text' => Categorie::find($n)->nom_categorie)
);
$this->getCategorieContent($chemin, $n);
echo $template->render(array(
"breadcrumb" => $menu,
"chemin" => $chemin,
"categories" => $cat,
"annonces" => $this->annonce));
}
}
\ No newline at end of file
<?php
namespace controller;
use model\Departement;
class getDepartment {
protected $departments = array();
public function getAllDepartments() {
return Departement::orderBy('nom_departement')->get()->toArray();
}
}
\ No newline at end of file
<?php
namespace controller;
use model\Annonce;
use model\Photo;
use model\Annonceur;
class index {
protected $annonce = array();
public function getAll($chemin) {
// foreach (Annonce::with("Annonceur")->orderBy('id_annonce', 'desc')->take(12)->get(array('id_annonce', 'id_annonceur', 'id_sous_categorie', 'id_departement', 'prix', 'date', 'titre', 'ville')) as $a) {
// array_push($this->annonce, $a->toArray());
// }
$tmp = Annonce::with("Annonceur")->orderBy('id_annonce','desc')->take(12)->get();
$annonce = [];
foreach($tmp as $t) {
$t->nb_photo = Photo::where("id_annonce", "=", $t->id_annonce)->count();
if($t->nb_photo > 0){
$t->url_photo = Photo::select("url_photo")
->where("id_annonce", "=", $t->id_annonce)
->first()->url_photo;
}else{
$t->url_photo = $chemin.'/img/noimg.png';
}
$t->nom_annonceur = Annonceur::select("nom_annonceur")
->where("id_annonceur", "=", $t->id_annonceur)
->first()->nom_annonceur;
array_push($annonce, $t);
}
$this->annonce = $annonce;
}
public function displayAllAnnonce($twig, $menu, $chemin, $cat) {
$template = $twig->loadTemplate("index.html.twig");
$menu = array(
array('href' => $chemin,
'text' => 'Acceuil'),
);
$this->getAll($chemin);
echo $template->render(array(
"breadcrumb" => $menu,
"chemin" => $chemin,
"categories" => $cat,
"annonces" => $this->annonce));
}
}
\ No newline at end of file
<?php
namespace controller;
use model\Annonce;
use model\Annonceur;
use model\Departement;
use model\Photo;
use model\Categorie;
class item {
public function __construct(){
}
function afficherItem($twig, $menu, $chemin, $n, $cat) {
$this->annonce = Annonce::find($n);
if(!isset($this->annonce)){
echo "404";
return;
}
$menu = array(
array('href' => $chemin,
'text' => 'Acceuil'),
array('href' => $chemin."/cat/".$n,
'text' => Categorie::find($this->annonce->id_categorie)->nom_categorie),
array('href' => $chemin."/item/".$n,
'text' => $this->annonce->titre)
);
$this->annonceur = Annonceur::find($this->annonce->id_annonceur);
$this->departement = Departement::find($this->annonce->id_departement );
$this->photo = Photo::where('id_annonce', '=', $n)->get();
$template = $twig->loadTemplate("item.html.twig");
echo $template->render(array("breadcrumb" => $menu,
"chemin" => $chemin,
"annonce" => $this->annonce,
"annonceur" => $this->annonceur,
"dep" => $this->departement->nom_departement,
"photo" => $this->photo,
"categories" => $cat));
}
function supprimerItemGet($twig, $menu, $chemin,$n){
$this->annonce = Annonce::find($n);
if(!isset($this->annonce)){
echo "404";
return;
}
$template = $twig->loadTemplate("delGet.html.twig");
echo $template->render(array("breadcrumb" => $menu,
"chemin" => $chemin,
"annonce" => $this->annonce));
}
function supprimerItemPost($twig, $menu, $chemin, $n, $cat){
$this->annonce = Annonce::find($n);
$reponse = false;
if(password_verify($_POST["pass"],$this->annonce->mdp)){
$reponse = true;
photo::where('id_annonce', '=', $n)->delete();
$this->annonce->delete();
}
$template = $twig->loadTemplate("delPost.html.twig");
echo $template->render(array("breadcrumb" => $menu,
"chemin" => $chemin,
"annonce" => $this->annonce,
"pass" => $reponse,
"categories" => $cat));
}
function modifyGet($twig, $menu, $chemin, $id){
$this->annonce = Annonce::find($id);
if(!isset($this->annonce)){
echo "404";
return;
}
$template = $twig->loadTemplate("modifyGet.html.twig");
echo $template->render(array("breadcrumb" => $menu,
"chemin" => $chemin,
"annonce" => $this->annonce));
}
function modifyPost($twig, $menu, $chemin, $n, $cat, $dpt){
$this->annonce = Annonce::find($n);
$this->annonceur = Annonceur::find($this->annonce->id_annonceur);
$this->categItem = Categorie::find($this->annonce->id_categorie)->nom_categorie;
$this->dptItem = Departement::find($this->annonce->id_departement)->nom_departement;
$reponse = false;
if(password_verify($_POST["pass"],$this->annonce->mdp)){
$reponse = true;
}
$template = $twig->loadTemplate("modifyPost.html.twig");
echo $template->render(array("breadcrumb" => $menu,
"chemin" => $chemin,
"annonce" => $this->annonce,
"annonceur" => $this->annonceur,
"pass" => $reponse,
"categories" => $cat,
"departements" => $dpt,
"dptItem" => $this->dptItem,
"categItem" => $this->categItem));
}
function edit($twig, $menu, $chemin, $allPostVars, $id){
date_default_timezone_set('Europe/Paris');
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email));
}
/*
* On récupère tous les champs du formulaire en supprimant
* les caractères invisibles en début et fin de chaîne.
*/
$nom = trim($_POST['nom']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$ville = trim($_POST['ville']);
$departement = trim($_POST['departement']);
$categorie = trim($_POST['categorie']);
$title = trim($_POST['title']);
$description = trim($_POST['description']);
$price = trim($_POST['price']);
// Tableau d'erreurs personnalisées
$errors = array();
$errors['nameAdvertiser'] = '';
$errors['emailAdvertiser'] = '';
$errors['phoneAdvertiser'] = '';
$errors['villeAdvertiser'] = '';
$errors['departmentAdvertiser'] = '';
$errors['categorieAdvertiser'] = '';
$errors['titleAdvertiser'] = '';
$errors['descriptionAdvertiser'] = '';
$errors['priceAdvertiser'] = '';
// On teste que les champs ne soient pas vides et soient de bons types
if(empty($nom)) {
$errors['nameAdvertiser'] = 'Veuillez entrer votre nom';
}
if(!isEmail($email)) {
$errors['emailAdvertiser'] = 'Veuillez entrer une adresse mail correcte';
}
if(empty($phone) && !is_numeric($phone) ) {
$errors['phoneAdvertiser'] = 'Veuillez entrer votre numéro de téléphone';
}
if(empty($ville)) {
$errors['villeAdvertiser'] = 'Veuillez entrer votre ville';
}
if(!is_numeric($departement)) {
$errors['departmentAdvertiser'] = 'Veuillez choisir un département';
}
if(!is_numeric($categorie)) {
$errors['categorieAdvertiser'] = 'Veuillez choisir une catégorie';
}
if(empty($title)) {
$errors['titleAdvertiser'] = 'Veuillez entrer un titre';
}
if(empty($description)) {
$errors['descriptionAdvertiser'] = 'Veuillez entrer une description';
}
if(empty($price) || !is_numeric($price)) {
$errors['priceAdvertiser'] = 'Veuillez entrer un prix';
}
// On vire les cases vides
$errors = array_values(array_filter($errors));
// S'il y a des erreurs on redirige vers la page d'erreur
if (!empty($errors)) {
$template = $twig->loadTemplate("add-error.html.twig");
echo $template->render(array(
"breadcrumb" => $menu,
"chemin" => $chemin,
"errors" => $errors)
);
}
// sinon on ajoute à la base et on redirige vers une page de succès
else{
$this->annonce = Annonce::find($id);
$idannonceur = $this->annonce->id_annonceur;
$this->annonceur = Annonceur::find($idannonceur);
$this->annonceur->email = htmlentities($allPostVars['email']);
$this->annonceur->nom_annonceur = htmlentities($allPostVars['nom']);
$this->annonceur->telephone = htmlentities($allPostVars['phone']);
$this->annonce->ville = htmlentities($allPostVars['ville']);
$this->annonce->id_departement = $allPostVars['departement'];
$this->annonce->prix = htmlentities($allPostVars['price']);
$this->annonce->mdp = password_hash ($allPostVars['psw'], PASSWORD_DEFAULT);
$this->annonce->titre = htmlentities($allPostVars['title']);
$this->annonce->description = htmlentities($allPostVars['description']);
$this->annonce->id_categorie = $allPostVars['categorie'];
$this->annonce->date = date('Y-m-d');
$this->annonceur->save();
$this->annonceur->annonce()->save($this->annonce);
$template = $twig->loadTemplate("modif-confirm.html.twig");
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin));
}
}
}
<?php
/**
* Created by PhpStorm.
* User: ponicorn
* Date: 26/01/15
* Time: 00:25
*/
namespace controller;
use model\Annonce;
use model\Annonceur;
use model\Photo;
class viewAnnonceur {
public function __construct(){
}
function afficherAnnonceur($twig, $menu, $chemin, $n, $cat) {
$this->annonceur = annonceur::find($n);
if(!isset($this->annonceur)){
echo "404";
return;
}
$tmp = annonce::where('id_annonceur','=',$n)->get();
$annonces = [];
foreach ($tmp as $a) {
$a->nb_photo = Photo::where('id_annonce', '=', $a->id_annonce)->count();
if($a->nb_photo>0){
$a->url_photo = Photo::select('url_photo')
->where('id_annonce', '=', $a->id_annonce)
->first()->url_photo;
}else{
$a->url_photo = $chemin.'/img/noimg.png';
}
$annonces[] = $a;
}
$template = $twig->loadTemplate("annonceur.html.twig");
echo $template->render(array('nom' => $this->annonceur,
"chemin" => $chemin,
"annonces" => $annonces,
"categories" => $cat));
}
}
\ No newline at end of file
<?php
namespace db;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
class connection {
public static function createConn() {
$capsule = new DB;
$capsule->addConnection(parse_ini_file("./config/config.ini"));
$capsule->setAsGlobal();
$capsule->bootEloquent();
}
}
\ No newline at end of file
File added
img/EOS_5D_Mark_III_Default_tcm79-932815.jpg

49.7 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment