Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.31 KB | None | 0 0
  1. <?php
  2. class users{
  3.   private $bdd;
  4.   public function __construct(){
  5.     require_once('core/db.php');
  6.     $this->bdd = $connect;
  7.   }
  8.   public function checkPassword(){
  9.     $email = $_POST['mail'];
  10.     $my_mdp = hash_hmac('ripemd160',$_POST['password'], 'si tu aimes la wac tape dans tes mains');
  11.     $req = $this->bdd->prepare("SELECT * FROM user WHERE mail = '$email'");
  12.     $req->execute();
  13.     $status = $req->fetch();
  14.     if ($status['activee'] == "0") {
  15.       echo "<p class='red-text text-darken-2'>Ce compte a été suprimé.</p>";
  16.     }
  17.     else {
  18.       if (isset($email) && isset($my_mdp)) {
  19.         $req = $this->bdd->prepare("SELECT * FROM user WHERE mail = '$email' AND password = '$my_mdp'");
  20.         $req->execute();
  21.         $check = $req->fetch();
  22.         if ($check['mail'] != $email ) {
  23.           require_once('connect.php');
  24.           echo "<p class='red-text text-darken-2'>adresse mail ou mot de passe invalide.</p>";
  25.         }
  26.         elseif($check['password'] != $my_mdp) {
  27.           require_once('connect.php');
  28.           echo "<p class='red-text text-darken-2'>adresse mail ou mot de passe invalide</p>";
  29.         }
  30.         else{
  31.           header('Location: index.php?controller=UserController&action=timeline');
  32.         }
  33.       }
  34.       $_SESSION['ID'] = $check['id'];
  35.       $_SESSION['pseudo'] = $check['pseudo'];
  36.       $_SESSION['nom'] = $check['nom'];
  37.       $_SESSION['mail'] = $check['mail'];
  38.       $_SESSION['password'] = $_POST['password'];
  39.       $_SESSION['img_profil'] = $check['img_profil'];
  40.       $_SESSION['img_couverture'] = $check['img_couverture'];
  41.       $_SESSION['description'] = $check['description'];
  42.       $_SESSION['web'] = $check['web'];
  43.       $_SESSION['date_nais'] = $check['date_nais'];
  44.       $_SESSION['date_ins'] = $check['date_ins'];
  45.       $_SESSION['activee'] = $check['activee'];
  46.       $_SESSION['ville'] = $check['ville_id'];
  47.     }
  48.   }
  49.   public function addUsers(){
  50.     if(isset($_POST['nom']) && isset($_POST['pseudo']) && isset($_POST['ville']) && isset($_POST['date_nais']) &&
  51.     isset($_POST['mail']) && isset($_POST['password'])){
  52.       $req = $this->bdd->prepare("INSERT INTO user(pseudo, nom, ville_id,
  53.        date_nais, mail, password) VALUES ('".$_POST['pseudo']."', '".$_POST['nom']."',
  54.        '".$_POST['ville']."', '".$_POST['date_nais']."', '".$_POST['mail']."', '".hash_hmac('ripemd160',$_POST['password'], 'si tu aimes la wac tape dans tes mains')."')");
  55.         $req->execute();
  56.         echo '<p class="black-text text-darken-2">Votre inscription a bien était enregistrée, vous allez recevoir un mail pour pouvoir la confirmée ... OU PAS<p><br>
  57.        <form class="osef" action="index.php?controller=UserController&action=connection" method="post">
  58.        <input class="btn waves-effect waves-light blue" type="submit" name="confirm" value="Se connecter">
  59.        </form>';
  60.         require_once('index.php');
  61.       }
  62.       else
  63.       {
  64.         return false;
  65.       }
  66.   }
  67.   public function membre(){
  68.       $req = $this->bdd->prepare('SELECT * FROM user INNER JOIN villes_france_free ON user.ville_id =
  69.        villes_france_free.ville_id  WHERE id = "'.$_SESSION['ID'].'"');
  70.         $req->execute();
  71.         $affiche = $req->fetch();
  72.         echo"<div id='Info'>";
  73.         echo "<br><p class='black-text text-darken-2'>".$affiche["nom"]."<br><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$affiche['id']."'>@".$affiche["pseudo"]."</a><br>".$affiche["date_nais"].
  74.         "<br>".$affiche["ville_nom"]."<br>".$affiche["mail"]."<br></p>";
  75.         echo "</div>";
  76.       }
  77.   public function disconnect(){
  78.         session_destroy();
  79.         header('Location: index.php?controller=UserController&action=connection');
  80.       }
  81.   public function change(){
  82.         $req = $this->bdd->prepare('UPDATE user SET nom = "'.$_POST['new_nom'].'",
  83.        pseudo = "'.$_POST['new_pseudo'].'", web = "'.$_POST['web'].'", description = "'.$_POST['description'].'",
  84.        mail = "'.$_POST['new_email'].'", password = "'.hash_hmac('ripemd160',$_POST['new_mdp'], 'si tu aimes la wac tape dans tes mains').'" WHERE id = "'.$_SESSION['ID'].'"');
  85.         $req->execute();
  86.         header('Location: index.php?controller=UserController&action=membre');
  87.  
  88.       }
  89.   public function add_img_P(){
  90.         if(isset($_POST['img_P'])){
  91.           $req = $this->bdd->prepare("UPDATE user SET img_profil = '".$_POST['img_P']."' WHERE id = '".$_SESSION['ID']."'");
  92.           $req->execute();
  93.           header('Location: index.php?controller=UserController&action=change');
  94.         }
  95.       }
  96.   public function add_img_C(){
  97.         if(isset($_POST['img_C'])){
  98.           $req = $this->bdd->prepare("UPDATE user SET img_couverture = '".$_POST['img_C']."' WHERE id = '".$_SESSION['ID']."'");
  99.           $req->execute();
  100.           header('Location: index.php?controller=UserController&action=change');
  101.         }
  102.       }
  103.   public function img_profil(){
  104.         $email = $_SESSION['mail'];
  105.         $req = $this->bdd->query("SELECT img_profil FROM user WHERE mail = '$email'");
  106.         $req = $req->fetch();
  107.         echo "<img class= 'img_p' src= ".$req['img_profil'].">";
  108.       }
  109.   public function img_cover(){
  110.         $email = $_SESSION['mail'];
  111.         $req = $this->bdd->query("SELECT img_couverture FROM user WHERE mail = '$email'");
  112.         $req = $req->fetch();
  113.         echo "<img class= 'img_c' src= ".$req['img_couverture'].">";
  114.       }
  115.   public function delete_confirm(){
  116.         $req = $this->bdd->prepare('UPDATE user SET activee = "0" WHERE ID = "'.$_SESSION['ID'].'"');
  117.         $req->execute();
  118.         echo "<p class='black-text text-darken-2'>Voter compte à bien été surprimé<p>";
  119.       }
  120.   public function AddHashTag(){
  121.         if(!empty($_POST['hastag'])){
  122.           $hash = htmlspecialchars($_POST['hashtag']);
  123.           $id = $_SESSION['ID'];
  124.           $req = $this->bdd->prepare("SELECT * FROM `user` INNER JOIN hashtag ON user.id = hashtag.id_tweet WHERE id = $id ");
  125.           $req->execute();
  126.           $req = $this->bdd->prepare("INSERT INTO `hashtag`(`name_hashtag`,`id_tweet`) VALUES ('$hash',$id)");
  127.           $req->execute();
  128.         }
  129.         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
  130.         header('Location: ' . $referer);
  131.       }
  132.   public function Poster(){
  133.         if(!empty($_POST['tweet'])){
  134.           $post = htmlspecialchars($_POST['tweet']);
  135.           $id = $_SESSION['ID'];
  136.           if(strlen($post) <= 140) {
  137.             $req = $this->bdd->prepare('SELECT * FROM `user` INNER JOIN tweet ON user.id = tweet.id_user WHERE id = '.$id.' ');
  138.             $req->execute();
  139.             $req = $this->bdd->prepare("INSERT INTO `tweet` (`tweet`,`date_tweet` ,`id_user`) VALUES ('$post', NOW(), '$id')");
  140.             $req->execute();
  141.           }
  142.         }
  143.         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
  144.         header('Location: ' . $referer);
  145.       }
  146.   public function readtweet(){
  147.         $req = $this->bdd->prepare('SELECT * FROM tweet INNER JOIN user ON tweet.id_user=user.id ORDER BY date_tweet DESC LIMIT 20');
  148.         $req->execute();
  149.         echo "<div class = 'Twe'>";
  150.         while($aff = $req->fetch()){
  151.           echo "<div class= 'tw'><img class= 'img_t' src= ".$aff['img_profil']."><p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><p>".htmlspecialchars($aff['tweet'])."</p><p>".$aff['date_tweet']."</p>";
  152.           if(isset($_SESSION['ID'])){
  153.             $reqq = $this->bdd->prepare('SELECT * FROM commentaire INNER JOIN user ON commentaire.id_user=user.id WHERE id_tweet = '.$aff['id_tweet'].'');
  154.             $reqq->execute();
  155.             echo "commentaire ";
  156.             while($afff = $reqq->fetch()){
  157.               echo "<a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$afff['pseudo']."</a> : ";
  158.               echo $afff['com']."<br>";
  159.             }
  160.             echo "</script><form class='osef' action='index.php?controller=UserController&action=comment&id=".$aff['id_tweet']."' method='post'>
  161.            <textarea id='comment' name='comment' class='materialize-textarea'rows='8' cols='80'></textarea>
  162.            <input class='btn waves-effect waves-light blue' type='submit' name='user' value='commentaire'></input></form>";
  163.             $sql = $this->bdd->prepare('SELECT * FROM tweet_like WHERE id_user = "'.$_SESSION['ID'].'" AND id_tweet = "'.$aff['id_tweet'].'"');
  164.             $sql2 = $sql->execute();
  165.             if($sql->rowCount() == 0){
  166.               echo "<form class='osef' action='index.php?controller=UserController&action=like&id=".$aff['id_tweet']."' method='post'>
  167.              <input class='waves-effect waves-light btn blue' type='submit' name='like' value='Like'></input>
  168.              </form>";
  169.             }
  170.             else{
  171.               echo "<form class='osef' action='index.php?controller=UserController&action=unlike&id=".$aff['id_tweet']."' method='post'>
  172.              <input class='waves-effect waves-light btn blue' type='submit' name='unlike' value='Unlike'></input>
  173.              </form>";
  174.             }
  175.             echo "<form class='osef' action='index.php?controller=UserController&action=retweet&id=".$aff['id_tweet']."' method='post'>
  176.            <input class='waves-effect waves-light btn blue' type='submit' name='unlike' value='retweet'></input>
  177.            </form></div>";
  178.           }
  179.           echo "</div>";
  180.         }
  181.         echo "</div>";
  182.       }
  183.   public function showMemberTwt() {
  184.         $req = $this->bdd->prepare('SELECT * FROM tweet INNER JOIN user ON tweet.id_user=user.id WHERE id_user = '.$_SESSION['ID'].' ORDER BY date_tweet DESC LIMIT 20 ');
  185.         $req->execute();
  186.         //var_dump('SELECT * FROM tweet INNER JOIN user ON tweet.id_user=user.id ORDER BY date_tweet DESC WHERE id_user = LIMIT 20');
  187.  
  188.         echo "<div class = 'Twe'>";
  189.         while($aff = $req->fetch()){
  190.           echo "<div class= 'tw'><img class= 'img_t' src= ".$aff['img_profil']."><p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><p>".htmlspecialchars($aff['tweet'])."</p><p>".$aff['date_tweet']."</p>";
  191.           $reqq = $this->bdd->prepare('SELECT * FROM commentaire INNER JOIN user ON commentaire.id_user=user.id WHERE id_tweet = '.$aff['id_tweet'].'');
  192.           $reqq->execute();
  193.           echo "commentaire ";
  194.           while($afff = $reqq->fetch()){
  195.             echo "<a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$afff['pseudo']."</a> : ";
  196.             echo $afff['com']."<br>";
  197.           }
  198.           echo "<form class='osef' action='index.php?controller=UserController&action=comment&id=".$aff['id_tweet']."' method='post'>
  199.          <textarea id='comment' name='comment' class='materialize-textarea'rows='8' cols='80'></textarea>
  200.          <input class='btn waves-effect waves-light blue' type='submit' name='user' value='commentaire'></form>";
  201.           $sql = $this->bdd->prepare('SELECT * FROM tweet_like WHERE id_user = "'.$_SESSION['ID'].'" AND id_tweet = "'.$aff['id_tweet'].'"');
  202.           $sql2 = $sql->execute();
  203.           if($sql->rowCount() == 0){
  204.             echo "<form class='osef' action='index.php?controller=UserController&action=like&id=".$aff['id_tweet']."' method='post'>
  205.            <input class='waves-effect waves-light btn blue' type='submit' name='like' value='Like'></input>
  206.            </form></div>";
  207.           }
  208.           else{
  209.             echo "<form class='osef' action='index.php?controller=UserController&action=unlike&id=".$aff['id_tweet']."' method='post'>
  210.            <input class='waves-effect waves-light btn blue' type='submit' name='unlike' value='Unlike'></input>
  211.            </form></div>";
  212.           }
  213.         }
  214.         echo "</div>";
  215.       }
  216.   public function all_users(){
  217.         global $id, $pp;
  218.         $req = $this->bdd->prepare('SELECT * FROM user WHERE id !=\''.$_SESSION['ID'].'\'');
  219.         $req->execute();
  220.         echo "<div class = 'all'>";
  221.         while($aff = $req->fetch()){
  222.           $id = $aff['id'];
  223.           echo "<div class= 'tw'><p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><p>".$aff['mail']."</p><img class= 'img_t' src= ".$aff['img_profil'].">";
  224.           $pp = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_followers=user.id WHERE id_followers = '".$_SESSION['ID']."' AND id_following = $id");
  225.           $pp->execute();
  226.           if($pp->rowCount() == 0) {
  227.             echo "<form class='osef' action='index.php?controller=UserController&action=follow&user_id=".$id."' method='post'>
  228.            <input class='btn waves-effect waves-light blue' type='submit' name='user' value='follow'>
  229.            </form>";
  230.           }
  231.           else {
  232.             echo "<form class='osef' action='index.php?controller=UserController&action=unfollow&user_id=".$id."' method='post'>
  233.            <input class='btn waves-effect waves-light blue' type='submit' name='user' value='unfollow'>
  234.            </form>";
  235.           }
  236.           echo "</div>";
  237.         }
  238.         echo "</div>";
  239.       }
  240.   public function follow(){
  241.         $ids = $_SESSION['ID'];
  242.         $id = $_GET['user_id'];
  243.         $req = $this->bdd->prepare("SELECT * FROM user INNER JOIN follow ON user.id=follow.id_followers WHERE id = $ids");
  244.         $req->execute();
  245.         $req = $this->bdd->prepare("SELECT * FROM user INNER JOIN follow ON user.id=follow.id_following WHERE id = $id ");
  246.         $req->execute();
  247.         $req = $this->bdd->prepare("INSERT INTO `follow` (`id_followers`,`id_following`) VALUES ($ids, $id)");
  248.         $req->execute();
  249.         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
  250.         header('Location: ' . $referer);
  251.       }
  252.   public function unfollow(){
  253.         $ids = $_SESSION['ID'];
  254.         $id = $_GET['user_id'];
  255.         $req = $this->bdd->prepare("SELECT * FROM user INNER JOIN follow ON user.id=follow.id_followers WHERE id = $ids");
  256.         $req->execute();
  257.         $req = $this->bdd->prepare("SELECT * FROM user INNER JOIN follow ON user.id=follow.id_following WHERE id = $id ");
  258.         $req->execute();
  259.         $req = $this->bdd->prepare("DELETE FROM follow WHERE id_followers = $ids AND id_following = $id");
  260.         $req->execute();
  261.         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
  262.         header('Location: ' . $referer);
  263.       }
  264.   public function comment(){
  265.         if(!empty($_POST['comment'])){
  266.           $req = $this->bdd->prepare('INSERT INTO commentaire(id_user, id_tweet, com) VALUES ("'.$_SESSION['ID'].'", "'.$_GET['id'].'", "'.$_POST['comment'].'")');
  267.           $req->execute();
  268.         }
  269.         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
  270.         header('Location: ' . $referer);
  271.       }
  272.   public function like(){
  273.         $req = $this->bdd->prepare('INSERT INTO tweet_like(id_user, id_tweet) VALUES ("'.$_SESSION['ID'].'", "'.$_GET['id'].'")');
  274.         $req->execute();
  275.         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
  276.         header('Location: ' . $referer);
  277.       }
  278.   public function unlike(){
  279.         $req = $this->bdd->prepare('DELETE FROM tweet_like WHERE id_user = "'.$_SESSION['ID'].'" AND id_tweet = "'.$_GET['id'].'"');
  280.         $req->execute();
  281.         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
  282.         header('Location: ' . $referer);
  283.       }
  284.   public function follower(){
  285.         $idf = $_SESSION['ID'];
  286.         $req = $this->bdd->prepare("SELECT COUNT(*) AS cont FROM user INNER JOIN follow ON user.id=follow.id_followers WHERE user.id='$idf'");
  287.         $req->execute();
  288.         $reqs = $this->bdd->prepare("SELECT COUNT(*) AS cunt FROM user INNER JOIN follow ON user.id=follow.id_following WHERE user.id='$idf'");
  289.         $reqs->execute();
  290.         echo "<div id='flw'>";
  291.         while ($aff=$reqs ->fetch()) {
  292.           echo "<form class='osef' action='index.php?controller=UserController&action=affFollow' method='post'>";
  293.           echo "<input class='btn waves-effect waves-light blue' type='submit' name='user' value='Abonnée : ".$aff['cunt']."'></form>";
  294.         }
  295.         while($aff = $req->fetch()){
  296.           echo "<form class='osef' action='index.php?controller=UserController&action=affFollowing' method='post'>";
  297.           echo "<input class='btn waves-effect waves-light blue' type='submit' name='user' value='Abonnements : ".$aff['cont']."'></form>";
  298.         }
  299.         echo "</div>";
  300.       }
  301.   public function affFollow() {
  302.         $idf = $_SESSION['ID'];
  303.         $requete = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_following=$idf WHERE id = id_followers");
  304.         $requete->execute();
  305.         $requetes = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_followers=$idf WHERE id = id_following");
  306.         $requetes->execute();
  307.         echo "<div class= 'tw'><h3>FOLLOWERS</h3><hr/>";
  308.         while($aff = $requete->fetch()){
  309.           $pp = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_followers=user.id WHERE id_followers = '".$_SESSION['ID']."' AND id_following = ".$aff['id']);
  310.           $pp->execute();
  311.           echo "<p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><img class= 'img_t' src= ".$aff['img_profil']."><br>";
  312.           if($pp->rowCount() == 0) {
  313.             echo "<form class='osef' action='index.php?controller=UserController&action=follow&user_id=".$aff['id']."' method='post'>
  314.            <input class='btn waves-effect waves-light blue' type='submit' name='user' value='follow'>
  315.            </form>";
  316.           }
  317.           else {
  318.             echo "<form class='osef' action='index.php?controller=UserController&action=unfollow&user_id=".$aff['id']."' method='post'>
  319.            <input class='btn waves-effect waves-light blue' type='submit' name='user' value='unfollow'>
  320.            </form>";
  321.           }
  322.         }
  323.         echo "</div>";
  324.       }
  325.   public function affFollowing() {
  326.         $idf = $_SESSION['ID'];
  327.         $requete = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_following=$idf WHERE id = id_followers");
  328.         $requete->execute();
  329.         $requetes = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_followers=$idf WHERE id = id_following");
  330.         $requetes->execute();
  331.         echo "<div class= 'tw'><h3>FOLLOWING</h3><hr/>";
  332.         while ($aff=$requetes->fetch()) {
  333.           echo "<p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><img class= 'img_t' src= ".$aff['img_profil'].">";
  334.           echo"<form class='osef' action='index.php?controller=UserController&action=unfollow&user_id=".$aff['id']."' method='post'>
  335.          <input class='btn waves-effect waves-light blue' type='submit' name='user' value='unfollow'>
  336.          </form><br>";
  337.         }
  338.         echo "</div>";
  339.       }
  340.   public function send_message(){
  341.         $req = $this->bdd->prepare('SELECT * FROM user WHERE pseudo = "'.htmlspecialchars($_POST['dest']).'"');
  342.         $req->execute();
  343.         while ($aff = $req->fetch()){
  344.           $reqs = $this->bdd->prepare('INSERT INTO messages (id_to, id_by, message) VALUES ('.$aff['id'].','.$_SESSION['ID'].', "'.$_POST['message'].'")');
  345.           $reqs->execute();
  346.         }
  347.         header('location: index.php?controller=UserController&action=messagerie');
  348.       }
  349.   public function read_message(){
  350.         $req = $this->bdd->prepare('SELECT * FROM messages INNER JOIN user ON messages.id_by=user.id WHERE id_to = '.$_SESSION['ID'].' ORDER BY date_env DESC');
  351.         $req->execute();
  352.         echo "<p>Reçu</p>";
  353.         while ($aff = $req->fetch()){
  354.           echo "<div class= 'tw'><img class= 'img_t' src= ".$aff['img_profil']."><p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><p>".htmlspecialchars($aff['message'])."</p>";
  355.           echo "<form class='osef' action='index.php?controller=UserController&action=repondre&id_by=".$aff['id_by']."' method='post'>
  356.          <textarea id='comment' name='message' class='materialize-textarea'rows='8' cols='80'></textarea>
  357.          <input class='btn waves-effect waves-light blue' type='submit' name='user' value='repondre'></form></div>";
  358.         }
  359.         $req = $this->bdd->prepare('SELECT * FROM messages INNER JOIN user ON messages.id_to=user.id WHERE id_by = '.$_SESSION['ID'].' ORDER BY date_env DESC');
  360.         $req->execute();
  361.         echo "<p>envoyer</p>";
  362.         while ($aff = $req->fetch()){
  363.           echo "<div class= 'tw'><img class= 'img_t' src= ".$aff['img_profil']."><p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><p>".htmlspecialchars($aff['message'])."</p></div>";
  364.         }
  365.       }
  366.   public function repondre(){
  367.         $id_to = $_GET['id_by'];
  368.         $req = $this->bdd->prepare('INSERT INTO messages (id_to, id_by, message) VALUES ('.$id_to.','.$_SESSION['ID'].', "'.$_POST['message'].'")');
  369.         var_dump($req);
  370.         $req->execute();
  371.         header('location: index.php?controller=UserController&action=messagerie');
  372.       }
  373.   public function profil(){
  374.         $req = $this->bdd->prepare('SELECT * FROM user INNER JOIN villes_france_free ON user.ville_id =
  375.          villes_france_free.ville_id  WHERE id = '.$_GET['id_user'].'');
  376.           $req->execute();
  377.           $affiche = $req->fetch();
  378.           echo"<div id='Info'>";
  379.  
  380.           echo "<br><p class='black-text text-darken-2'>".$affiche["nom"]."<br><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$affiche['id']."'>@".$affiche["pseudo"]."</a><br>".$affiche["date_nais"].
  381.           "<br>".$affiche["ville_nom"]."<br>".$affiche["mail"]."<br></p>";
  382.           echo "</div>";
  383.  
  384.         }
  385.   public function showProfilTwt(){
  386.           $id = $_GET['id_user'];
  387.           $req = $this->bdd->prepare('SELECT * FROM tweet INNER JOIN user ON tweet.id_user=user.id WHERE id_user = '.$_GET['id_user'].' ORDER BY date_tweet DESC LIMIT 20 ');
  388.           $req->execute();
  389.           echo "<div class = 'Twe'>";
  390.           while($aff = $req->fetch()){
  391.             echo "<div class= 'tw'><img class= 'img_t' src= ".$aff['img_profil']."><p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><p>".htmlspecialchars($aff['tweet'])."</p><p>".$aff['date_tweet']."</p>";
  392.             $reqq = $this->bdd->prepare('SELECT * FROM commentaire INNER JOIN user ON commentaire.id_user=user.id WHERE id_tweet = '.$aff['id_tweet'].'');
  393.             $reqq->execute();
  394.             echo "commentaire ";
  395.             while($afff = $reqq->fetch()){
  396.               echo "<a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$afff['pseudo']."</a> : ";
  397.               echo $afff['com']."<br>";
  398.             }
  399.             echo "<form class='osef' action='index.php?controller=UserController&action=comment&id=".$aff['id_tweet']."' method='post'>
  400.            <textarea id='comment' name='comment' class='materialize-textarea'rows='8' cols='80'></textarea>
  401.            <input class='btn waves-effect waves-light blue' type='submit' name='user' value='commentaire'></form>";
  402.             $sql = $this->bdd->prepare('SELECT * FROM tweet_like WHERE id_user = "'.$_SESSION['ID'].'" AND id_tweet = "'.$aff['id_tweet'].'"');
  403.             $sql2 = $sql->execute();
  404.             if($sql->rowCount() == 0){
  405.               echo "<form class='osef' action='index.php?controller=UserController&action=like&id=".$aff['id_tweet']."' method='post'>
  406.              <input class='waves-effect waves-light btn blue' type='submit' name='like' value='Like'></input>
  407.              </form>";
  408.             }
  409.             else{
  410.               echo "<form class='osef' action='index.php?controller=UserController&action=unlike&id=".$aff['id_tweet']."' method='post'>
  411.              <input class='waves-effect waves-light btn blue' type='submit' name='unlike' value='Unlike'></input>
  412.              </form>";
  413.             }
  414.             echo "<form class='osef' action='index.php?controller=UserController&action=retweet&id=".$aff['id_tweet']."' method='post'>
  415.            <input class='waves-effect waves-light btn blue' type='submit' name='unlike' value='retweet'></input>
  416.            </form></div>";
  417.           }
  418.           $pp = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_followers=user.id WHERE id_followers = '".$_SESSION['ID']."' AND id_following = $id");
  419.           $pp->execute();
  420.           if($pp->rowCount() == 0) {
  421.             echo "<form class='osef' action='index.php?controller=UserController&action=follow&user_id=".$id."' method='post'>
  422.            <input class='btn waves-effect waves-light blue' type='submit' name='user' value='follow'>
  423.            </form>";
  424.           }
  425.           else {
  426.             echo "<form class='osef' action='index.php?controller=UserController&action=unfollow&user_id=".$id."' method='post'>
  427.            <input class='btn waves-effect waves-light blue' type='submit' name='user' value='unfollow'>
  428.            </form>";
  429.           }
  430.           echo "</div>";
  431.           echo "</div>";
  432.         }
  433.   public function img_profil_profil(){
  434.           $req = $this->bdd->query("SELECT img_profil FROM user WHERE id = ".$_GET['id_user']."");
  435.           $req = $req->fetch();
  436.           echo "<img class= 'img_p' src= ".$req['img_profil'].">";
  437.         }
  438.   public function img_cover_profil(){
  439.           $req = $this->bdd->query("SELECT img_couverture FROM user WHERE id = ".$_GET['id_user']."");
  440.           $req = $req->fetch();
  441.           echo "<img class= 'img_c' src= ".$req['img_couverture'].">";
  442.         }
  443.   public function followerProfil(){
  444.           $idf = $_GET['id_user'];
  445.           $req = $this->bdd->prepare("SELECT COUNT(*) AS cont FROM user INNER JOIN follow ON user.id=follow.id_followers WHERE user.id='$idf'");
  446.           $req->execute();
  447.           $reqs = $this->bdd->prepare("SELECT COUNT(*) AS cunt FROM user INNER JOIN follow ON user.id=follow.id_following WHERE user.id='$idf'");
  448.           $reqs->execute();
  449.           echo "<div id='flw'>";
  450.           while ($aff=$reqs ->fetch()) {
  451.             echo "<form class='osef' action='index.php?controller=UserController&action=affFollowProfil&id_user=".$idf."' method='post'>";
  452.             echo "<input class='btn waves-effect waves-light blue' type='submit' name='user' value='Abonnée : ".$aff['cunt']."'></form>";
  453.           }
  454.           while($aff = $req->fetch()){
  455.             echo "<form class='osef' action='index.php?controller=UserController&action=affFollowingProfil&id_user=".$idf."' method='post'>";
  456.             echo "<input class='btn waves-effect waves-light blue' type='submit' name='user' value='Abonnements : ".$aff['cont']."'></form>";
  457.           }
  458.           echo "</div>";
  459.         }
  460.   public function affFollowProfil() {
  461.           $idf = $_GET['id_user'];
  462.           $requete = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_following=$idf WHERE id = id_followers");
  463.           $requete->execute();
  464.           $requetes = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_followers=$idf WHERE id = id_following");
  465.           $requetes->execute();
  466.           echo "<div class= 'tw'><h3>FOLLOWERS</h3><hr/>";
  467.           while($aff = $requete->fetch()){
  468.             $pp = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_followers=user.id WHERE id_followers = '".$_SESSION['ID']."' AND id_following = ".$aff['id']);
  469.             $pp->execute();
  470.             echo "<p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><img class= 'img_t' src= ".$aff['img_profil']."><br>";
  471.           }
  472.           echo "</div>";
  473.         }
  474.   public function affFollowingProfil(){
  475.           $idf = $_GET['id_user'];
  476.           $requete = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_following=$idf WHERE id = id_followers");
  477.           $requete->execute();
  478.           $requetes = $this->bdd->prepare("SELECT * FROM follow INNER JOIN user ON follow.id_followers=$idf WHERE id = id_following");
  479.           $requetes->execute();
  480.           echo "<div class= 'tw'><h3>FOLLOWING</h3><hr/>";
  481.           while ($aff=$requetes->fetch()) {
  482.             echo "<p><a class='lnProf'href='index.php?controller=UserController&action=profil&id_user=".$aff['id']."'>@".$aff['pseudo']."</a></p><img class= 'img_t' src= ".$aff['img_profil'].">";
  483.           }
  484.           echo "</div>";
  485.         }
  486.   public function retweet(){
  487.     $id = $_SESSION['ID'];
  488.     $req = $this->bdd->prepare('SELECT * FROM tweet WHERE id_tweet = '.$_GET['id'].' ');
  489.     $req->execute();
  490.     while ($aa = $req->fetch()) {
  491.       $post = $aa['tweet'];
  492.       $idr = $aa['id_tweet'];
  493.       $req = $this->bdd->prepare('INSERT INTO tweet (tweet, id_retweet,id_user) VALUES ("'.htmlspecialchars($post).'", '.$idr.', '.$id.')');
  494.       $req->execute();
  495.       $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'index.php';
  496.       header('Location: ' . $referer);
  497.     }
  498.   }
  499. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement