Example #1
0
function weather_generate()
{
    global $db;
    // get regions
    $regions = getRegions();
    // get weather
    $weather = weather_getWeatherWonders();
    foreach ($regions as $region) {
        if (!$region['startRegion']) {
            weather_log('Skipping unused region %s.', $region['name']);
            continue;
        }
        weather_log('Processing region %s.', $region['name']);
        // pick a random weather
        $regionweather = $weather[array_rand($weather)];
        weather_log('Selected Weather: %s', $regionweather->name);
        // save weather information in DB
        $sql = $db->prepare("UPDATE " . REGIONS_TABLE . "\n                         SET weather = :weather\n                         WHERE regionID = :regionID");
        $sql->bindValue('weather', $regionweather->weatherID, PDO::PARAM_INT);
        $sql->bindValue('regionID', $region['regionID'], PDO::PARAM_INT);
        if (!$sql->execute()) {
            weather_log('Failed to execute query: %s', $query);
            return -1;
        }
        $sql = $db->prepare("INSERT INTO " . EVENT_WEATHER_TABLE . "\n                         (regionID, weatherID, impactID, start, end)\n                         VALUES (:regionID, :weatherID, :impactID, :start, :end)");
        foreach ($regionweather->impactList as $impactID => $impact) {
            $delay = (int) ($impact['delay'] * WEATHER_TIME_BASE_FACTOR);
            $now = time();
            $sql->bindValue('regionID', $region['regionID'], PDO::PARAM_INT);
            $sql->bindValue('weatherID', $regionweather->weatherID, PDO::PARAM_INT);
            $sql->bindValue('impactID', $impactID, PDO::PARAM_INT);
            $sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
            $sql->bindValue('end', time_toDatetime($now + $delay), PDO::PARAM_STR);
            if (!$sql->execute()) {
                weather_log('Failed to execute query');
                return -1;
            }
        }
    }
}
Example #2
0
function weather_getReport()
{
    global $weatherTypeList;
    init_Weathers();
    $regions = getRegions();
    $template = tmpl_open($_SESSION['player']->getTemplatePath() . 'weather_report.ihtml');
    $tmp = true;
    foreach ($regions as $region) {
        $tmp = $tmp && $region[weather] == -1;
    }
    if ($tmp) {
        // no weather so far
        tmpl_set($template, 'CONTENT/NOWEATHER', array('iterate' => ''));
        return tmpl_parse($template);
    }
    $alt = 0;
    foreach ($regions as $region) {
        $alt = ($alt + 1) % 2;
        // alternates between 0 and 1. Couldn't use regionID, they don't need to be adjacent
        tmpl_iterate($template, 'CONTENT/WEATHER/ROW');
        tmpl_set($template, 'CONTENT/WEATHER/ROW', array('region' => $region['name'], 'weather' => $weatherTypeList[$region['weather']]->name, 'alternate' => $alt));
    }
    return tmpl_parse($template);
}
<?php

require_once "10.regions.php";
$regions = getRegions();
?>
<!DOCTYPE HTML PUBLIC
                 "-//W3C//DTD HTML 4.01 Transitional//EN"
                 "http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <title>Wines</title>
