function assez_de_votes($id_potin, $bdd) { $data_potin = infos_potin($id_potin, $bdd); if (nb_votants($id_potin, $bdd) > nb_utilisateurs_actifs_groupe($data_potin['id_Groupe'], $bdd) / 2) { return true; } else { return false; } }
// pour chacun des groupes en commun foreach ($groupes_communs as $ng => $groupe_courant) { $groupe_courant = infos_groupe($groupe_courant, $bdd); $potins_cherches = rechercher_potins_d_un_user_dans_un_groupe($id_user, $groupe_courant['id_groupe'], $user_concerne['id_user'], $bdd); //echo '<h3>'.$groupe_courant['nom'].'</h3>'; echo '<div class="panel panel-default panel-acc-gp"> <div class="panel-heading" role="tab" id="acc-gp-' . $groupe_courant['id_groupe'] . '"> <h4 class="panel-title"> <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse-gp-' . $groupe_courant['id_groupe'] . '" aria-expanded="false" aria-controls="collapse-gp-' . $groupe_courant['id_groupe'] . '"> ' . $groupe_courant['nom'] . ' </a> </h4> <span class="badge pg-gp-nb-pot-gp">' . nb_potins_visibles_sur_user_ds_gpe($groupe_courant['id_groupe'], $user_concerne['id_user'], $id_user, $bdd) . ' potins ! </span> </div> <div id="collapse-gp-' . $groupe_courant['id_groupe'] . '" class="panel-collapse collapse" role="tabpanel" aria-labelledby="acc-gp-' . $groupe_courant['id_groupe'] . '"> <div class="panel-body">'; if ($potins_cherches != 0) { // Pour chacun des potins du groupe foreach ($potins_cherches as $i => $potin_courant) { $potin_courant = infos_potin($potin_courant, $bdd); echo vue_affichage_potin($potin_courant, $id_user, $bdd); } } echo '</div> </div> </div>'; } echo '</div>'; // Fin accordéon echo '<a href="' . INDEX . '?page=page_membre&id_concerne=' . $user_concerne['id_user'] . '&onglet=groupes">Découvrir des potins dans ses autres groupes !</a>'; echo '</div>';
//echo "erreur file type"; } if (isset($_POST['id_groupe']) && isset($_POST['users_concernes']) && isset($_POST['potin'])) { $groupe = $_POST['id_groupe']; $concernes = json_decode($_POST['users_concernes']); $potin = $_POST['potin']; $potin = make_clickable($potin); // On écrit le potin dans la table "potins" $req = $bdd->prepare('INSERT INTO potins(potin, id_auteur, id_groupe, date_potin, image) VALUES(?, ?, ?, NOW(), ?)'); $req->execute(array($potin, $id_user, $groupe, $LienImageNews)); $id_nouveau_potin = $bdd->lastInsertId(); // On récupère l'id du potin inséré // On associe le potin à chaque user concerne foreach ($concernes as $key => $concerne_courant) { $req = $bdd->prepare('INSERT INTO cor_potin_users(id_concerne, id_potin, decouvert) VALUES(?, ?, 0)'); $req->execute(array($concerne_courant, $id_nouveau_potin)); // Notifications include_once 'modele/notifications.php'; nouvelle_notif($concerne_courant, 'nouv_potin', $id_nouveau_potin, $groupe, $bdd); } // Renvoi de l'affichage du nouveau potin include_once 'modele/rechercher_potins.php'; $potin_courant = infos_potin($id_nouveau_potin, $bdd); //include_once('vue/potin/affichage_potin.php'); include_once 'vue/potin/potin_v4.php'; //$retour['potin'] = vue_affichage_potin($potin_courant, $id_user, $bdd); $retour['potin'] = vue_potin_v4($potin_courant, $id_user, $bdd); $retour['id_potin'] = $id_nouveau_potin; echo $retour['potin']; //echo json_encode($retour); }
<?php /** Et si l'utilisateur a dejà débloqué le potin ? */ include_once 'modele/notifications.php'; include_once 'modele/infos_potin.php'; include_once 'modele/appartient_au_groupe.php'; $infos_notif = infos_notif($_GET['id_notif'], $bdd); if ($id_user == $infos_notif['id_user']) { notif_vue($_GET['id_notif'], $bdd); // L'user a vu la notification if (appartient_au_groupe($id_user, groupe_du_potin($_GET['id_potin'], $bdd), $bdd)) { $potin_courant = infos_potin($_GET['id_potin'], $bdd); include 'vue/afficher_potin_brouille.php'; } else { echo 'Vous ne pouvez accéder à ce potin'; } }
} else { $nb_potins_a_decouvrir = $nb_potins_sur_user_ds_gp_courant; } if ($nb_potins_a_decouvrir > 0) { if (calculer_points($id_user, $bdd) >= 20) { $tous_potins = tous_potins_sur_user_ds_gpe($id_groupe, $id_concerne); if ($potins_decouverts != 0) { // Il faut les retirer des autres $potins_cherches = array_diff($tous_potins, $potins_decouverts); } else { // Sinon on prend tous les potins $potins_cherches = $tous_potins; } // On choisit un potin au hasard dans ceux qu'on a pas encore découverts $potin_au_pif = $potins_cherches[array_rand($potins_cherches)]; $potin_decouvert = infos_potin($potin_au_pif, $bdd); // On enregistre le potin comme découvert potin_externe_decouvert($potin_decouvert['id_Potin']); $reponse_potin = vue_affichage_potin($potin_decouvert, $id_user, $bdd); $reponse_message = 'succes'; } else { $reponse_message = 'pas_points'; } } else { $reponse_message = 'pas_potins'; } } else { $reponse_message = 'non_autorise'; } // Construction de la réponse JSON $reponse['potin'] = $reponse_potin;