function routeRequest() { if (isset($_SESSION['LAST_ACTIVITY']) && time() - $_SESSION['LAST_ACTIVITY'] > 1800) { // last request was more than 30 minutes ago session_unset(); // unset $_SESSION variable for the run-time session_destroy(); // destroy session data in storage } $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp $dbh = Database::connect(); $u = Utilisateur::getUtilisateur($dbh, $_SESSION["id"]); $uri = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '/')); switch ($uri) { case '/': echo file_get_contents('./public/index.html'); echo '<script type="text/babel">' . file_get_contents('./public/scripts/Connexion-Inscription/Connexion.js') . file_get_contents('./public/scripts/Connexion-Inscription/Inscription.js') . file_get_contents('./public/scripts/Connexion-Inscription/EditProfile.js') . file_get_contents('./public/scripts/Affiche/Autobar/Autobar.js') . file_get_contents('./public/scripts/Affiche/Autobar/LieuAutobar.js') . file_get_contents('./public/scripts/Lieu/Lieu.js') . file_get_contents('./public/scripts/Utilisateur/Utilisateur.js') . file_get_contents('./public/scripts/Utilisateur/ListeUtilisateur.js') . file_get_contents('./public/scripts/Affiche/ObjetForm.js') . file_get_contents('./public/scripts/Affiche/Objet.js') . file_get_contents('./public/scripts/Affiche/NavbarObjet.js') . file_get_contents('./public/scripts/Filter/FilterBar.js') . file_get_contents('./public/scripts/Affiche/ListeAffiche.js') . file_get_contents('./public/scripts/Docs/Docs.js') . file_get_contents('./public/scripts/Lieu/Lieu.js') . file_get_contents('./public/scripts/Lieu/NavbarLieu.js') . file_get_contents('./public/scripts/Lieu/LieuForm.js') . file_get_contents('./public/scripts/Lieu/ListeLieu.js') . file_get_contents('./public/scripts/Lieu/LieuMap.js') . file_get_contents('./public/scripts/App/App.js') . '</script>'; break; case '/Connexion': if ($_SERVER['REQUEST_METHOD'] === 'POST') { $u = Utilisateur::seConnecter($dbh, $_POST['identifiant'], $_POST['motdepasse']); if (!is_null($_SESSION["id"])) { echo json_encode(array("result" => json_decode(json_encode($u)))); } else { echo json_encode(array("error" => $u)); } } else { if ($_SERVER['REQUEST_METHOD'] === 'PUT') { if (!is_null($u)) { echo json_encode(array("result" => json_decode(json_encode($u)))); } } } break; case '/Deconnexion': if ($_SERVER['REQUEST_METHOD'] === 'POST') { Utilisateur::seDeconnecter(); } break; case '/Inscription': if ($_SERVER['REQUEST_METHOD'] === 'POST') { echo Helpers::testInscription($dbh); } break; case '/EditProfile': if (!is_null($u) && $_SERVER['REQUEST_METHOD'] === 'POST') { echo Helpers::testUpdate($dbh); } break; case '/ChargerLesObjets': if ($_SERVER['REQUEST_METHOD'] === 'GET') { header('Content-Type: application/json'); $reponse = Objet::chargerLesObjets($dbh); echo json_encode($reponse); } break; case '/AjouterUnObjet': if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!is_null($u)) { $u = $u->ajouterUnObjet($dbh, $_POST["nom"], $_POST["description"], json_decode($_POST["lieux"])); if (is_array($u) && isset($u["error"])) { echo json_encode($u); } else { echo json_encode(array("result" => "success")); } } } break; case '/SupprimerUnObjet': if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!is_null($u)) { $u->supprimerUnObjet($dbh, $_POST["ido"]); } } break; case '/DeclarerAvoirTrouveUnObjet': if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!is_null($u)) { $u->declarerAvoirTrouveUnObjet($dbh, $_POST["ido"]); } } break; case '/RetirerDeclaration': if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!is_null($u)) { $u->retirerDeclaration($dbh, $_POST["ido"]); } } break; case '/AjouterUnLieu': if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!is_null($u)) { $l = Lieu::ajouterUnLieu($dbh, $_POST["tag"], $_POST["lat"], $_POST["lng"]); if (is_array($l) && isset($l["error"])) { echo json_encode($l); } else { echo json_encode(array("e" => "v")); } } } break; case '/SupprimerUnLieu': if ($_SERVER['REQUEST_METHOD'] === 'POST') { Lieu::supprimerUnLieu($dbh, $_POST["idl"]); } break; case '/ChargerLesLieux': if ($_SERVER['REQUEST_METHOD'] === 'GET') { header('Content-Type: application/json'); $reponse = Lieu::chargerLesLieux($dbh); echo json_encode($reponse); } break; case '/ChargerLesUtilisateurs': if (!is_null($u)) { if ($_SERVER['REQUEST_METHOD'] === 'GET') { header('Content-Type: application/json'); $reponse = Utilisateur::chargerLesUtilisateurs($dbh); echo json_encode($reponse); } } break; case '/DetruireUtilisateur': if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!is_null($u)) { $u->detruireUtilisateur($dbh, $_POST["idu"]); } } break; case '/RendreAdmin': if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!is_null($u)) { echo $u->rendreAdmin($dbh, $_POST["idu"]); } } break; case '/ChargerLesMessagesEmetteur': $e = 1; case '/ChargerLesMessagesDestinataire': if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (!is_null($u)) { header('Content-Type: application/json'); $reponse = Message::chargerLesMessages($u->idu, $e); echo json_encode($reponse); } } break; default: echo file_get_contents('./public/redirect.html'); return false; } }
echo $twig->render('user_profil.html.twig', array('user' => $user, 'accessuser' => $_SESSION["co"], 'userco' => $userco)); break; //////////////// AJOUT D'OBJET ////////////// // affichage du formulaire d'ajout //////////////// AJOUT D'OBJET ////////////// // affichage du formulaire d'ajout case "add": $userco = $userManager->get($iduser); $categories = $categorieManager->getList(); echo $twig->render('ajout.html.twig', array('accessuser' => $_SESSION["co"], 'userco' => $userco, "cats" => $categories)); break; // envoie de l'objet en bdd // envoie de l'objet en bdd case "addobj": $userco = $userManager->get($iduser); $newobj = new Objet($_POST); $newobj->setIdUser($iduser); $objet = $objetsManager->add($newobj, $_FILES['photo']); header('location: index.php'); break; ////////////ENCHERE //////////// //affiche la page pour enchérir ////////////ENCHERE //////////// //affiche la page pour enchérir case "encherir": $userco = $userManager->get($iduser); $objet = $objetsManager->get($_GET["idobj"]); $enchere = $enchereManager->getLast($_GET["idobj"]); $enchere->setIdUser($iduser); echo $twig->render('encherir.html.twig', array('accessuser' => $_SESSION["co"], 'userco' => $userco, 'obj' => $objet, 'enchere' => $enchere)); break;
<?php /** * Created by PhpStorm. * User: Arthur * Date: 26/06/2015 * Time: 15:37 */ //Afficher une string $string = "Afficher une string avec echo"; echo $string . '<br />'; //Afficher un tableau $tableau = array('Bonjour', 1, true); var_dump($tableau); echo '<br />'; //Afficher un boolean $boolean = true; echo $boolean . '<br />'; //Afficher un objet //D'abord IL FAUT DEFINIR L'OBJET class Objet { public function objet() { echo 'On affiche un objet'; } } $object = new Objet(); $object->objet();
function combatAction() { $this->view->title = "Combat"; $id = (int) $this->_request->getParam('id', 0); // Pour afficher la zone $zone = new Zone(); $monstre = new Monstre(); $avatar = new Avatar(); $classe = new Classe(); $case = new Case_(); // Pour afficher l'inventaire dans le menu $arme_ = new Objet(); $armure_ = new Objet(); $avatar = $avatar->findById($id); $ligne = $case->getLigne($avatar->id_case); $colonne = $case->getColonne($avatar->id_case); $classe = $classe->getNameById($avatar->id_classe); $arme_ = $arme_->findById($avatar->id_arme); $armure_ = $armure_->findById($avatar->id_armure); $case = $case->findById($avatar->id_case); $appMonstre = new Zend_Session_Namespace('appMonstre'); $fin_combat = false; //zone $zone = $zone->findById($case->id_zone); if (!isset($appMonstre->round)) { $appMonstre->round = 0; $id_monstre = $appMonstre->id_monstre; echo $id_monstre; $monstre = $monstre->findById($id_monstre); $appMonstre->hp_monstre = $monstre->hp_monstre; $appMonstre->mp_monstre = $monstre->mp_monstre; $appMonstre->att_monstre = $monstre->att_monstre; $appMonstre->attsp_monstre = $monstre->attsp_monstre; $appMonstre->def_monstre = $monstre->def_monstre; $appMonstre->defsp_monstre = $monstre->defsp_monstre; $appMonstre->vit_monstre = $monstre->vit_monstre; } else { $monstre = $monstre->findById($appMonstre->id_monstre); } if ($appMonstre->hp_monstre == 0) { $message_victoire = "Vous avez vaincu " . $monstre->nom_monstre; $fin_combat = true; $appMonstre->round = NULL; $this->view->fin_message = $message_victoire; } if ($avatar->hp_avatar == 0) { $message_defaite = "Vous avez été vaincu par " . $monstre->nom_monstre; $fin_combat = true; $appMonstre->round = NULL; $this->view->fin_message = $message_defaite; } if ($fin_combat && $avatar->hp_avatar > 0) { $dropsmonstre = new ObjetMonstre(); $dropsmonstre = $dropsmonstre->getByMonstre($appMonstre->id_monstre); $cpt = 0; $drops = array(); foreach ($dropsmonstre as $drop) { $nbaleatoire = rand(0, 100); if ($nbaleatoire < $drop->taux_drop) { $item = new LigneInventaire(); if ($item = $item->findItem($avatar->id_avatar, $drop->id_objet)) { $data = array('quantite_ligne' => $item->quantite_ligne + 1); $where = " id_avatar = " . $avatar->id_avatar . " AND id_objet = " . $drop->id_objet; $item = new LigneInventaire(); $item->update($data, $where); } else { $data = array('id_avatar' => $avatar->id_avatar, 'id_objet' => $drop->id_objet, 'quantite_ligne' => 1); $item = new LigneInventaire(); $item->insert($data); } $objet = new Objet(); $drops[$cpt] = $objet->findById($drop->id_objet)->nom_objet; $cpt++; } } $this->view->dropsmonstre = $drops; $this->view->cpt = $cpt; $avatar_ = new Avatar(); $exp = $avatar->exp_avatar + $monstre->exp_monstre; $data = array('exp_avatar' => $exp); $where = ' id_avatar = ' . $id; $avatar_->update($data, $where); lvlUp($id); $this->view->exp = $exp; } //gestion de la fuite $fuite = false; $this->view->fuite = ""; if (isset($appMonstre->fuite)) { if ($appMonstre->fuite == true) { $this->view->message_fuite = "Fuite réussie!"; $fuite = true; $appMonstre->round = NULL; } else { $this->view->message_fuite = "Fuite échouée!"; } $appMonstre->fuite = NULL; } $this->view->fuite = $fuite; $this->view->fin_combat = $fin_combat; $this->view->ligne = $ligne; $this->view->colonne = $colonne; $this->view->avatar = $avatar; $this->view->classe = $classe; $this->view->monstre = $monstre; $this->view->monstre_ = $appMonstre; $this->view->arme_ = $arme_; $this->view->armure_ = $armure_; $this->view->zone = $zone; }
public function update(Objet $obj) { $req = "UPDATE objets SET idcategorie = '" . $obj->getIdCategorie() . "', " . "nom = '" . $obj->getNom() . "', " . "prixini = '" . $obj->getPrixIni() . "', " . "datedebut = '" . $obj->getDateDebut() . "', " . "datefin = " . $obj->getDateFin() . ", " . "description = " . $obj->getDescription() . ", " . "photo = '" . $obj->getPhoto() . "' " . " WHERE idobj =" . $obj->getIdObj(); echo $req; return $this->db->exec($req); }