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']; ?> Bouffe@Ulm

Validation de la suppression du repas

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 ?> Bouffe@Ulm = 1 || $_SESSION['admin'] == 1) { ?>

Bouffe@Ulm

                     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

Qui doit quoi ?

Lire "ligne" doit "case"€ à "colonne". Les liens permettent de confirmer le paiement des dettes.

'.$copain.''; echo ''; } ?> $copainA) { if($_SESSION['nom'] == $copainA) $copainA = ''.$copainA.''; echo ''; foreach($copains as $keyB=>$copainB) { $deltaAB = dettes($keyA,$keyB, $debut_mois, $fin_mois); if(round($deltaAB,2) <= 0) echo ''; else { echo ''; $lien_valider_tous[$keyB] = 1; } } echo ''; } echo ''; foreach($copains as $key=>$copain) { if(($_SESSION['nom'] == $copain OR $_SESSION['admin'] == 1) && !empty($lien_valider_tous[$key])) echo ''; else echo ''; } echo ''; ?>
Doit\À '.$copain.'
'.$copainA.'-' . round($deltaAB, 2) . '€
ValidationConfirmer paiements
Dépenses détaillées du mois actuel'; else echo '

Dépenses détaillées

'; //Then we display all the expenditures ?> query('SELECT id, menu, date, de, copains, montant, invites FROM depenses WHERE date>'.$debut_mois.' AND date<'.$fin_mois.' ORDER BY '.$_GET['tri'].' '.$_GET['sens'].', date DESC'); } else { $req = $bdd->query('SELECT id, menu, date, de, copains, montant, invites FROM depenses WHERE date>'.$debut_mois.' AND date<'.$fin_mois.' ORDER BY date DESC'); } while($donnees = $req->fetch()) { //Date (AM/PM) $AM_PM = array('AM'=>'le midi', 'PM'=>'le soir'); $date = date('j/m', $donnees['date']).' '.$AM_PM[date('A', $donnees['date'])]; $id = (int) $donnees['id']; $copains_in_array_id = explode(',', $donnees['copains']); //List of friends who ate (array) $copains_in = ''; $nombre_participants = count($copains_in_array_id); $req_paiements = $bdd->query('SELECT de, montant FROM paiements WHERE id_depense='.$id); //List of who paid yet $paiements = array(); $montants = array(); while($paiement = $req_paiements->fetch()) { // We use an array to store the list of friends who paid and so to // avoir a useless 2D array search $paiements[$paiement['de']] = $paiement['de']; // If we already defined $montant[] if (isset($montants[$paiement['de']])) $montants[$paiement['de']] += $paiement['montant']; else $montants[$paiement['de']] = $paiement['montant']; } // Friend number 0 is none $copains[0] = "Tout seul"; $copains_in_array_name = array(); //Prepare an array with buddy names to sort it foreach($copains_in_array_id as $key=>$id_copain) { $copains_in_array_name[$key] = $copains[(int) $id_copain]; } asort($copains_in_array_name); $i = 0; // What to write in the friends cell foreach($copains_in_array_name as $key=>$copain) { $copains_in .= $copain; $id_copain = $copains_in_array_id[$key]; $keys = array_keys($paiements, $id_copain); if($id_copain != $donnees['de']) { $montant_du = (float) $donnees['montant']/(substr_count($donnees['copains'], ',') + 1 + $donnees['invites']); if(!empty($keys)) { if(round($montants[$keys[0]],2) == round($montant_du,2)) $copains_in .= ' (payé)'; else $copains_in .= ' (reste '.round($montant_du - $montants[$keys[0]],2).'€)'; } else $copains_in .= ' (reste '.round($montant_du,2).'€)'; } if($i != $nombre_participants-1) $copains_in .= '
'; $i++; } $invites = ''; if($donnees['invites'] == 1) $invites = '
'. (int) $donnees['invites'].' invité'; if($donnees['invites'] > 1) $invites = '
'. (int) $donnees['invites'].' invités'; //Only the admin and the one who paid the meal can edit it if((int) $donnees['de'] == $_SESSION['id'] || $_SESSION['admin'] == 1) { $modif_link = 'Modifier'; $suppr_link = 'Supprimer'; } else { $modif_link = ''; $suppr_link = ''; } echo ''; } $req->closeCursor(); ?>
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 { ?>