/**
 * Main function to insert radios in the database. Call auxiliary functions
 * to format the data that is going to be inserted for each radio.
 * 
 * @param array $data radio data from the csv file
 * @return void
 */
function insertRadio(array $data)
{
    global $row;
    //remove white spaces from the end and beggining of the strings
    $data = array_map('trim', $data);
    if (!empty($data[0])) {
        $name = addslashes($data[0]);
    } else {
        die("Mandatory field 'name' is empty in line {$row}\n");
    }
    $address = addslashes($data[1]);
    $city = addslashes($data[2]);
    $state = formatState($data[3]);
    $city_code = getCityCode($data[2], $state);
    $license = formatLicense($data[4]);
    list($latitude, $longitude) = formatCoordinates($data[5]);
    list($channel, $frequency) = formatChannelAndFrequency($data[6]);
    $identifier = $data[7];
    if (!empty($latitude) && !empty($longitude)) {
        $visible = 1;
    } else {
        $visible = 0;
    }
    $time = time();
    query("INSERT INTO radios_comunitarias (razao_social, endereco, cod_municipio, municipio, uf, latitude, longitude, canal, frequencia, indicador, visivel, licenca, created)\n\t\tVALUES ('{$name}', '{$address}', '{$city_code}', '{$city}', '{$state}', '{$latitude}', '{$longitude}', '{$channel}', '{$frequency}', '{$identifier}', '{$visible}', '{$license}', FROM_UNIXTIME({$time}))");
}
Example #2
0
 * Created by PhpStorm.
 * User: Alexey
 * Date: 03.09.2015
 * Time: 14:34
 */
