/front/page/TraitementMesAnnonces.class.php

https://github.com/Kelzo/projet-sel · PHP · 147 lines · 135 code · 4 blank · 8 comment · 4 complexity · 46a9e2145d3615fb5aaf3e3caf0bf7c2 MD5 · raw file

  1. <?php
  2. class TraitementMesAnnonces{
  3. function __construct(){
  4. $qAnnonce = new QueryAnnonce();
  5. $id = $_SESSION['id'];
  6. $util = new Util();
  7. $qUser = new QueryUtilisateur();
  8. $user = $qUser->getById($id);
  9. $qCom = new QueryCommentaire();
  10. $qNotif = new QueryNotification();
  11. $qTransaction = new QueryTransaction();
  12. //on traite la suppression
  13. if(ISSET($_POST['suppressionAnnonce'])){
  14. $qAnnonce->delete($_POST['annonceId']);
  15. //et on supprime tous les elements si rapportant
  16. $listeCom = $qCom->getByAnnonceId($_POST['annonceId']);
  17. while($blop=mysql_fetch_objet($listeCom)){
  18. $qCom->delete($blop->id);
  19. }
  20. $listeNotif = $qNotif->getByAnnonceId($_POST['annonceId']);
  21. while($blop=mysql_fetch_objet($listeNotif)){
  22. $qNotif->delete($blop->id);
  23. }
  24. $listeTransaction = $qTransaction->getByAnnonceId($_POST['annonceId']);
  25. while($blop=mysql_fetch_objet($listeTransaction)){
  26. $qTransaction->delete($blop->id);
  27. }
  28. }
  29. //on traite la reponse
  30. if(ISSET($_POST['reponse'])){
  31. //envoi des deux notifications
  32. $notif1 = new Notification();
  33. $notif1->date=date('Y-m-d',time());
  34. //on recupere l'annonce associé
  35. $annonce = $qAnnonce->getById($_POST['annonceCibleId']);
  36. $notif1->desc=mysql_escape_string("Vous etez interessé par <a href=consulterAnnonce.php?annonce=".$annonce->id.">l'annonce ".$annonce->titre."</a>");
  37. $notif1->etat="REPONDU";
  38. $notif1->recepteurId=$user->id;
  39. $notif1->emetteurId=$user->id;
  40. $notif1->type="REPONSE";
  41. $notif1->annonceId=$_POST['annonceCibleId'];
  42. $notif1->transactionDirectId=-1;
  43. $qNotif->insert($notif1);
  44. $notif2 = new Notification();
  45. $notif2->date=date('Y-m-d',time());
  46. //on recupere l'annonce associé
  47. $annonce = $qAnnonce->getById($_POST['annonceCibleId']);
  48. if($_POST['annonceId']!=-1){
  49. $notif2->desc=mysql_escape_string($user->nom." ".$user->prenom." est interessé par <a href=consulterAnnonce.php?annonce=".$annonce->id.">l'annonce ".$annonce->titre."</a> et vous propose <a href='consulterAnnonce.php?annonce=".$_POST['annonceId']."'> l'annonce suivante</a> ainsi que ".$_POST['prix']." grains de poivre en echange.");
  50. }else{
  51. $notif2->desc=mysql_escape_string($user->nom." ".$user->prenom." est interessé par <a href=consulterAnnonce.php?annonce=".$annonce->id.">l'annonce ".$annonce->titre."</a> et vous propose ".$_POST['prix']." grains de poivre en echange.");
  52. }
  53. $notif2->etat="EN_ATTENTE";
  54. $notif2->recepteurId=$annonce->utilisateurId;
  55. $notif2->emetteurId=$user->id;
  56. $notif2->type="REPONSE";
  57. $notif2->annonceId=$_POST['annonceCibleId'];
  58. $notif2->transactionDirectId=-1;
  59. $qNotif->insert($notif2);
  60. //on crée la transaction
  61. $transaction = new Transaction();
  62. $transaction->annonceId=$_POST['annonceCibleId'];
  63. $transaction->emetteurId=$user->id;
  64. $transaction->recepteurId=$annonce->utilisateurId;
  65. $transaction->prix=$_POST['prix'];
  66. $transaction->annoncePropositionId=$_POST['annonceId'];
  67. $qTransaction->insert($transaction);
  68. }
  69. //on traite le formulaire commentaire
  70. if(ISSET($_POST['commentaire'])){
  71. $newCom = new Commentaire();
  72. $newCom->annonceId=$_POST['annonceId'];
  73. $newCom->datePublication= date('Y-m-d',time());
  74. $newCom->texte=mysql_escape_string($_POST['texte']);
  75. $newCom->utilisateurId=$user->id;
  76. $qCom->insert($newCom);
  77. //on envoie une notification a celui qui a écrit le com
  78. $notif1 = new Notification();
  79. $notif1->date=date('Y-m-d',time());
  80. $annonce = $qAnnonce->getById($_POST['annonceId']);
  81. $emetteurAnnonce = $qUser->getById($annonce->utilisateurId);
  82. $notif1->desc=mysql_escape_string("Vous avez commenté <a href=consulterAnnonce.php?annonce=".$annonce->id.">l'annonce</a> concernant ".$annonce->desc." proposé par ".$emetteurAnnonce->nom." ".$emetteurAnnonce->prenom);
  83. $notif1->etat="REPONDU";
  84. $notif1->recepteurId=$user->id;
  85. $notif1->emetteurId=$user->id;
  86. $notif1->type="COMMENTAIRE";
  87. $notif1->annonceId=$_POST['annonceId'];
  88. $notif1->transactionDirectId=-1;
  89. $qNotif->insert($notif1);
  90. //on envoie une notification a celui qui a écrit l'annonce
  91. $notif2 = new Notification();
  92. $notif2->date=date('Y-m-d',time());
  93. $notif2->desc=mysql_escape_string($user->nom." ".$user->prenom." a commenté votre <a href=consulterAnnonce.php?annonce=".$annonce->id.">annonce ".$annonce->titre."</a><br/>");
  94. $notif2->etat="REPONDU";
  95. $notif2->recepteurId=$annonce->utilisateurId;
  96. $notif2->emetteurId=$user->id;
  97. $notif2->annonceId=$_POST['annonceId'];
  98. $notif2->transactionDirectId=-1;
  99. $notif2->type="COMMENTAIRE";
  100. $qNotif->insert($notif2);
  101. }
  102. //on traite la suppression commentaire
  103. if(ISSET($_POST['suppressionCom'])){
  104. $qCom->delete($_POST['comId']);
  105. //on envoie une notification
  106. $notif1 = new Notification();
  107. $notif1->date=date('Y-m-d',time());
  108. $annonce = $qAnnonce->getById($_POST['annonceId']);
  109. $notif1->desc=mysql_escape_string("Vous avez supprimé un de vos commentaires de <a href=consulterAnnonce.php?annonce=".$annonce->id.">l'annonce ".$annonce->titre."</a><br/>");
  110. $notif1->etat="REPONDU";
  111. $notif1->recepteurId=$user->id;
  112. $notif1->emetteurId=$user->id;
  113. $notif1->annonceId=$annonce->id;
  114. $notif1->transactionDirectId=-1;
  115. $notif1->type="COMMENTAIRE";
  116. $qNotif->insert($notif1);
  117. }
  118. //si on creer une annonce
  119. if(ISSET($_POST['crea'])){
  120. $annonceNew=new Annonce();
  121. $annonceNew->typeAnnonceId = mysql_escape_string($_POST['typeAnnonceId']."");
  122. $annonceNew->utilisateurId = $user->id;
  123. $annonceNew->titre = mysql_escape_string($_POST['titre']."");
  124. $annonceNew->desc = mysql_escape_string($_POST['desc']."");
  125. $annonceNew->date = date('Y-m-d',strtotime(mysql_escape_string($_POST['date']."")));
  126. $annonceNew->adresse = mysql_escape_string($_POST['adresse']."");
  127. $annonceNew->cp = mysql_escape_string($_POST['cp']."");
  128. $annonceNew->ville = mysql_escape_string($_POST['ville']."");
  129. $annonceNew->coutPoivre = mysql_escape_string($_POST['coutPoivre']."");
  130. $annonceNew->idAnnonceParent = -1;
  131. $annonceNew->annonceValide = false;
  132. $annonceNew->datePublication = date('Y-m-d',time());
  133. $annonceNew->permanente= mysql_escape_string($_POST['permanente']."");
  134. $qAnnonce->insert($annonceNew);
  135. }
  136. }
  137. }
  138. ?>