Пример #1
0
function crawl($tname, $year, $monthArr)
{
    $dealType = $GLOBALS['dealType'];
    $stateArr = $GLOBALS['stateArr'];
    if ($monthArr == null) {
        die("monthArr must be set!");
    }
    $period = intval(($monthArr[0] - 1) / 3) + 1;
    echo "Working on {$year} ({$period}) " . implode(" ", $monthArr) . "\n";
    $db = new mysqli("p:localhost", "trend", "only!trend!", "rtrend");
    // Check connection
    if ($db->connect_error) {
        die("Connection failed: " . $db->connect_error);
    }
    // Set utf8
    //$db->set_charset("utf8");
    if (!isset($dealType[$tname])) {
        die("No args for {$tname}\n");
    }
    // get deal type and table name
    $args = $dealType[$tname];
    foreach ($stateArr as $state => $stateCode) {
        echo "Working on {$year} ({$period}) on {$state} for {$tname}\n";
        $cities = getCities($year, $period, $stateCode, $args);
        $cityArr = json_decode($cities, true);
        foreach ($cityArr['jsonList'] as $city) {
            $counties = getCounties($year, $period, $stateCode, $city['CODE'], $args);
            $countyArr = json_decode($counties, true);
            foreach ($countyArr['jsonList'] as $county) {
                $deals = getDeals($year, $period, $stateCode, $city['CODE'], $county['CODE'], $args);
                $dealArr = json_decode($deals, true);
                foreach ($monthArr as $month) {
                    // echo("Working on $year/$month ($period) on $state " . $city['NAME'] . " " . $county['NAME'] . "\n");
                    $infoArr = ['year' => $year, 'month' => $month, 'state' => $state, 'city' => $city['NAME'], 'county' => $county['NAME']];
                    // update
                    // function update($db, $tname, $metaArr, $json) {
                    update($db, $tname, $infoArr, $deals);
                }
            }
        }
    }
    // make aggregation
    foreach ($monthArr as $month) {
        echo "Make agg {$tname} on {$year}/{$month}";
        mkagg($db, $tname, $year, $month);
    }
    $db->close();
}
<?php

include_once "../libs/start.php";
if (isset($_POST['get_option'])) {
    $option = addslashes(htmlspecialchars(trim($_POST['get_option'])));
    $counties = getCounties($option);
    $map_found = foundCity($option);
    if ($option === "1") {
        echo "<div class='sel seld-old'>\n\t\t\t\t\t\t<span class='sel seld-old-title' data-b='select-county'>Округа</span>\n\n\t\t\t\t\t\t<div class='all-city' data-b='all-counties-dropdown'>\n\t\t\t\t\t\t\t<p>Выберите округ(а)</p>\n\n\t\t\t\t\t\t\t<div class='checkbox all'>\n\t\t\t\t\t\t\t\t<label>\n\t\t\t\t\t\t\t\t\t<input class='ch' type='checkbox' value='all'>\n\t\t\t\t\t\t\t\t\t<span class='checkbox_box'></span>\n\t\t\t\t\t\t\t\t\t<span class='lab'>Все округа</span>\n\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t</div>";
    }
    for ($i = 0; $i < count($counties); $i++) {
        $id_county = $counties[$i]['id_county'];
        $county_name = $counties[$i]['county_name'];
        $map = $counties[$i]['map'];
        $yandex = $counties[$i]['yandex'];
        echo "\t\t<div class='checkbox'>\n\t\t\t\t\t\t\t\t<label>\n\t\t\t\t\t\t\t\t\t<input class='ch' type='checkbox' name='test' id='{$id_county}' value='{$county_name}'>\n\t\t\t\t\t\t\t\t\t<span class='checkbox_box'></span>\n\t\t\t\t\t\t\t\t\t<span class='lab'>{$county_name}</span>\n\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t</div>";
    }
    if ($option === "1") {
        echo "<div class='btn-rounded'>Ок</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>";
    }
    // Проверяем есть ли карта у города
    for ($i = 0; $i < count($map_found); $i++) {
        $id_map = $map_found[$i]['id_city'];
        $map = $map_found[$i]['map'];
        $yandex = $map_found[$i]['yandex'];
        if ($map != '') {
            echo "<div class='count-sel-and-map'>\n\t\t\t\t\t\t\t<span>Выбрано районов: <strong>0</strong></span>\n\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\t<a name='modal' href='#dialog{$option}'>\n\t\t\t\t\t\t\t\t\tВыбрать округа и районы на карте\n\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</div>";
        } else {
            echo "<div class='count-sel-and-map'>\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\t<a name='yandex' href='#yandex{$option}'>\n\t\t\t\t\t\t\t\t\tПоказать на карте\n\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</div>";
        }
    }
							<option value=""> Any </option>
							<?php 
$systems = getSystems();
foreach ($systems as $system) {
    echo '<option value="' . $system['college_system'] . '">' . $system['college_system'] . '</option>';
}
?>
					</select></td>
				</tr>
				<tr>
					<td>County:</td>
					<td>
						<select name="county"> 
							<option value=""> Any </option>
							<?php 
$counties = getCounties();
foreach ($counties as $county) {
    echo '<option value="' . $county['county'] . '">' . $county['county'] . '</option>';
}
?>
						</select>
					</td>
				</tr>
				<tr>
					<td>Number of Students:</td>
					<td>
						<select name="maxStudents">
							<option value=""> Any </option>
							<option value="10000"> less than 10,000</option>
							<option value="25000"> less than 25,000</option>
							<option value="100000"> over 25,000</option>