Ejemplo n.º 1
0
function deleteTruck(&$db, $id)
{
    if (empty($id)) {
        return false;
    }
    // bail if no id present
    $query = "DELETE FROM trucks WHERE id = '{$id}'";
    // will return false if query error or true if it worked
    return process_query($db, $query);
}
Ejemplo n.º 2
0
function lcm_query_db($query, $accept_fail = false)
{
    global $lcm_mysql_link;
    static $tt = 0;
    $my_debug = $GLOBALS['sql_debug'];
    $my_profile = $GLOBALS['sql_profile'];
    /* [ML] I have no idea whether this is overkill, but without it,
    	   we get strange problems with Cyrillic and other non-latin charsets.
    	   We need to check whether tables were installed correctly, or else
    	   it will not show non-latin utf8 characters correctly. (i.e. for
    	   people who upgraded LCM, but didn't import/export their data to 
    	   fix the tables.)
    	*/
    if (read_meta('db_utf8') == 'yes') {
        lcm_mysql_set_utf8();
    } elseif (!read_meta('db_utf8') == 'no' && !read_meta('lcm_db_version')) {
        // We are not yet installed, so check MySQL version on every request
        // Note: checking is is_file('inc/data/inc_meta_cache.php') is not
        // enough, because the keywords cache may have been generated, but not
        // the meta.
        if (!preg_match("/^(4\\.0|3\\.)/", mysql_get_server_info())) {
            lcm_mysql_set_utf8();
        }
    }
    $query = process_query($query);
    if ($my_profile) {
        $m1 = microtime();
    }
    if ($GLOBALS['mysql_recall_link'] and $lcm_mysql_link) {
        $result = mysql_query($query, $lcm_mysql_link);
    } else {
        $result = mysql_query($query);
    }
    if ($my_debug and $my_profile) {
        $m2 = microtime();
        list($usec, $sec) = explode(" ", $m1);
        list($usec2, $sec2) = explode(" ", $m2);
        $dt = $sec2 + $usec2 - $sec - $usec;
        $tt += $dt;
        echo "<small>" . htmlentities($query);
        echo " -> <font color='blue'>" . sprintf("%3f", $dt) . "</font> ({$tt})</small><p>\n";
    }
    if ($my_debug) {
        lcm_debug("QUERY: {$query}\n", 1, 'sql');
    }
    if (lcm_sql_errno() && !$accept_fail) {
        $s = lcm_sql_error();
        $error = _T('warning_sql_query_failed') . "<br />\n" . htmlentities($query) . "<br />\n";
        $error .= "&laquo; " . htmlentities($s) . " &raquo;<br />";
        lcm_panic($error);
    }
    return $result;
}
 /**
  * Increments the number of times a profile has been viewed in the database.
  * Yay storing user data!
  */
 public function increment_profile_view_counter()
 {
     $viewer_id = $this->viewer_user->user_row["UserID"];
     $viewed_id = $this->viewed_user->user_row["UserID"];
     // God I hate these sql queries
     $sql_query = 'INSERT INTO ' . Constant::profile_views_database_name . ' VALUES ';
     $sql_query .= '(' . $viewer_id . ', ' . $viewed_id . ', 1)';
     $sql_query .= ' ON DUPLICATE KEY UPDATE `ProfileViews` = `ProfileViews` + 1;';
     $connection = create_connection();
     // process the query
     process_query($sql_query, $connection);
     close_connection($connection);
 }
Ejemplo n.º 4
0
function lcm_query_db($query, $accept_fail = false)
{
    global $lcm_pgsql_link;
    global $lcm_pgsql_error;
    static $tt = 0;
    $my_debug = $GLOBALS['sql_debug'];
    $my_profile = $GLOBALS['sql_profile'];
    $lcm_pgsql_error = "";
    $query = process_query($query);
    if ($my_profile) {
        $m1 = microtime();
    }
    if ($GLOBALS['mysql_recall_link'] and $lcm_pgsql_link) {
        $result = pg_query($query, $lcm_pgsql_link);
    } else {
        $result = pg_query($query);
    }
    if ($my_debug and $my_profile) {
        $m2 = microtime();
        list($usec, $sec) = explode(" ", $m1);
        list($usec2, $sec2) = explode(" ", $m2);
        $dt = $sec2 + $usec2 - $sec - $usec;
        $tt += $dt;
        echo "<small>" . htmlentities($query);
        echo " -> <font color='blue'>" . sprintf("%3f", $dt) . "</font> ({$tt})</small><p>\n";
    }
    if ($my_debug) {
        lcm_debug("QUERY: {$query}\n", 1, 'sql');
    }
    if (!$result) {
        $err = lcm_sql_error();
        if (!$accept_fail) {
            $error = _T('warning_sql_query_failed') . "<br />\n" . htmlentities($query) . "<br />\n";
            $error .= "&laquo; " . htmlentities($err) . " &raquo;<br />";
            lcm_panic($error);
        }
        $lcm_pgsql_error = $err;
        lcm_log("sql failed: {$err}");
    }
    return $result;
}
 /**
  * @param $user_id int The id of the user whose user row to retrieve from the database.
  * @return array The array containing the row of the user, if it exists.
  */
 public static function get_user_row_by_id($user_id)
 {
     $sql_query = 'SELECT * FROM `' . Constant::user_database_name . '` ';
     $sql_query .= 'WHERE UserID="' . $user_id . '";';
     $connection = create_connection();
     // the user row with the particular id; it could be empty
     $user_row = process_query($sql_query, $connection, MYSQLI_ASSOC);
     // close the connection before exiting the function
     close_connection($connection);
     // returns an empty array if the user row doesn't exists
     return empty($user_row) ? array() : $user_row;
 }