</head>
<body>
<form action="10.results.php" method="GET">
Region: 
<select name="regionName">
<?php 
foreach ($regions as $id => $name) {
    ?>
   <option value="<?php 
    echo $id;
    ?>
"><?php 
    echo $name;
    ?>
</option> 
<?php 
}
?>
</select>
Example #4
0
function readProjectFromCsv($fname)
{
    $result = [];
    $errors = [];
    $regions = getRegions();
    $data = file($fname);
    if (!$data) {
        return [false, ['Ошибка чтения файла проекта.']];
    }
    $result['name'] = isset($data[0]) ? trim(mb_convert_encoding($data[0], 'utf-8', 'windows-1251')) : '';
    $result['url'] = isset($data[1]) ? trim(mb_convert_encoding($data[1], 'utf-8', 'windows-1251')) : '';
    if ($result['name'] == '') {
        return [false, ['Не задано название проекта.']];
    }
    if ($result['url'] == '') {
        return [false, ['Не задан урл проекта.']];
    }
    $l = count($data);
    $result['regions'] = [];
    for ($i = 2; $i < $l; $i++) {
        if (empty($data[$i])) {
            break;
        }
        $line = trim(mb_convert_encoding($data[$i], 'utf-8', 'windows-1251'));
        if ($line == '') {
            break;
        }
        $result['regions'][] = [$line, $regions[$line]];
    }
    if (count($result['regions']) == 0) {
        $result['regions'][] = ['Москва', $regions['Москва']];
    }
    $i++;
    $result['keywords'] = [];
    for (; $i < $l; $i++) {
        if (empty($data[$i])) {
            break;
        }
        $line = trim(mb_convert_encoding($data[$i], 'utf-8', 'windows-1251'));
        if ($line == '') {
            break;
        }
        $result['keywords'][] = $line;
    }
    if (count($result['keywords']) == 0) {
        return [false, ['Не заданы ключевые слова проекта.']];
    }
    return [$result, $errors];
}
function getRegions($countries)
{
    getInCycle('getRegions', $countries, 'country_id', 'regions');
}
function getCities($countries)
{
    getInCycle('getCities', $countries, 'country_id', 'cities');
}
function getUniversities($cities)
{
    getInCycle('getUniversities', $cities, 'city_id', 'universities');
}
function getSchools($cities)
{
    getInCycle('getSchools', $cities, 'city_id', 'schools');
}
function getFaculties($universities)
{
    getInCycle('getFaculties', $universities, 'university_id', 'faculties');
}
function getChairs($faculties)
{
    getInCycle('getChairs', $faculties, 'faculty_id', 'chairs');
}
getCountries();
getRegions('countries');
getCities('countries');
getUniversities('cities');
getFaculties('universities');
getChairs('faculties');
getSchools('cities');
Example #6
0
<?
Example #7
0
function weather_generate($db)
{
    global $db;
    // get regions
    $regions = getRegions();
    // get weather
    $weather = weather_getWeatherWonders($db);
    foreach ($regions as $region) {
        if (!$region['startRegion']) {
            weather_log('Skipping unused region %s.', $region['name']);
            continue;
        }
        weather_log('Processing region %s.', $region['name']);
        // pick a random weather
        $regionweather = $weather[array_rand($weather)];
        weather_log('Selected Weather: %s', $regionweather->name);
        // save weather information in DB
        $query = "UPDATE `Regions` " . "SET `weather` = {$regionweather->weatherID} " . "WHERE `regionID` = {$region['regionID']}";
        if (!$db->query($query)) {
            weather_log('Failed to execute query: %s', $query);
            return -1;
        }
        foreach ($regionweather->impactList as $impactID => $impact) {
            $delay = (int) (($delayDelta + $impact['delay']) * WEATHER_TIME_BASE_FACTOR);
            $now = time();
            $query = sprintf("INSERT INTO Event_weather " . "(`regionID`, `weatherID`, `impactID`, `start`, `end`) " . "VALUES (%d, %d, %d, '%s', '%s')", $region['regionID'], $regionweather->weatherID, $impactID, time_toDatetime($now), time_toDatetime($now + $delay));
            if (!$db->query($query)) {
                weather_log('Failed to execute query: %s', $query);
                return -1;
            }
        }
    }
}
Example #8
0
function getReceivers($db)
{
    $receivers = array();
    if (isset($_POST["users_ids"]) && $_POST["users_ids"] != "") {
        print "Spacific ids = " . $_POST["users_ids"] . "<br>";
        $arr = explode(";", $_POST["users_ids"]);
        $ids = "";
        for ($i = 0; $i < count($arr); $i++) {
            if ($arr[$i] != "") {
                if ($i == 0) {
                    $ids = "id=" . $arr[$i];
                } else {
                    $ids .= " or id=" . $arr[$i];
                }
            }
        }
        $result = $db->getUsersOfCond($ids);
        while ($row = mysql_fetch_array($result)) {
            $receivers[] = $row["registration_id"];
            print "selected  = " . $row["registration_id"] . "<br>";
        }
        if (count($receivers) > 0) {
            return $receivers;
        }
    }
    $send_method = $_POST["send_method"];
    if (!isset($_POST["send_method"])) {
        $send_method = 1;
    }
    switch ($send_method) {
        case 1:
            $result = $db->getAllUsers();
            while ($row = mysql_fetch_array($result)) {
                $receivers[] = $row["registration_id"];
            }
            break;
        case 2:
            $users = getRegions();
            for ($i = 0; $i < count($users); $i++) {
                $subusers = $db->getUsersByRegionId($users[$i]);
                while ($row = mysql_fetch_array($subusers)) {
                    $receivers[] = $row["registration_id"];
                }
            }
            /*
                        if(count($receivers) == 0){
                            $result = $db->getAllUsers();
                            while ($row = mysql_fetch_array($result)){
                                $receivers[] = $row["registration_id"];
                            }
                        }*/
            break;
        case 3:
            $users = getLangs();
            for ($i = 0; $i < count($users); $i++) {
                $subusers = $db->getUsersByLangId($users[$i]);
                while ($row = mysql_fetch_array($subusers)) {
                    $receivers[] = $row["registration_id"];
                }
            }
            /*
                        if(count($receivers) == 0){
                            $result = $db->getAllUsers();
                            while ($row = mysql_fetch_array($result)){
                                $receivers[] = $row["registration_id"];
                            }
                        }*/
            break;
    }
    return $receivers;
}
Example #9
0
function addNewRegionsToDb()
{
    $regionsData = getRegions();
    insertRegions($regionsData);
}
<?php

$method = $_POST['method'];
if ($method == "getRegions") {
    getRegions();
} else {
    if ($method == "getMatch") {
        getMatch($_POST['region'], $_POST['match_id']);
    }
}
/**
 * Function returns all regions analysed
 * Scan directory
 * @return Array with regions
 */
function getRegions()
{
    $dir = 'resources/bilgewater_matchID';
    $files = array_diff(scandir($dir), array('..', '.'));
    $regions = array();
    foreach ($files as $file) {
        array_push($regions, strtolower(explode(".", $file)[0]));
    }
    echo json_encode($regions);
}
/**
 * Function returns stats for one game
 * Launch a request to RIOT API
 * Update BDD
 */
function getMatch($region, $id)