Example #1
0
}
for ($j = 0; $j < $NUMBER_OF_GROUPS; $j++) {
    // Pick a random course
    $course_id = mt_rand(1, $max_course_id);
    $course = get_course($db, $course_id);
    $name = "Random {$course['title']} group";
    $day = random_day();
    $time = random_time();
    $place = random_place();
    $groupquery->bindValue(":course_id", $course_id);
    $groupquery->bindValue(":name", $name);
    $groupquery->bindValue(":day", $day);
    $groupquery->bindValue(":time", $time);
    $groupquery->bindValue(":place", $place);
    $groupquery->execute();
    $group_id = $db->lastInsertId();
    // Add members
    $nmembers = mt_rand($NUMBER_OF_MEMBERS_MIN, $NUMBER_OF_MEMBERS_MAX);
    $useridids = random_select($nmembers, 0, count($userids) - 1);
    foreach ($useridids as $i) {
        if (!is_taking($userids[$i], $course_id)) {
            $classquery->bindValue(":course_id", $course_id);
            $classquery->bindValue(":user_id", $userids[$i]);
            $classquery->execute();
        }
        $memberquery->bindValue(":group_id", $group_id);
        $memberquery->bindValue(":user_id", $userids[$i]);
        $memberquery->execute();
    }
}
echo "Done";
    }
    $statement->closeCursor();
    //second we check for mask concordance
    $items = validate_from_network($conf, $items, $checker);
    $items = validate_from_regex($conf, $items, $checker);
    //third and last we randomly choose an item
    if (count($items) > 0) {
        $max = count($items);
        $index = rand(0, $max);
        while (!isset($items[$index])) {
            $index = rand(0, $max);
        }
        return $items[$index];
    } else {
        error_log("Unable to define a valid item for the checker :" . $checker . ". You should review your configuration.", 0);
        return null;
    }
}
$pdo = connexionbdd($conf);
$var = random_select($pdo, $checker, $conf);
if ($var != null) {
    $host_explode = explode(':', $var['item']);
    if (count($host_explode) == 3) {
        $array = array("host" => $host_explode[0], "protocole" => $host_explode[1], "port" => $host_explode[2], "string" => "");
    } else {
        $array = array("host" => $host_explode[0], "protocole" => $host_explode[1], "port" => $host_explode[2], "string" => $host_explode[3]);
    }
    $json = json_encode($array);
    increment($var['item'], $pdo);
    echo $json;
}