echo '<head>';
echo '<link rel="stylesheet" type="text/css" href="../as/css/style.css">';
echo '</head>';
if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET['origin']) && isset($_GET['destination'])) {
    require_once "../as/aviasales.php";
    $origin = $_GET['origin'];
    $dest = $_GET['destination'];
    $compare = isset($_GET['compare']) ? (100 - $_GET['compare']) / 100 : 0.85;
    echo 'Highlighted <span class="highlighted">' . (1 - $compare) * 100 . '%+</span> below average<br><br>';
    $originIata = getCityCode($origin);
    $destIata = getCityCode($dest);
    $dates = array('2015-09', '2015-10', '2015-11', '2015-12', '2016-01', '2016-02', '2016-03', '2016-03');
    //$dates = array('2016-02');
    echo 'From: ' . $origin . '</br> To: ' . $dest . '</br></br>';
    //Table header
    echo '<table>';
    echo '<tr><th>Date</th><th>Price</th><th>Average</th><th>Transfers</th><th>Return at</th><th>Link</th></tr>';
    foreach ($dates as $date) {
        $calendar = getCalendar($originIata, $destIata, $date);
        $average = getAverage($originIata, $destIata, $date);
        if (array_key_exists('success', $calendar) && $calendar['success'] == 1 && array_key_exists('data', $calendar)) {
            $color = false;
            foreach ($calendar['data'] as $day => $data) {
                if ($color) {
                    echo '<tr class="colored">';
                } else {
Example #3
0
<?php

/**
 * Created by PhpStorm.
 * User: Alexey
 * Date: 03.09.2015
 * Time: 16:24
 */
if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET['origin']) && isset($_GET['destination']) && isset($_GET['date']) && isset($_GET['compare'])) {
    require_once "../as/aviasales.php";
    $origin = getCityCode($_GET['origin']);
    $destination = $_GET['destination'] ? getCityCode($_GET['destination']) : false;
    $date = $_GET['date'] ? $_GET['date'] : false;
    echo '<head>';
    echo '<link rel="stylesheet" type="text/css" href="../as/css/style.css">';
    echo '</head>';
    $compare = isset($_GET['compare']) ? (100 - $_GET['compare']) / 100 : 0.85;
    echo 'Highlighted <span class="highlighted">' . (1 - $compare) * 100 . '%+</span> below average<br><br>';
    $results = getCheap($origin, $destination, $date);
    //$average = getAverage($origin, $destination, $date);
    //echo print_r($cheap);
    if (array_key_exists('success', $results) && $results['success'] == 1 && array_key_exists('data', $results)) {
        echo '<table><tr><th>Direction</th><th>Airline</th><th>Date Departure</th><th>Date Return</th><th>Price Rub</th><th>Average Price</th></tr>';
        foreach ($results['data'] as $direction => $flights) {
            $color = false;
            foreach ($flights as $flight) {
                $departureDate = substr($flight['departure_at'], 0, 7);
                $returnDate = substr($flight['return_at'], 0, 7);
                $average = getAverage($origin, $direction, $departureDate);
                if ($color) {
                    echo '<tr class="colored">';
Example #4
0
     $this->init_settings();
     // This is part of the settings API. Loads settings you previously init.
     // Save settings in admin if you have any defined
     add_action('woocommerce_update_options_shipping_' . $this->id, array($this, 'process_admin_options'));
 }
 /**				 * calculate_shipping function.				 *				 * @access public				 * @param mixed $package				 * @return void				 */
 public function calculate_shipping($package = array())
 {
     //подключаем файл с классом CalculatePriceDeliveryCdek
     include_once TEMPLATEPATH . "/calc_deliv_cdek_js/CalculatePriceDeliveryCdek.php";
     try {
         //создаём экземпляр объекта CalculatePriceDeliveryCdek
         $calc = new CalculatePriceDeliveryCdek();
         //Авторизация. Для получения логина/пароля (в т.ч. тестового) обратитесь к разработчикам СДЭК -->						//$calc->setAuth('authLoginString', 'passwordString');
         if (isset($_REQUEST['calc_shipping'])) {
             foreach ($_REQUEST as $k => $v) {
                 $_SESSION[$k] = $_REQUEST[$k];
             }
         }
         $labb = 'Доставка';
         $res['result'] = 0;
         //устанавливаем город-отправитель
         $calc->setSenderCityId("152");
         //устанавливаем город-получатель
         $calc->setReceiverCityId($_SESSION['receiverCityId']);
         //устанавливаем дату планируемой отправки
         $calc->setDateExecute($_SESSION['dateExecute']);
         //устанавливаем тариф по-умолчанию
         $calc->setTariffId('11');
         //задаём список тарифов с приоритетами
         // $calc->addTariffPriority($_REQUEST['tariffList1']);
         // $calc->addTariffPriority($_REQUEST['tariffList2']);																										//устанавливаем режим доставки
         $calc->setModeDeliveryId($_SESSION['modeId']);
         //добавляем места в отправление
         $total_items = isset($_SESSION['total_items']) ? $_SESSION['total_items'] : 0;
         global $woocommerce;
         $total_weight = (int) $total_items * (double) $_SESSION['weight1'];
         $calc->addGoodsItemBySize($total_weight, $_SESSION['length1'], $_SESSION['width1'], $_SESSION['height1']);
         //$calc->addGoodsItemByVolume($_REQUEST['weight2'], $_REQUEST['volume2']);
         if ($calc->calculate() === true) {
             $res = $calc->getResult();
             //$res['result']['price'] = round( $res['result']['price'] +  $res['result']['price'], -1 );
             $pr = 5;
             // Проценты
             $labb = 'EMS';
             $code = getCityCode(trim(mb_strtolower($_SESSION['country'])));
             $total_items = isset($_SESSION['total_items']) ? $_SESSION['total_items'] : 0;
             if (sizeof($woocommerce->cart->get_cart()) > 0) {
                 foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
                     $total_items = (int) $values['quantity'];
                 }
             }
             $total_weight = (int) $total_items * (double) $_SESSION['total_items'];
             $total_weight = $_SESSION['total_items'] * 0.025;
             $json = file_get_contents("http://emspost.ru/api/rest?method=ems.calculate&from=city--kaliningrad&to={$code}&weight={$total_weight}");
             $rh = fopen('log.txt', 'a+');
             fputs($rh, $json . "\t" . $_SESSION['country'] . "\n");
             fputs($rh, $total_weight . "   " . $code . "\n");
             $json = json_decode($json);
             $json = $json->rsp;
             $aa = $json->price;
             $aa = round($aa);
             $aa = max($aa * 1.05, 790);
             $bbb = ceil($aa / 10) * 10;
             fclose($rh);
             if ($_SESSION['calc_tip'] == '2') {
                 $labb = 'Почта';
                 $res['result']['price'] = $woocommerce->cart->cart_contents_total * ($pr / 100);
                 $res['result']['price'] = max(min(1700, $res['result']['price']), 350);
                 $res['result']['price'] = round($res['result']['price'], -1);
                 $bbb = ceil($res['result']['price'] / 10) * 10;
             }
             //$bbb=$_SESSION['calc_tip'];
             if ($_SESSION['country'] == '444') {
                 $t = $total_weight;
                 switch (true) {
                     case $t > 0 and $t <= 1.5:
                         // дапазон чисел
                         $bbb = 1755;
                         break;
                     case $t > 1.5 and $t <= 3:
                         // дапазон чисел
                         $bbb = 2145;
                         break;
                     case $t > 3 and $t <= 6:
                         // дапазон чисел
                         $bbb = 2715;
                         break;
                     case $t > 6 and $t <= 11:
                         // дапазон чисел
                         $bbb = 3655;
                         break;
                     case $t > 11 and $t <= 16:
                         // дапазон чисел
                         $bbb = 4615;
                         break;
                     case $t > 16 and $t <= 20:
                         // дапазон чисел
                         $bbb = 5565;
                         break;
                 }
             }
             $html = array("Цена доставки: {$res['result']['price']}");
             if (array_key_exists('cashOnDelivery', $res['result'])) {
                 $html[] = "Ограничение оплаты наличными, от (руб): " . $res['result']['cashOnDelivery'];
             }
             //printf("<div class='woocommerce-message'>%s</div>", implode("<br/>", $html) );
         } else {
             $err = $calc->getError();
             if (isset($err['error']) && !empty($err)) {
                 print "<div class = 'woocommerce-error'>";
                 //var_dump($err);
                 foreach ($err['error'] as $e) {
                     echo 'Код ошибки: ' . $e['code'] . '.<br />';
                     echo 'Текст ошибки: ' . $e['text'] . '.<br />';
                 }
                 print "</div>";
             }
         }
         //раскомментируйте, чтобы просмотреть исходный ответ сервера
         // var_dump($calc->getResult());
         // var_dump($calc->getError());
         global $delta;
         $rate = array('id' => $this->id, 'label' => $labb, 'cost' => $bbb, 'calc_tax' => 'per_item');
         // Register the rate
Example #5
0
$destinations = getDestinations(5);
//Only include tariffs 80%+ cheaper then month average
$ratio = 0.7;
//Dates for next 6 months
$weekends = getWeekends(30);
//Table header
echo '<table>';
echo '<tr><th>Origin</th><th>Destination</th><th>Date</th><th>Days</th><th>Return at</th><th>Price</th><th>Average</th><th>Link</th></tr>';
$month = '';
foreach ($origins as $origin) {
    foreach ($destinations as $destination) {
        foreach ($weekends as $weekend) {
            foreach (array('Friday', 'Saturday') as $day) {
                //Get IATA codes
                $originIata = getCityCode($origin);
                $destIata = getCityCode($destination['destination_name']);
                if ($originIata && $destIata) {
                    //Define average rate for dest/month
                    $curMonth = date('Y-m', strtotime($weekend['Friday']));
                    if ($month != $curMonth) {
                        $month = $curMonth;
                        $calendar = getCalendar($originIata, $destIata, $curMonth);
                        $average = round(getAverageFromCalendar($calendar));
                    }
                    $cheap = getCheap($originIata, $destIata, $weekend[$day], $weekend['Sunday']);
                    if (array_key_exists('success', $cheap) && true == $cheap['success'] && array_key_exists('data', $cheap) && array_key_exists($destIata, $cheap['data'])) {
                        //loop through variants
                        foreach ($cheap['data'][$destIata] as $variant) {
                            $departure_at = date('Y-m-d H:i', strtotime($variant['departure_at']));
                            $return_at = date('Y-m-d H:i', strtotime($variant['return_at']));
                            $expires_at = $variant['expires_at'];