示例#1
0
function updateDatabase($dir, $db)
{
    $model = null;
    $mats = null;
    foreach (new RecursiveDirectoryIterator($dir) as $child) {
        if ($child->isDir()) {
            updateDatabase($child, $db);
        } else {
            // echo "<p>".$child->getPathname()."</p>";
            if (strpos($child->getPathname(), ".csbin") !== FALSE) {
                $model = $child->getPathname();
            } else {
                $mats = $child->getPathname();
            }
            if ($model && $mats) {
                $size = filesize($child->getPathname());
                $result = $db->query("SELECT meshId FROM Meshes WHERE fileName='{$model}' AND materialName='{$mats}'");
                // var_dump($result);
                $data = $result->fetch_array(MYSQL_ASSOC);
                // var_dump($data);
                if (!$data) {
                    $db->query("INSERT INTO Meshes VALUES (DEFAULT, '{$model}', '{$mats}', 0, 0, {$size})");
                } else {
                    $db->query("UPDATE Meshes SET fileSize={$size} WHERE fileName='{$model}' AND materialName='{$mats}'");
                }
                return;
            }
        }
    }
}
示例#2
0
 function update($table, $getters, $mysqli)
 {
     $params = array();
     if (!empty($getters)) {
         $params = $getters;
         $identifier = substr($table, 0, -1) . '_id';
         $controller = "user_id = " . $_SESSION['user_id'];
         updateDatabase($table, $identifier, $controller, $params, $mysqli);
     }
 }