Ejemplo n.º 6
0
        if (empty($id)) {
            // display feedback and bail
            echo '<p>Error: Invalid ID.</p>';
            break;
            // terminate case
        }
        // get truck info by id
        $query = "SELECT \r\n\t\t\t\t\ttrucks.number, \r\n\t\t\t\t\tdrivers.name AS driver, \r\n\t\t\t\t\tclients.name AS client \r\n\t\t\t\t  FROM trucks \r\n\t\t\t\t  LEFT JOIN drivers ON trucks.driver_id = drivers.id \r\n\t\t\t\t  LEFT JOIN clients ON trucks.client_id = clients.id \r\n\t\t\t\t  WHERE trucks.id = '{$id}'\r\n\t\t\t\t ";
        $truck = process_query($db, $query);
        if ($truck === false) {
            break;
        }
        $truck = $truck->fetch_assoc();
        // get location info
        $query = "SELECT \r\n\t\t\t\t\tactivity.log_date, \r\n\t\t\t\t\tactivity.mile_post \r\n\t\t\t\t  FROM activity \r\n\t\t\t\t  WHERE activity.truck_id = {$id} \r\n\t\t\t\t  ORDER BY activity.log_date DESC \r\n\t\t\t\t  LIMIT 1 \r\n\t\t\t\t ";
        $location = process_query($db, $query);
        if ($location === false) {
            break;
        }
        $location = $location->fetch_assoc();
        // display info
        ?>
		<h1>Truck Details</h1>
		<h2>Truck #<?php 
        echo $truck['number'];
        ?>
</h2>
		<p>
			<strong>Driver:</strong> 
			<span><?php 
        echo $truck['driver'];
