31, 2=>28+date('L'), 3=>31, 4=>30, 5=>31, 6=>30, 7=>31, 8=>31, 9=>30, 10=>31, 11=>30, 12=>31); $fin_mois = mktime(23, 59, 59, $num_mois, $dernier_jour[$num_mois], $annee); $bornes = array($debut_mois, $fin_mois); return $bornes; } //Return what A must pay to B function dettes($A, $B, $debut_mois, $fin_mois) { global $bdd; //When A paid and B was here $reqA_B = $bdd->prepare('SELECT id, date, montant, copains, invites FROM depenses WHERE date>'.$debut_mois.' AND date<'.$fin_mois.' AND de=:param1 AND (copains LIKE "%,'.(int) $B.',%" OR copains LIKE "%,'.(int)$B.'" OR copains LIKE "'.(int) $B.',%" OR copains LIKE "'.(int) $B.'")'); $reqA_B->bindvalue(':param1',$A); $reqA_B->execute(); //When B paid and A was here $reqB_A = $bdd->prepare('SELECT id, date, montant, copains, invites FROM depenses WHERE date>'.$debut_mois.' AND date<'.$fin_mois.' AND de=:param1 AND (copains LIKE "%,'.(int) $A.',%" OR copains LIKE "%,'.(int)$A.'" OR copains LIKE "'.(int) $A.',%" OR copains LIKE "'.(int) $A.'")'); $reqB_A->bindvalue(':param1',$B); $reqB_A->execute(); //What A already paid to B for the current month $reqPaiementsA_B = $bdd -> prepare('SELECT paiements.montant AS montant FROM paiements LEFT JOIN depenses ON paiements.id_depense=depenses.id WHERE depenses.date >'.$debut_mois.' AND depenses.date<'.$fin_mois.' AND paiements.de=:de AND paiements.a=:a'); $reqPaiementsA_B->bindvalue(':de',$A); $reqPaiementsA_B->bindvalue(':a',$B); $reqPaiementsA_B->execute(); //Same thing for B to A $reqPaiementsB_A = $bdd -> prepare('SELECT paiements.montant AS montant FROM paiements LEFT JOIN depenses ON paiements.id_depense=depenses.id WHERE depenses.date >'.$debut_mois.' AND depenses.date<'.$fin_mois.' AND paiements.de=:de AND paiements.a=:a'); $reqPaiementsB_A->bindvalue(':de',$B); $reqPaiementsB_A->bindvalue(':a',$A); $reqPaiementsB_A->execute(); //$deltaAB : What A must pay to B $deltaAB = 0; while($donneesA_B = $reqA_B->fetch()) { //We get the price of the meal, divided by the number of people who ate //nbre de virgule + 1 $deltaAB -= $donneesA_B['montant']/(substr_count($donneesA_B['copains'], ',') + 1 + $donneesA_B['invites']); } while($donneesB_A = $reqB_A->fetch()) //idem { $deltaAB += $donneesB_A['montant']/(substr_count($donneesB_A['copains'], ',') + 1 + $donneesB_A['invites']); } while($donneesPaiementsA_B = $reqPaiementsA_B->fetch()) //idem { $deltaAB -= $donneesPaiementsA_B['montant']; } while($donneesPaiementsB_A = $reqPaiementsB_A->fetch()) //idem { $deltaAB += $donneesPaiementsB_A['montant']; } return $deltaAB; } if(isset($_GET['del'])) //If we want to delete an expenditure { if(empty($_GET['valide']) OR empty($_GET['token']) OR $_GET['token'] != $_SESSION['token_del_depense'] OR $_SESSION['token_del_depense_time'] < time() - (15*60) OR strpos($_SERVER['HTTP_REFERER'], 'http://'.$CONFIG['base_url'].'/index.php') > 0 OR strpos($_SERVER['HTTP_REFERER'], 'https://'.$CONFIG['base_url'].'/index.php') > 0) //If we didn't click the link to validate the deletion and the token is not valid (not present or older than 15 minutes) or if the referer is not ok { $_SESSION['token_del_depense'] = sha1(uniqid(rand(), true)); //We generate a token and store it in a session variable $_SESSION['token_del_depense_time'] = time(); //We also store the time at which the token has been generated $lien = 'index.php?del='.$_GET['del'] .'&valide=1&token='.$_SESSION['token_del_depense']; ?>
Confirmer la suppression ou Retour
query('DELETE FROM depenses WHERE id='.$id); $bdd->query('DELETE FROM paiements WHERE id_depense='.$id); header('location: message.php?id=1'); exit(); } //This get all the friends' name (we need it next) $req2 = $bdd->query('SELECT id, nom FROM copains ORDER BY nom ASC'); while($copain = $req2->fetch()) { $copains[$copain['id']] = $copain['nom']; //And put it in an array } $req_jeu = $bdd->prepare('SELECT COUNT(*) AS nbre_jeu FROM depenses WHERE de=:de'); $req_jeu->bindValue(':de', $_SESSION['id']); $req_jeu->execute(); $donnees_jeu = $req_jeu->fetch(); //To define wether we display the game or not //SESSION token for the update of what people must pay to us (modif.php) $_SESSION['token_validate_single'] = sha1(uniqid(rand(), true)); //We generate a token and store it in a session variable $_SESSION['token_validate_single_time'] = time(); //We also store the time at which the token has been generated ?>xxxxx xXXXXXXXXXx XXXXXXXXXXXXX xXXXXXXXX XXXx XXXXXXXXX 0XXXX\\\\\\ xXXXXXXXXXxxXXXX\\\\\\\ XXXXXXXXXXXXXXXX////// \ XXXXXXXXXXXXXXXXX XXXXX|\XXX/|XXXXX XXXXX| \-/ |XXXXX xXXXXX| [ ] |XXXXXx xXXXX | /-\ | XXXXx xXXXXX |/ \| XXXXXx xXXXXXX XXXXXXx xXXXXXXX XXXXXXXx xXXXXXXXX XXXXXXXXx xXXXXXXXXX XXXXXXXXXx xXXXXXXXXXX XXXXXXXXXXx xXXXXXXXXXXX XXXXXXXXXXXx xXXXXXXXX XXX XXX XXXXXXXXx XXXXXXXX XXX XXX XXXXXXXX xXXXXXXX XXX XXX XXXXXXXx XXXXXX XXX XXX XXXXXX XXXX XXX XXX XXXX XX XXX XXX XX XXX XXX XXX XXX XXX XXX XXX XXX XXXx xXXX XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX XXXXXXX ____XXXXXX XXXXXX____ /________/ \________\'; exit(); } else { $_SESSION['aClique_time'] = time(); } } ?>
Ajouter une dépense | Modifier le mot de passe | Consulter les remboursements | Gérer les remboursements | Modifier les copains | Modifier l'annonce d'accueil | Déconnexion
Lire "ligne" doit "case"€ à "colonne". Les liens permettent de confirmer le paiement des dettes.
Doit\À | '.$copain.''; echo ''.$copain.' | '; } ?>|
---|---|---|
'.$copainA.' | '; foreach($copains as $keyB=>$copainB) { $deltaAB = dettes($keyA,$keyB, $debut_mois, $fin_mois); if(round($deltaAB,2) <= 0) echo '- | '; else { echo '' . round($deltaAB, 2) . '€ | '; $lien_valider_tous[$keyB] = 1; } } echo '
Validation | '; foreach($copains as $key=>$copain) { if(($_SESSION['nom'] == $copain OR $_SESSION['admin'] == 1) && !empty($lien_valider_tous[$key])) echo 'Confirmer paiements | '; else echo ''; } echo ' |
Date | Payé par | Copains | Montant | Menu | Modifier | Supprimer |
---|---|---|---|---|---|---|
'.$date.' | '.$copains[(int) $donnees["de"]].' | '.$copains_in.$invites.' | '.(float) $donnees['montant'].'€ | '.nl2br(htmlspecialchars($donnees["menu"])).' | '.$modif_link.' | '.$suppr_link.' |
N\'afficher que les dépenses du dernier mois.'; } else { echo 'Afficher toutes les dépenses'; } ?>
= 1 || $_SESSION['admin'] == 1 || $_SESSION['nom'] == 'Alexandre') //Bonus : display a "My little Poney" game { ?>