示例#1
0
 public function upd_resa()
 {
     global $wpdb;
     if (isset($_POST["pl_adulte_upd"]) && isset($_POST["pl_enfant_upd"])) {
         if (!is_numeric($_POST["post_id_upd"])) {
             $upd = z;
         } else {
             if ($_POST["pl_adulte_upd"] == 0 && $_POST["pl_enfant_upd"] == 0) {
                 $upd = 2;
             } else {
                 $post_id = $_POST["post_id_upd"];
                 $current_user = wp_get_current_user();
                 $id_user = $current_user->ID;
                 $user_rank = $user->roles[0];
                 $nb_place_dispo = get_post_meta($post_id, '_nb_place', true);
                 $query2 = $wpdb->get_results("SELECT * FROM cjm_reservation WHERE id_evenement = {$post_id} AND id_participant = {$id_user}");
                 $ancien_nb_place = $query2[0]->nbplace + $query2[0]->nbplace_enf;
                 $prix_total = getPrixTotal($post_id, intval($_POST["pl_adulte_upd"]), intval($_POST["pl_enfant_upd"]), $user_rank);
                 if ($nb_place_dispo + $ancien_nb_place < $_POST["pl_adulte_upd"] + $_POST["pl_enfant_upd"]) {
                     $upd = 3;
                 } else {
                     if (get_post_meta($post_id, '_etat_resa', true) == 'file_attente') {
                         $bool = 1;
                     } else {
                         $bool = 0;
                     }
                     $query = $wpdb->update(cjm_reservation, array('nbplace' => esc_attr($_POST["pl_adulte_upd"]), 'nbplace_enf' => esc_attr($_POST["pl_enfant_upd"]), 'paiement' => 0, 'prix_total' => $prix_total, 'liste_attente' => $bool, 'date_resa' => date("d-m-Y H:i:s")), array('id_participant' => $id_user, 'id_evenement' => $_POST["post_id_upd"]));
                     if ($query == 1) {
                         $nb_place_maj = $nb_place_dispo + $ancien_nb_place - intval(esc_attr($_POST["pl_adulte_upd"])) - intval(esc_attr($_POST["pl_enfant_upd"]));
                         $query = update_post_meta($post_id, '_nb_place', $nb_place_maj);
                     }
                     if ($query == 1) {
                         $isSent = MailSender::send_email_ins_modif($current_user->user_login, true, $post_id);
                     }
                     $upd = 1;
                 }
             }
         }
         echo json_encode($upd);
     }
     wp_die();
 }
    $_COOKIE["nbPlaces"] = $_POST['nbPlaces'];
    setcookie("place", $_POST['place'], time() + 86400);
    $_COOKIE["place"] = $_POST['place'];
    setcookie("idMatch", $_GET['id'], time() + 86400);
    $_COOKIE["idMatch"] = $_GET['id'];
    $placesOk = nbPlacesOk($_COOKIE["idMatch"], $_COOKIE["nbPlaces"], $_COOKIE["place"]);
    if ($placesOk >= 0) {
        header('Location: place.php?id=' . $_GET["id"] . "&err=2&nbRest=" . $placesOk);
    }
} else {
    if (isset($_GET['red'])) {
    } else {
        header('Location: place.php?id=' . $_GET["id"] . "&err=1");
    }
}
$prix = getPrixTotal($_COOKIE["idMatch"], $_COOKIE["place"], $_COOKIE["nbPlaces"]);
//A chaque fois qu'on retourne sur la page, le prix total est réinitiatisé, et modifié par la suite si un réduction a été appliquée
setcookie("prix", $prix, time() + 86400);
$_COOKIE["prix"] = $prix;
$bdd = Connect_db();
$SQL_Query = 'SELECT jourMatch as j, heureMatch as h, typeMatch as t FROM Matchs WHERE idMatch = ' . $_COOKIE["idMatch"];
$query = $bdd->prepare($SQL_Query);
$query->execute();
while ($line = $query->fetch()) {
    setcookie("jourMatch", $line["j"], time() + 86400);
    $_COOKIE["jourMatch"] = $line["j"];
    setcookie("heureMatch", $line["h"], time() + 86400);
    $_COOKIE["heureMatch"] = $line["h"];
    setcookie("typeMatch", $line["t"], time() + 86400);
    $_COOKIE["typeMatch"] = $line["t"];
}
示例#3
0
function save_metabox($post_id)
{
    global $wpdb;
    if ($_POST["post_type"] != "reservation") {
        return;
    } else {
        if (isset($_POST['date_debut']) && isset($_POST['date_fin']) && isset($_POST['nom_voyage']) && isset($_POST['nb_place']) && isset($_POST['nb_place_total']) && isset($_POST['etat_resa']) && isset($_POST['tarif_adulte']) && isset($_POST['tarif_adherent']) && isset($_POST['tarif_enfant'])) {
            $tarif_adulte = get_post_meta($post_id, "_tarif_adulte", true);
            $tarif_enfant = get_post_meta($post_id, "_tarif_enfant", true);
            $tarif_adherent = get_post_meta($post_id, "_tarif_adherent", true);
            if ($tarif_adulte != $_POST['tarif_adulte'] || $tarif_enfant != $_POST['tarif_enfant'] || $tarif_adherent != $_POST['tarif_adherent']) {
                update_post_meta($post_id, '_tarif_adulte', $_POST['tarif_adulte']);
                update_post_meta($post_id, '_tarif_enfant', $_POST['tarif_enfant']);
                update_post_meta($post_id, '_tarif_adherent', $_POST['tarif_adherent']);
                $select = $wpdb->get_results("select id_resa,nbplace,nbplace_enf,id_participant,mail_confirm from cjm_reservation where id_evenement=" . $post_id);
                foreach ($select as $key => $value) {
                    $user = get_user_by('ID', $value->id_participant);
                    $value->role = $user->roles[0];
                }
                $select1 = $wpdb->get_results("select id_resa,nbplace,nbplace_enf,role from cjm_reservation_ext where id_evenement=" . $post_id);
                $select = array_merge($select, $select1);
                foreach ($select as $key => $value) {
                    if (!is_null($value->mail_confirm)) {
                        $query = $wpdb->update("cjm_reservation", array("prix_total" => getPrixTotal($post_id, $value->nbplace, $value->nbplace_enf, $value->role)), array("id_resa" => $value->id_resa), array("%d"), array('%d'));
                    } else {
                        $query = $wpdb->update("cjm_reservation_ext", array("prix_total" => getPrixTotal($post_id, $value->nbplace, $value->nbplace_enf, $value->role)), array("id_resa" => $value->id_resa), array("%d"), array('%d'));
                    }
                }
            }
            update_post_meta($post_id, '_date_debut', $_POST['date_debut']);
            update_post_meta($post_id, '_date_fin', $_POST['date_fin']);
            update_metadata('post', $post_id, '_nb_place', $_POST['nb_place']);
            // fait la même chose,juste pour le test :)
            update_post_meta($post_id, '_nb_place_total', $_POST['nb_place_total']);
            update_post_meta($post_id, '_nom_voyage', $_POST['nom_voyage']);
            update_post_meta($post_id, '_etat_resa', $_POST['etat_resa']);
        }
    }
}
示例#4
0
 public function modif_resa()
 {
     global $wpdb;
     $error = "";
     if (isset($_POST["id"]) && isset($_POST["nbplace"]) && isset($_POST["nbplace_enf"]) && isset($_POST["tel"]) && isset($_POST["id_user"]) && isset($_POST["table"]) && !empty($_POST["id"]) && !empty($_POST["tel"]) && !empty($_POST["id_user"])) {
         $table = "";
         if (!empty($_POST["table"])) {
             $select = $wpdb->get_results("SELECT id_evenement,nbplace,nbplace_enf,role,liste_attente FROM cjm_reservation_ext WHERE id_resa=" . $_POST["id"]);
             $resquery = $wpdb->update('cjm_reservation_ext', array('tel' => $_POST["tel"], 'nbplace' => intval($_POST["nbplace"]), 'nbplace_enf' => intval($_POST["nbplace_enf"]), "prix_total" => getPrixTotal($select[0]->id_evenement, intval($_POST["nbplace"]), intval($_POST["nbplace_enf"]), $select[0]->role)), array('id_resa' => intval($_POST["id"])), array('%s', '%d', '%d'), array('%d'));
             if ($resquery == 1 && $select[0]->liste_attente == 0) {
                 $curr_nbplace = intval(get_post_meta(intval($select[0]->id_evenement), "_nb_place", true));
                 $nbplace_maj = $curr_nbplace + intval($select[0]->nbplace) + intval($select[0]->nbplace_enf) - intval($_POST["nbplace"]) - intval($_POST["nbplace_enf"]);
                 $resquery = update_post_meta(intval($select[0]->id_evenement), "_nb_place", $nbplace_maj);
             } else {
                 $error .= "pas d'update ";
             }
             if ($resquery == false) {
                 $error .= "nbplace pas MAJ ";
             }
         } else {
             $select = $wpdb->get_results("SELECT id_evenement,nbplace,nbplace_enf,id_participant,liste_attente\n          FROM cjm_reservation\n          WHERE id_resa=" . $_POST["id"]);
             $user = get_userdata($select[0]->id_participant);
             $resquery = $wpdb->update("cjm_reservation", array("nbplace" => intval($_POST["nbplace"]), "nbplace_enf" => intval($_POST["nbplace_enf"]), "prix_total" => getPrixTotal($select[0]->id_evenement, intval($_POST["nbplace"]), intval($_POST["nbplace_enf"]), $user->roles[0])), array("id_resa" => intval($_POST["id"])));
             if ($resquery == 1 && $select[0]->liste_attente == 0) {
                 $curr_nbplace = intval(get_post_meta(intval($select[0]->id_evenement), "_nb_place", true));
                 $nbplace_maj = $curr_nbplace + intval($select[0]->nbplace) + intval($select[0]->nbplace_enf) - intval($_POST["nbplace"]) - intval($_POST["nbplace_enf"]);
                 $resquery = update_post_meta(intval($select[0]->id_evenement), "_nb_place", $nbplace_maj);
             } else {
                 $error .= "pas d'update nbplace";
             }
             if ($resquery == false) {
                 $error .= "MAJ nbplace didnt work";
             }
             $resquery = $wpdb->update("cjm_usermeta", array("meta_value" => $_POST["tel"]), array("meta_key" => "tel", "user_id" => intval($_POST["id_user"])), array('%s'), array('%s', '%d'));
             if ($resquery == false) {
                 $error .= "MAJ du tel didnt work";
             }
         }
         $values = array("id_resa" => $_POST["id"], "nbplace_adl" => $_POST["nbplace"], "nbplace_enf" => $_POST["nbplace_enf"], "tel" => $_POST["tel"], "id_user" => $_POST["id_user"], "nom_table" => $_POST["table"], "select" => $select[0], "query" => $resquery, "nbplace_maj" => $nbplace_maj, "current_nbplace" => $curr_nbplace, "user" => $user);
         $res = array("error" => $error, "valeurs" => $values);
         echo json_encode($res);
     } else {
         echo json_encode($values);
     }
     wp_die();
 }