示例#1
0
} else {
    $access = array();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $action = $_POST['action'];
    $gid = $_POST['group_id'];
    $name = $_POST['name'];
    $permission = $_POST['permission'];
    $error = array();
    if (strlen($name) < 3 || strlen($name) > 20) {
        $error['name'] = $lang['error_group_name'];
    }
    if (empty($error)) {
        if ($action == "insert") {
            $insert_data = array('name' => $name, 'permission' => $permission);
            $insert_query = insertGroup($insert_data);
            if ($insert_query) {
                $_SESSION['success'] = $lang['success_insert'];
                header('Location:user_group.html');
            } else {
                $error_warning = $lang['error_query'];
            }
        } else {
            if ($action == "update") {
                echo "y" . $group_id;
                $edit_data = array('groupId' => $gid, 'name' => $name, 'permission' => $permission);
                $edit_query = editGroup($edit_data);
                if ($edit_query) {
                    $_SESSION['success'] = $lang['success_edit'];
                    header('Location:user_group.html');
                } else {
function creerTournoi($nbPairByGroup, $idTournament, $pluie, $dbh)
{
    // var_dump($nbPairByGroup);
    // var_dump($idTournament);
    // var_dump($pluie);
    // echo "-----------------players    ";
    $players = getSoloPlayers($idTournament, $dbh);
    // print_r(count($players));
    // echo "-----------------pairs    ";
    $pairs = makingPair($players);
    // print_r(count($pairs));
    // echo "-----------------insert    ";
    insertPairs(transformPairsToDb($pairs, $idTournament, $dbh), $dbh);
    // echo "-----------------cours :    ";
    $cours = getAllCourts($idTournament, $pluie, $dbh);
    // print_r(count($cours));
    // echo "-----------------pairs :    ";
    $pairs = getPairs($idTournament, $dbh);
    // print_r(count($pairs));
    // echo "-----------------groups :    ";
    $nbGroup = 0;
    //n-1
    $group = [];
    while (!empty($pairs)) {
        // echo "[GROUP START NUM=".$nbGroup."]";
        // echo "pairs = ".count($pairs);
        $group[$nbGroup]['pairs'] = getXPairByRank($pairs, array_shift($pairs), $nbPairByGroup);
        $group[$nbGroup]['leader'] = getLeaderOfGroup($group[$nbGroup]['pairs']);
        // echo "COUNT___________".count($group[$nbGroup]['pairs'])."__________COUNT";
        // var_dump($group[$nbGroup]['pairs']);
        //var_dump($group[$nbGroup]['leader']);
        // echo "pairs = ".count($pairs);
        $key = array_search($group[$nbGroup]['pairs'][1], $pairs);
        unset($pairs[$key]);
        /*foreach ($group[$nbGroup]['pairs'] as $p) {
            $key = array_search($p, $pairs);
            unset($pairs[$key]);
          }*/
        // echo "pairs = ".count($pairs);
        // echo "[GROUP END NUM = ".$nbGroup."]";
        $nbGroup++;
    }
    // var_dump(count($group));
    // die('GROUPS');
    // echo "-----------------groups and cours :    ";
    set_time_limit(0);
    foreach ($group as $k => $g) {
        $courtTmp = getNearCours($cours, $g['pairs'], $dbh);
        $key = array_search($courtTmp, $cours);
        unset($cours[$key]);
        $group[$k]['court_fk'] = $courtTmp;
        $groupTmp = ['court_fk' => $courtTmp['idcourts'], 'tournament_fk' => $idTournament];
        if (!is_null($g['leader'])) {
            $groupTmp['leader'] = $g['leader'];
        }
        $idGroup = insertGroup($groupTmp, $dbh);
        $group[$k]['group_id'] = $idGroup;
        foreach ($g['pairs'] as $kPair => $valuePair) {
            addGroupFkPair($valuePair['idpairs'], $idGroup, $dbh);
            $group[$k]['pairs'][$kPair]['joueur1'] = getPlayerById($valuePair['user_j1_fk'], $dbh);
            $group[$k]['pairs'][$kPair]['joueur2'] = getPlayerById($valuePair['user_j2_fk'], $dbh);
        }
    }
    return $group;
}
示例#3
0
    if (!isset($_POST['gname']) || $_POST['gname'] == "") {
        $err['gname'] = "Please enter your group name";
    }
    // don't allow 01:00:50
    if ($_POST['gin_hrs'] != 0 && $_POST['gin_min'] == 0 && $_POST['gin_sec'] != 0) {
        $err['gin_err'] = "Please make sure minute is set if hour and second is set.";
    }
    // don't allow 01:00:50
    if ($_POST['gout_hrs'] != 0 && $_POST['gout_min'] == 0 && $_POST['gout_sec'] != 0) {
        $err['gout_err'] = "Please make sure minute is set if hour and second is set.";
    }
    $data['gin'] = $_POST['gin_hrs'] . ":" . $_POST['gin_min'] . ":" . $_POST['gin_sec'];
    $data['gout'] = $_POST['gout_hrs'] . ":" . $_POST['gout_min'] . ":" . $_POST['gout_sec'];
    // if no error
    if (empty($err)) {
        if (insertGroup($data, $db)) {
            echo "<script>alert('User group successfully added')</script>";
        } else {
            header("location: " . ROOT . "error.html");
            exit;
        }
    } else {
        echo "<script>alert('Enter group name, hours, minutes and seconds corrrectly.')</script>";
    }
}
// *** edit group ***
if (isset($_POST['gedit']) && $_POST['gedit'] == "true" && $_POST['gedit'] != "") {
    $data['gname'] = trim($_POST['gname']);
    $data['gin'] = trim($_POST['gin']);
    $data['gout'] = trim($_POST['gout']);
    $data['gid'] = trim($_POST['gid']);