示例#3
0
function check_update($dbname, $connection)
{
    date_default_timezone_set("Europe/Stockholm");
    /* Fetch the created time of the GeoIP table IP */
    $query = "SHOW TABLE STATUS FROM " . $dbname . " WHERE NAME='IP'  ";
    $result = mysqlQuery_Result($connection, $query);
    /* Check if the GeoIP table IP exists*/
    $if_exist = mysqli_num_rows($result);
    if ($if_exist == 0) {
        /* If the GeoIP table does not exist, we are going to update the database*/
        updateDatabase($if_exist, $connection);
        /* If the GeoIP table exist, we are going to check the created time*/
    } else {
        $row = mysqli_fetch_assoc($result);
        /* Get the created time with format ####-##-##, for example 2015-07-25 */
        $create_time = $row['Create_time'];
        /* Get the created time with format of Unix timestamp, for example 1437733146 */
        /* Get the CREATED month of the GeoIP table with numeric format, for example 7 means July */
        $latest_updated_date = date('n', strtotime($row['Create_time']));
        /* Get the CURRENT month with numeric format */
        $date_month = date("n");
        /* Compare the current month and the created month of the table. If the current month larger than the created month, it means that the GeoIP table was created in the last month.*/
        if ($date_month > $latest_updated_date) {
            $date_year = date("Y");
            $date_month = date("F");
            /* As the table was created in the last month, we are going to check if the first Tuesday of the month is past, in case of updating database at the beginning of the month but the first Tuesday is still not past yet. By comparing the Unix timestamp between current time and the time of the first Tuesday. */
            if (time() > strtotime($date_month . $date_year . "Tuesday")) {
                /* Update the GeiIP table*/
                updateDatabase($if_exist, $connection);
            } else {
                /* If we need not to update, display the database version */
                echo "GeoIP Database Version: " . $create_time;
            }
        } else {
            /* If we need not to update, display the database version */
            echo "GeoIP Database Version: " . $create_time;
        }
    }
}
示例#4
0
                            $replacement = bcadd($base, $localId);
                            $newQuery = $startSplit . $replacement . ";\n";
                            fwrite($fileWriteHandle, $newQuery);
                        }
                    }
                } else {
                    continue;
                }
            }
        }
    }
    fclose($fileHandle);
    fclose($fileWriteHandle);
}
parseFile();
updateDatabase();
/*
$returnStatus = true;
$lab_config_id = $_REQUEST['lid'];
$backup_folder = $_REQUEST['backup_path'];

# Perform backup of current version before reverting?
$do_currbackup = false;
if($_REQUEST['do_currbackup'] == 'Y')
	$do_currbackup = true;
if($do_currbackup === true)
{
	if(!BackupLib::performBackup($lab_config_id, getcwd() ) === true)
	{
		# Backup of current version failed.
		page_redirect(false);
示例#5
0
<?php

require "functions.php";
if ($_POST["updateDatabase"]) {
    $db = my_connect();
    //echo $db;
    updateDatabase("assets/models/", $db);
    $db->close();
} else {
    if ($_GET["getMeshes"]) {
        $db = my_connect();
        $result = $db->query("SELECT * FROM Meshes");
        $meshes = array();
        while ($row = $result->fetch_array(MYSQL_ASSOC)) {
            $curMesh = array();
            foreach ($row as $meshField) {
                $curMesh[] = $meshField;
            }
            //array for holding all the spatial data for this mesh
            $spatialData = array();
            //get all the spatial data associated with this mesh
            $spatialResult = $db->query("SELECT \n\t\t\torientX, \n\t\t\torientY, \n\t\t\torientZ, \n\t\t\tposX,\n\t\t\tposY,\n\t\t\tposZ\n\t\t\tfrom `Spatial Data`\n\t\t\twhere meshId=" . $row["meshId"]);
            //compact it into a separate array then append this array to the end of the current mesh array
            while ($spatialRow = $spatialResult->fetch_array(MYSQL_ASSOC)) {
                $curSpatial = array();
                foreach ($spatialRow as $spaceData) {
                    $curSpatial[] = $spaceData;
                }
                $spatialData[] = $curSpatial;
            }
            $meshes[] = array($curMesh, $spatialData);
示例#6
0
class AuthenticateFailedException extends Exception
{
}
$db = checkDatabase();
if ($db === False) {
    // Database is not available
    $app->map('/api/(:path+)', function () use($app) {
        $output['code'] = 500;
        $output['status'] = 'fail';
        $output['message'] = $GLOBALS['messages']['90003'];
        $app->response->setStatus($output['code']);
        $app->response->setBody(json_encode($output));
    })->via('DELETE', 'GET', 'POST');
    $app->run();
}
if (updateDatabase($db) == False) {
    // Failed to update database
    // TODO should run una tantum
    $app->map('/api/(:path+)', function () use($app) {
        $output['code'] = 500;
        $output['status'] = 'fail';
        $output['message'] = $GLOBALS['messages']['90006'];
        $app->response->setStatus($output['code']);
        $app->response->setBody(json_encode($output));
    })->via('DELETE', 'GET', 'POST');
    $app->run();
}
// Define output for unprivileged requests
$forbidden = array('code' => 401, 'status' => 'forbidden', 'message' => $GLOBALS['messages']['90032']);
/***************************************************************************
 * Authentication
function testDataBase($_host, $_user, $_pass, $_dbname, $_prefix)
{
    if (!function_exists("mysql_connect")) {
        return "PHP/MySQL extension is missing (php_mysql.dll)";
    }
    $connection = @mysql_connect($_host, $_user, $_pass);
    @mysql_query("SET NAMES 'utf8'", $connection);
    if (!$connection) {
        $error = mysql_error();
        return "Can't connect to database. Invalid host or login! (" . mysql_errno() . (!empty($error) ? ": " . $error : "") . ")";
    } else {
        $db_selected = @mysql_select_db(@mysql_real_escape_string($_dbname), $connection);
        if (!$db_selected) {
            return mysql_errno() . ": " . mysql_error();
        } else {
            $resultv = @mysql_query("SELECT VERSION() as `mysql_version`", $connection);
            if (!$resultv) {
                return mysql_errno() . ": " . mysql_error();
            } else {
                $mrow = @mysql_fetch_array($resultv, MYSQL_BOTH);
                $mversion = explode(".", $mrow["mysql_version"]);
                if (count($mversion) > 0 && $mversion[0] < MYSQL_NEEDED_MAJOR) {
                    return "LiveZilla requires MySQL version " . MYSQL_NEEDED_MAJOR . " or greater. The MySQL version installed on your server is " . $mrow["mysql_version"] . ".";
                }
            }
            $tables = array(DATABASE_INFO => array("`version`", "`chat_id`", "`ticket_id`", "`gtspan`"), DATABASE_RESOURCES => array("`id`", "`owner`", "`editor`", "`value`", "`edited`", "`title`", "`created`", "`type`", "`discarded`", "`parentid`", "`rank`", "`size`"), DATABASE_PREDEFINED => array("`id`", "`internal_id`", "`group_id`", "`lang_iso`", "`invitation_manual`", "`invitation_auto`", "`welcome`", "`website_push_manual`", "`website_push_auto`", "`browser_ident`", "`is_default`", "`auto_welcome`", "`editable`"), DATABASE_TICKETS => array("`id`", "`user_id`", "`target_group_id`"), DATABASE_TICKET_MESSAGES => array("`id`", "`time`", "`ticket_id`", "`text`", "`fullname`", "`email`", "`company`", "`ip`"), DATABASE_TICKET_EDITORS => array("`ticket_id`", "`internal_fullname`", "`status`", "`time`"), DATABASE_POSTS => array("`id`", "`chat_id`", "`time`", "`micro`", "`sender`", "`receiver`", "`receiver_group`", "`text`", "`translation`", "`translation_iso`", "`received`", "`persistent`"), DATABASE_EVENT_ACTION_INVITATIONS => array("`id`", "`action_id`", "`position`", "`speed`", "`slide`", "`margin_left`", "`margin_top`", "`margin_right`", "`margin_bottom`", "`style`", "`close_on_click`"), DATABASE_EVENT_TRIGGERS => array("`id`", "`receiver_user_id`", "`receiver_browser_id`", "`action_id`", "`time`", "`triggered`"), DATABASE_PROFILES => array("`id`", "`edited`", "`first_name`", "`last_name`", "`email`", "`company`", "`phone`", "`fax`", "`street`", "`zip`", "`department`", "`city`", "`country`", "`gender`", "`languages`", "`comments`", "`public`"), DATABASE_PROFILE_PICTURES => array("`id`", "`internal_id`", "`time`", "`webcam`", "`data`"));
            $result = @mysql_query("SELECT `version` FROM `" . @mysql_real_escape_string($_prefix) . DATABASE_INFO . "`", $connection);
            $row = @mysql_fetch_array($result, MYSQL_BOTH);
            $version = $row["version"];
            if (!$result || empty($version)) {
                return "Cannot read the LiveZilla Database version. Please try to recreate the table structure.";
            }
            if ($version != VERSION) {
                require_once "./_lib/functions.data.db.update.inc.php";
                $upres = updateDatabase($version, $connection, $_prefix);
                if ($upres !== true) {
                    return "Cannot update database structure from [" . $version . "] to [" . VERSION . "]. Please make sure that the user " . $_user . " has the MySQL permission to ALTER tables in " . $_dbname . ".\r\n\r\nError: " . $upres;
                }
            }
            foreach ($tables as $tblName => $fieldlist) {
                $result = @mysql_query("SHOW COLUMNS FROM `" . @mysql_real_escape_string($_prefix . $tblName) . "`", $connection);
                if (!$result) {
                    return mysql_errno() . ": " . mysql_error();
                } else {
                    if (@mysql_num_rows($result) != count($fieldlist)) {
                        return "Invalid field count for " . $_prefix . $tblName . ". Delete " . $_prefix . $tblName . " manually and try to recreate the tables.";
                    }
                }
            }
            return null;
        }
    }
}
    echo "<p>Max amount of database records: " . $databaseMaxRecords . "</p>";
    echo "<hr />";
}
if (empty($_POST['run'])) {
    echo "<p>Plese use the buttons to display a new PIN Number</p>";
} else {
    $pincheckArray = queryPinNumbers();
    // run queryPinNumbers function to pull all used PIN numbers into an array
    // run getPin function carrying arguments across
    $attemptPin = getPin($randomNumberLength, $randomNumberTolerance, $pincheckArray, $showDevWorking);
    if ($showDevWorking == 1) {
        echo "<p>PIN Number: " . $attemptPin . "</p>";
    }
    $pinNumber = $attemptPin;
    // Set PIN Number
    updateDatabase($pinNumber, $databaseMaxRecords, $showDevWorking);
    // Update database with new pin number and display results
    echo "<a name='pin'></a>";
    echo "<hr/><div id='pin'><h2><span class='radius success label'>PIN: " . $pinNumber . "</span></h2></div>";
}
// database connection function
function dbconnect()
{
    # LOCAL
    $username = "******";
    $password = "";
    $database = "pin";
    $hostname = "localhost";
    # LIVE
    //$username                = "******";
    //$database                = "alancoleman_couk_pin";
 static function InitUpdateDatabase($_version, $_connection, $_prefix, $engine)
 {
     require_once "./_lib/functions.data.db.update.inc.php";
     $upres = updateDatabase($_version, $_connection, $_prefix, $engine);
     return $upres;
 }
function testDataBase($_host, $_user, $_pass, $_dbname, $_prefix)
{
    if (!function_exists("mysql_connect")) {
        return "PHP/MySQL extension is missing (php_mysql.dll)";
    }
    $connection = @mysql_connect($_host, $_user, $_pass);
    if (!$connection) {
        $error = mysql_error();
        return "Can't connect to database. Invalid host or login! (" . mysql_errno() . (!isnull($error) ? ": " . $error : "") . ")";
    } else {
        $db_selected = @mysql_select_db(mysql_real_escape_string($_dbname), $connection);
        if (!$db_selected) {
            return mysql_errno() . ": " . mysql_error();
        } else {
            $rand = substr(rand(10000, 1000000), 0, 15);
            $tables = array(DATABASE_DATA => array("`file`", "`time`", "`data`", "`size`"), DATABASE_CHATS => array("`id`", "`time`", "`endtime`", "`closed`", "`chat_id`", "`external_id`", "`fullname`", "`internal_id`", "`html`", "`plain`", "`email`", "`company`", "`iso_language`", "`host`", "`ip`", "`gzip`", "`transcript_sent`"), DATABASE_INFO => array("`version`", "`chat_id`", "`ticket_id`"), DATABASE_INTERNAL => array("`id`", "`time`", "`time_confirmed`", "`internal_id`", "`status`"), DATABASE_RESOURCES => array("`id`", "`owner`", "`editor`", "`value`", "`edited`", "`title`", "`created`", "`type`", "`discarded`", "`parentid`", "`rank`", "`size`"), DATABASE_PREDEFINED => array("`id`", "`internal_id`", "`group_id`", "`lang_iso`", "`invitation`", "`welcome`", "`website_push`", "`browser_ident`", "`is_default`", "`auto_welcome`"), DATABASE_ROOMS => array("`id`", "`time`", "`last_active`", "`status`", "`target_group`"), DATABASE_TICKETS => array("`id`", "`user_id`", "`target_group_id`"), DATABASE_TICKET_MESSAGES => array("`id`", "`time`", "`ticket_id`", "`text`", "`fullname`", "`email`", "`company`", "`ip`"), DATABASE_TICKET_EDITORS => array("`ticket_id`", "`internal_fullname`", "`status`", "`time`"), DATABASE_POSTS => array("`id`", "`time`", "`micro`", "`sender`", "`receiver`", "`receiver_group`", "`text`", "`received`", "`persistent`"));
            $result = @mysql_query("SELECT version FROM `" . mysql_real_escape_string($_prefix) . DATABASE_INFO . "`", $connection);
            $row = @mysql_fetch_array($result, MYSQL_BOTH);
            $version = $row["version"];
            if (!$result || isnull($version)) {
                return "Cannot read the LiveZilla Database version. Please try to recreate the table structure.";
            }
            if ($version != VERSION) {
                require_once "./_lib/functions.data.db.update.inc.php";
                $upres = updateDatabase($version, $connection, $_prefix);
                if ($upres !== true) {
                    return "Cannot update database structure from [" . $version . "] to [" . VERSION . "]. Please make sure that the user " . $_user . " has the MySQL permission to ALTER tables in " . $_dbname . ".\r\n\r\nError: " . $upres;
                }
            }
            foreach ($tables as $tblName => $fieldlist) {
                $result = @mysql_query("SHOW COLUMNS FROM `" . mysql_real_escape_string($_prefix . $tblName) . "`", $connection);
                if (!$result) {
                    return mysql_errno() . ": " . mysql_error();
                } else {
                    if (@mysql_num_rows($result) == count($fieldlist)) {
                        $queryFields = "INSERT INTO `" . mysql_real_escape_string($_prefix . $tblName) . "` (";
                        $queryValues = ") VALUES (";
                        for ($i = 0; $i < count($fieldlist); $i++) {
                            $queryFields .= $fieldlist[$i] . ($i < count($fieldlist) - 1 ? "," : "");
                            $queryValues .= ($i == 0 ? $rand : "0") . ($i < count($fieldlist) - 1 ? "," : "");
                        }
                        $result = @mysql_query($queryFields . $queryValues . ")", $connection);
                        if (!$result) {
                            return mysql_errno() . ": " . mysql_error();
                        } else {
                            $result = @mysql_query("DELETE FROM " . mysql_real_escape_string($_prefix . $tblName) . " WHERE " . mysql_real_escape_string(substr($fieldlist[0], 1, strlen($fieldlist[0]) - 2)) . "=" . mysql_real_escape_string($rand), $connection);
                            if (!($result && @mysql_affected_rows() > 0)) {
                                return mysql_errno() . ": " . mysql_error();
                            }
                        }
                    } else {
                        return "Invalid field count for " . $_prefix . $tblName . ". Delete " . $_prefix . $tblName . " manually and try to recreate the tables.";
                    }
                }
            }
            return null;
        }
    }
}
示例#11
0
 function initializeDB($database)
 {
     //Get file contents
     $jsonData = file_get_contents('../tfproject/lib/js/json/library.json');
     //Convert JSON string into PHP array ArrayAccess
     $data = json_decode($jsonData, true);
     //For Developmental purpose only
     $error = json_last_error();
     updateDatabase($data, $database);
 }
示例#12
0
function printStep4()
{
    ?>
	<form action="index.php?step=4" method="post">
		<legend><?php 
    echo _t('version_update');
    ?>
</legend>

		<?php 
    if (updateDatabase(false)) {
        ?>
		<p class="alert alert-warn"><?php 
        echo _t('update_long');
        ?>
</p>

		<div class="form-group form-actions">
			<div class="group-controls">
				<input type="hidden" name="updateDatabase" value="1" />
				<button type="submit" class="btn btn-important"><?php 
        echo _t('update_start');
        ?>
</button>
			</div>
		</div>

		<?php 
    } else {
        ?>
		<p class="alert alert-warn"><?php 
        echo _t('update_end');
        ?>
</p>

		<div class="form-group form-actions">
			<div class="group-controls">
				<a class="btn btn-important next-step" href="?step=5"><?php 
        echo _t('next_step');
        ?>
</a>
			</div>
		</div>
		<?php 
    }
    ?>
	</form>
<?php 
}