$query_count = 0;
$link = mysql_connect($server, $dbuser, $dbpass);
mysql_select_db($database);
function file_get_data($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //Set curl to return the data instead of printing it to the browser.
    curl_setopt($ch, CURLOPT_URL, $url);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
$raw = file_get_data('http://backpack.tf/api/IGetPrices/v4/?key=' . $bptf_api_key . '&compress=1&raw=1') or die('Error connecting');
$prices = json_decode($raw, true);
if ($prices['response']['success'] == 0) {
    die('Error recieved from backpack.tf: ' . $prices['response']['message']);
}
foreach ($prices['response']['items'] as $itemname => $obj) {
    // Ugly, but completes in about 0.2 seconds.
    $defindexes = $obj['defindex'];
    foreach ($obj['prices'] as $quality => $tradable) {
        foreach ($tradable as $tradable => $craftable) {
            foreach ($craftable as $craftable => $priceindex) {
                // Priceindex = crate series or unusual effect. 0 otherwise.
                foreach ($priceindex as $effect => $stats) {
                    foreach ($defindexes as $defindex) {
                        $prepare[] = array('defindex' => $defindex, 'quality' => $quality, 'effect' => $effect, 'value' => $stats['value'], 'last_change' => $stats['difference'], 'last_update' => $stats['last_update'], 'currency' => $stats['currency'], 'value_raw' => $stats['value_raw'], 'tradable' => $tradable, 'craftable' => $craftable);
                    }
$link = mysql_connect($server, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
function file_get_data($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //Set curl to return the data instead of printing it to the browser.
    curl_setopt($ch, CURLOPT_URL, $url);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
/* Keep in mind, this raw data is > 3MB */
$raw = file_get_data('http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=' . $steam_api_key . '&language=en_US') or die('Error connecting');
$all = json_decode($raw, true);
if (!$all['result']) {
    die("Error retrieving item schema from steampowered API.");
}
foreach ($all['result'] as $key => $value) {
    if ($key == "items") {
        foreach ($value as $item) {
            // Paintcans are a special case, so we can get the color information.
            if ($item['tool']['type'] == "paint_can") {
                foreach ($item['attributes'] as $attribute) {
                    if ($attribute['class'] == "set_item_tint_rgb" || $attribute['class'] == "set_item_tint_rgb_2") {
                        $rgb[] = str_pad(dechex($attribute['value']), 6, "0", STR_PAD_LEFT);
                        // Hex code in decimal converted to 6-digit hex.
                    }
                }
$date = date("M-d-Y_H-i-s");
$backupname = "{$url}-backup-{$date}.zip";
// Check for newer versions of script
function file_get_data($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
$latest_version = file_get_data('https://raw.github.com/jeremehancock/cron-backup-script-setup/master/version.txt');
$latest_version = preg_replace("/\r|\n/", "", $latest_version);
if (!isset($installed_version)) {
    echo "New version available!\nTo update simply re-install following instructions found here: http://www.rackspace.com/knowledge_center/article/scheduled-backup-cloud-sites-to-cloud-files\n";
} elseif ($installed_version < $latest_version) {
    echo "New version available!\nTo update simply re-install following instructions found here: http://www.rackspace.com/knowledge_center/article/scheduled-backup-cloud-sites-to-cloud-files\n";
}
if ($db_backup == "true") {
    // Check mysql database credentials
    $db_connection = mysql_connect($db_host, $db_user, $db_password);
    if (!$db_connection) {
        echo date("h:i:s") . " -- Database connection failed! Check your database credentials in the cron-backup-config.php file.\n";
        die;
    } else {
        // Dump the mysql database
        echo date("h:i:s") . " -- Starting database dump...\n";