$cfg = array('DB_HOST', 'DB_USER', 'DB_PASS', 'DB_NAME');
loadConfig($cfg);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    echo "post: ";
    //Ok we got a POST, read from $_POST.
    $v = $_POST['content'];
    $threshold = $_POST['threshold'];
    if (!is_numeric($threshold)) {
        $threshold = 600.0;
        // default
    }
    if (is_numeric($v)) {
        if ((double) $v > $threshold) {
            insertToDB("Hello");
        } elseif ((double) $v <= $threshold) {
            insertToDB("World");
        }
    }
}
// Very simple loader
function loadConfig($vars = array())
{
    foreach ($vars as $v) {
        define($v, get_cfg_var("mHealth.cfg.{$v}"));
    }
}
// Insert into database
function insertToDB($content)
{
    // Create connection
    $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
Example #2
0
    $w_string = '<?php
							define ("DB_SERVER",   "' . $servername . '"); 
							define ("DB_LOGIN",    "' . $username . '"); 
							define ("DB_PASSWORD", "' . $password . '"); 
							define ("DB_NAME",     "' . $database . '");
						?>';
    $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/config.php", "w");
    fwrite($fp, $w_string);
    fclose($fp);
}
$clients_data_json = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/clients_data.json");
$tv_program_data_json = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/tv_program_data.json");
$advertisement_data_json = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/advertisement_data.json");
$clients_data = json_decode($clients_data_json, true);
$tv_program_data = json_decode($tv_program_data_json, true);
$advertisement_data = json_decode($advertisement_data_json, true);
insertToDB($clients_data, 'clients', $db);
insertToDB($tv_program_data, 'tv_program', $db);
insertToDB($advertisement_data, 'advertisement', $db);
function insertToDB($data, $table, $db)
{
    $str = "";
    for ($i = 0, $l = count($data); $i < $l; $i++) {
        foreach ($data[$i] as $key => $value) {
            $str .= "'" . $value . "',";
        }
        $db->query("INSERT " . $table . " VALUES (" . trim($str, ",") . ")");
        echo trim($str, ",") . "</br>";
        $str = "";
    }
}
Example #3
0
    $w_string = '<?php
							define ("DB_SERVER",   "' . $servername . '"); 
							define ("DB_LOGIN",    "' . $username . '"); 
							define ("DB_PASSWORD", "' . $password . '"); 
							define ("DB_NAME",     "' . $database . '");
						?>';
    $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/config.php", "w");
    fwrite($fp, $w_string);
    fclose($fp);
}
$users_data_json = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/users_data.json");
$calls_data_json = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/calls_data.json");
$tariffs_data_json = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/tariffs_data.json");
$users_data = json_decode($users_data_json, true);
$calls_data = json_decode($calls_data_json, true);
$tariffs_data = json_decode($tariffs_data_json, true);
insertToDB($users_data, 'users', $db);
insertToDB($tariffs_data, 'tariffs', $db);
insertToDB($calls_data, 'calls', $db);
function insertToDB($data, $table, $db)
{
    $str = "";
    for ($i = 0, $l = count($data); $i < $l; $i++) {
        foreach ($data[$i] as $key => $value) {
            $str .= "'" . $value . "',";
        }
        $db->query("INSERT " . $table . " VALUES (" . trim($str, ",") . ")");
        echo trim($str, ",") . "</br>";
        $str = "";
    }
}
Example #4
0
<?php

/* Candralab Ecommerce v2.0
 * http://www.candra.web.id/
 * Candra adi putra <*****@*****.**>
 * last edit: 15 okt 2013
 */
?>