Ejemplo n.º 7
0
        $uiid = urldecode($value);
    }
}
//$prompt = "";
$responseMessage = "";
if ($message != "" && $uiid != "") {
    $ref = "";
    $content = "";
    $cmd = parseCommand($message, $ref, $content);
    $responseMessage = "parseCommand returns [" . $cmd . "] ref=[" . $ref . "] content=[" . $content . "]";
    $con = dbopen();
    if ($cmd == "lg") {
        $responseMessage = process_list_groups($con, $uiid, 0);
    } else {
        if ($cmd == "query") {
            $responseMessage = process_query($con, $uiid, $ref, $content);
        } else {
            if ($cmd == "ans") {
                $responseMessage = process_answer($con, $uiid, $ref, $content);
            } else {
                if ($cmd == "lq") {
                    $responseMessage = process_list_queries($con, $uiid, $ref, $content);
                    // ref for groupId, content for queryId
                } else {
                    if ($cmd == "la") {
                        $responseMessage = process_list_answers($con, $uiid, $ref, $content, 0);
                    } else {
                        if ($cmd == "next") {
                            $responseMessage = process_list_next($con, $uiid);
                        } else {
                            if ($cmd == "fg") {
Ejemplo n.º 8
0
    }
    $tweet = array("id" => $id, "text" => $text, "time_of_tweet" => $time_of_tweet, "lang" => $lang);
    $tweets_array[$id] = $tweet;
    build_reverse_index($tweet);
}
fclose($fp);
print_r($inverted_index);
$tfx = tf("say", "494633625082548224");
echo $tfx;
exit;
$stdin = fopen("php://stdin", "r");
while (1) {
    echo "Enter the search string\n";
    $input_query = fgets($stdin);
    $input_query = trim($input_query);
    process_query($input_query);
}
function build_reverse_index($tweet)
{
    global $inverted_index;
    //print_r($tweet);
    $tweet_id = $tweet['id'];
    $text = $tweet['text'];
    //replace comma, semicolon etc
    $text = str_replace(",", " ", $text);
    $text = str_replace(":", " ", $text);
    $text = str_replace("...", " ", $text);
    $text = str_replace("..", " ", $text);
    $words = explode(" ", $text);
    foreach ($words as $word) {
        $word = process_word($word);
 /**
  * Increments the number of times the user has logged in.
  */
 public function increment_login_counter()
 {
     $user_id = $this->user_row[0]["UserID"];
     $sql_query = 'INSERT INTO `' . Constant::login_count_database_name . '`(`UserID`, `LoginTimes`) ';
     $sql_query .= 'VALUES (' . $user_id . ', 1) ON DUPLICATE KEY UPDATE ';
     $sql_query .= '`LoginTimes` = `LoginTimes` + 1;';
     $connection = create_connection();
     process_query($sql_query, $connection);
     close_connection($connection);
     return $sql_query;
 }
Ejemplo n.º 10
0
 // EDIT no break added intentionally
 case 'ADD':
     // add a new row to the database table
     // get list of unassigned drivers
     // the simplest way to do this is to left join
     // trucks to drivers and look for driver rows
     // where truck fields are NULL
     // (outer joins are not supported in MySQL)
     $query = "\r\n\t\t\tSELECT \r\n\t\t\t\tdrivers.id, \r\n\t\t\t    drivers.name\r\n\t\t\tFROM drivers \r\n\t\t\tLEFT JOIN trucks ON drivers.id = trucks.driver_id \r\n\t\t\tWHERE trucks.id IS NULL\r\n\t\t";
     $drivers = process_query($db, $query);
     if ($drivers === false) {
         break;
     }
     // get list of clients
     $query = "\r\n\t\t\tSELECT \r\n\t\t\t\tclients.id, \r\n\t\t\t    clients.name\r\n\t\t\tFROM clients \r\n\t\t";
     $clients = process_query($db, $query);
     if ($clients === false) {
         break;
     }
     include 'trucks-form.php';
     break;
     // ADD
 // ADD
 case 'PROCESS':
     // update database
     // preprocess data
     // validate data
     $isValidData = true;
     // innocent until proven guilty
     $validationMessages = '';
     // test that number is a numeric value
Ejemplo n.º 11
0
    return true;
}
function process_query()
{
    $upload_dir = '../img/';
    $upload_url_dir = '/img/';
    $upload_file = false;
    try {
        $new_name = rand(0, PHP_INT_MAX) . '.jpg';
        $upload_file = $upload_dir . basename($_FILES['image']['name']);
        move_uploaded_file($_FILES['image']['tmp_name'], $upload_file);
        if (!resize_img($upload_file, $upload_dir . $new_name)) {
            throw new Exception();
        } else {
            $data = $upload_url_dir . $new_name;
            $label = 'url';
            $status = RESPONSE_STATUS_OK;
        }
    } catch (Exception $e) {
        $data = 'file is not image of .jpg .gif .png formats';
        $label = 'error';
        $status = RESPONSE_STATUS_FAIL;
    } finally {
        if ($upload_file) {
            unlink($upload_file);
        }
    }
    api_echo_as_json($data, $label, $status);
}
process_query();
                if ($in_query && $line[2] == 'Q') {
                    // # Query_time: 0  Lock_time: 0  Rows_sent: 0  Rows_examined: 156
                    $numbers = explode(': ', substr($line, 12));
                    $query_time = array((int) $numbers[1], (int) $numbers[2], (int) $numbers[3], (int) $numbers[4]);
                    $in_query = $query_time[0] >= $min_query_time || $min_rows_examined && $query_time[3] >= $min_rows_examined;
                }
            }
        }
    } else {
        if ($in_query) {
            $query .= $line;
        }
    }
}
if ($query) {
    process_query($queries, $query, $no_duplicates, $user, $host, $timestamp, $query_time, $ls);
}
if ($queries && $no_duplicates) {
    if ($con) {
        $db_queries = array();
        foreach ($con->query("SELECT * FROM queries") as $row) {
            $db_queries[$row[1]] = $row[0];
        }
        $db_query_id = 1;
        if ($db_queries) {
            $db_query_id = max($db_queries) + 1;
        }
        $db_hosts = array();
        foreach ($con->query("SELECT * FROM hosts") as $row) {
            $db_hosts[$row[1]] = $row[0];
        }
    if ($row = $result->fetch_assoc()) {
        $uiid = $row["id"];
        $userid = $row["userid"];
        //echo "<b>$uiid $userid</b><br>Phone: $phone<br>City: $city<br>Country: $country<br><hr><br>";
    }
    $i++;
}
$responseMessage = "";
include "bpwelcome.php";
if (strlen($responseMessage) == 0) {
    //echo "\n user_body = " . $user_body . "\n";
    if (startsWith($user_body, "lg:")) {
        $responseMessage = process_group($con);
    } else {
        if (startsWith($user_body, "query:")) {
            $responseMessage = process_query($con, $user_body, $uiid);
        } else {
            if (startsWith($user_body, "ans:")) {
                $responseMessage = process_answer($con, $user_body, $uiid);
            } else {
                if (startsWith($user_body, "lq:")) {
                    //echo "---lq\n";
                    $responseMessage = process_list_queries($con, $user_body, $uiid);
                } else {
                    if (startsWith($user_body, "la:")) {
                        $responseMessage = process_list_answers($con, $user_body, $uiid);
                    } else {
                        if (startsWith($user_body, "next:")) {
                            $responseMessage = process_list_next($con, $user_body, $uiid);
                        } else {
                            if (startsWith($user_body, "fg:")) {