<?php 
session_start();
require_once '../inc/config.php';
require_once '../inc/function.php';
require_once '../chart/chart.inc.php';
$idpelanggan = $_SESSION['idpelanggan'];
/* menambahkan kode pesan dan detail pesan kedalam database*/
$kd_transaksi = kd_transaksi();
$total_bayar = $_SESSION['totalbayar'];
insertToDB($kd_transaksi, $idpelanggan, $total_bayar);
unset($_SESSION['chart']);
//check if query successful
$link = "location:../index.php?mod=chart&pg=finish&total_bayar={$total_bayar}&kd_transaksi={$kd_transaksi}";
header($link);
Example #5
0
function my_push()
{
    $rawData = gzinflate(substr(file_get_contents('php://input'), 10, -8));
    $postedJson = json_decode($rawData, true);
    if (json_last_error() != JSON_ERROR_NONE) {
        error_log('Last JSON error: ' . json_last_error() . json_last_error_msg() . PHP_EOL . PHP_EOL, 0);
    }
    try {
        $dbPDO = dbConnect(0, array("SET SESSION wait_timeout = 300;"));
    } catch (PDOException $e) {
        die("DB error, try again.");
    }
    foreach ($postedJson['d'] as $post) {
        if (!isset($post['data'], $post['exec_time'], $post['id'], $post['status'], $post['type'])) {
            die("Wrong parameters");
        }
        if (!is_numeric($post['exec_time'])) {
            die("Wrong parameters");
        }
        //    print "working with ". $post['id'] .PHP_EOL; flush();
        if ($post['type'] == "page") {
            //Is it a stage one crawl.
            update_page($post['id'], $post['exec_time'], $post['data']);
            continue;
        }
        if ($post['status'] != "done") {
            //For some reason the agent did not complete, switch trough error messages and try to react.
            if (isset($post['error_msg'])) {
                if (strpos($post['error_msg'], "(#21)") !== false) {
                    //We got a error 21 "Page ID <old> was migrated to page ID <new>"
                    continue;
                }
                if (strpos($post['error_msg'], "Unsupported get request") !== false) {
                    //We got a error 21 "Page ID <old> was migrated to page ID <new>"
                    $sql = "UPDATE post SET status = 'removed'" . ", who = INET_ATON(" . $dbPDO->quote($_SERVER["REMOTE_ADDR"]) . ") " . ", time = " . $post['exec_time'] . ", time_stamp = UNIX_TIMESTAMP()" . " WHERE page_fb_id = " . $dbPDO->quote(strstr($post['id'], '_', true)) . " AND " . " post_fb_id= " . $dbPDO->quote(substr(strstr($post['id'], '_'), 1)) . "; ";
                    $result = $dbPDO->exec($sql);
                    //if($query != 1)
                    //die("DB error, try again.");
                    continue;
                }
            }
            $sql = "INSERT IGNORE INTO pull_posts VALUES (" . $dbPDO->quote(strstr($post['id'], '_', true)) . "," . ($post['type'] == "page" ? "0" : $dbPDO->quote(substr(strstr($post['id'], '_'), 1))) . ");";
            $result = $dbPDO->exec($sql);
            continue;
        }
        //Make sure that we already have the posts file in the DB.
        $sql = "SELECT page_fb_id, post_fb_id, CONCAT(page_fb_id , '_' , DATE_FORMAT(date,'%Y-%m-%dT%H'),'_',page_fb_id,'_',post_fb_id,'.json')" . " AS fname, REPLACE(name,' ','_') AS archive, fb_id FROM post,page WHERE page_fb_id=fb_id AND page_fb_id=" . $dbPDO->quote(strstr($post['id'], '_', true)) . " AND post_fb_id=" . $dbPDO->quote(substr(strstr($post['id'], '_'), 1));
        $result = $dbPDO->query($sql);
        if ($row = $result->fetchAll()[0]) {
            $archive = realpath(dirname(__FILE__)) . '/phar/' . preg_replace('/[^[:alnum:]]/', '_', $row['archive']) . '-' . $row['fb_id'];
            //Lock archive, this lock will be released when we get a new lock or close connection.
            $lock = $dbPDO->query("SELECT GET_LOCK(" . $dbPDO->quote($archive) . ", 30);")->fetchAll()[0][0];
            if ($lock != 1) {
                //Unable to get lock.
                die("Unable to get lock for: " . $archive);
            }
            if (!phar_put_contents($row['fname'], $archive, $post['data'])) {
                die("Unable to write the file: " . $row['fname']);
            }
            //continue; //We did not manage to write to our phar archive, try with next post.
            $sql = "UPDATE post SET status = 'done'" . ", who = INET_ATON(" . $dbPDO->quote($_SERVER["REMOTE_ADDR"]) . ") " . ", time = " . $post['exec_time'] . ", time_stamp = UNIX_TIMESTAMP()" . " WHERE page_fb_id = " . $row['page_fb_id'] . " AND " . " post_fb_id= " . $row['post_fb_id'] . "; ";
            $query = $dbPDO->exec($sql);
            if ($query != 1) {
                die("DB error, try again.");
            }
            /*
             * Insert into db
             */
            $db = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, MYSQL_PORT);
            if ($db->connect_error) {
                error_log('Connect Error F (' . $db->connect_errno . ') ' . $db->connect_error, 0);
                continue;
            }
            $GLOBALS['db'] =& $db;
            try {
                insertToDB(parseJsonString($post['data']), $db);
                $db->close();
            } catch (Exception $e) {
                error_log("Parse Error (" . $post['id'] . ") " . $e->getMessage() . " in " . $e->getFile() . ":" . $e->getLine(), 0);
            }
        } else {
            die("No post with id {$post_id} in db");
        }
    }
    print "Pushed to db.\n";
    return;
}