コード例 #1
0
ファイル: main.php プロジェクト: sacramento04/practice
function export_db($is_backup = false)
{
    global $db, $db_host, $db_user, $db_pass, $db_name, $db_port;
    $stime = microtime(true);
    if ($is_backup) {
        $output_file = str_replace('\\', '/', getcwd()) . "/backup/" . date("Y-m-d_H-i-s") . ".php";
    } else {
        $changes = get_changes();
        $i = 0;
        while (true) {
            $i += 1;
            $file_name = date("Y-m-d") . "-" . sprintf("%02d", $i);
            $ver = (int) str_replace('-', '', $file_name);
            if (array_key_exists($ver, $changes) == false) {
                break;
            }
        }
        $output_file = str_replace('\\', '/', getcwd()) . "/changes/" . $file_name . ".dump.php";
    }
    $file = fopen($output_file, 'c');
    $tables = get_tables($db_host, $db_user, $db_pass, $db_name, $db_port);
    $max_length = get_max_length($tables);
    fwrite($file, "<?php\n\n");
    fwrite($file, "echo \"\\n\\n\";\n");
    fwrite($file, "\n            execute(\"\n            /*!40101 SET NAMES utf8 */;\n\n            /*!40101 SET SQL_MODE=''*/;\n\n            /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n            /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n            /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n            /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n            \");\n        ");
    foreach ($tables as $table) {
        if ($table == "db_version") {
            continue;
        }
        if ($is_backup) {
            echo "backup ";
        } else {
            echo "dump ";
        }
        echo $table . " ";
        $dots = generate_char($max_length, strlen($table), '.');
        echo $dots . "......... ";
        $sql = get_create_table_sql($db, $table);
        fwrite($file, 'if ($db_version == 0)' . "\n{\n");
        fwrite($file, "    echo \"    " . $table . " " . $dots . "......... \";\n\n");
        fwrite($file, "    execute(\"\n");
        fwrite($file, $sql);
        fwrite($file, "\n\");\n\n");
        fwrite($file, "    echo \"[created]\\n\"; \n");
        fwrite($file, "}\n\n");
        if ($is_backup == false && strpos($table, "player") === 0) {
            echo "[ignore]\n";
            continue;
        }
        $fields = get_table_fields($db, $table);
        $sql = get_insert_into_sql($db, $table, $fields);
        fwrite($file, "echo \"    " . $table . " " . $dots . "......... \";\n\n");
        fwrite($file, "execute(\"DELETE FROM `" . $table . "`\");\n\n");
        if ($sql != "") {
            fwrite($file, "execute(\"\n");
            fwrite($file, $sql);
            fwrite($file, "\");\n\n");
        }
        fwrite($file, "echo \"[loaded]\\n\"; \n");
        fwrite($file, "\n");
        echo "[done]\n";
    }
    fwrite($file, "\n            execute(\"\n            /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n            /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n            /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n            /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n            \");\n        ");
    fwrite($file, "echo \"\\n\";\n");
    fwrite($file, "?>\n");
    fclose($file);
    if ($is_backup == false) {
        $sql = "UPDATE `db_version` SET `version` = " . $ver . ", `change_time` = UNIX_TIMESTAMP()";
        if ($db->query($sql) === FALSE) {
            die("can't update db_version");
        }
    }
    $etime = microtime(true);
    echo "\ndatabase ";
    if ($is_backup) {
        echo "backup ";
    } else {
        echo "dump ";
    }
    echo "complete in " . round($etime - $stime, 2) . "s\n";
}
コード例 #2
0
ファイル: collect.php プロジェクト: jsib/dumps.loc
function go()
{
    //Объявляем глобальные переменные
    global $version_files;
    global $virtual_files;
    global $eol;
    global $store;
    //Задаем пути к директориям и сразу же проверяем
    $dir = correct_path("C:\\Temp");
    $store = correct_path("C:\\Store");
    if (!file_exists($dir)) {
        echo "Ошибка.{$eol}Директория-источник {$dir} не существует.{$eol}Подробнее смотрите файл " . __FILE__ . " строка " . __LINE__ . $eol . "Скрипт принудительно завершает работу.";
        exit;
    }
    if (!file_exists($store)) {
        echo "Ошибка.{$eol}Директория-хранилище {$store} не существует.{$eol}Подробнее смотрите файл " . __FILE__ . " строка " . __LINE__ . $eol . "Скрипт принудительно завершает работу.";
        exit;
    }
    /*Анализируем файл с информацией о копиях в хранилище*/
    //1. Номер последней копии
    $main_info_file = $store . "store.info";
    if (file_exists($main_info_file)) {
        if ($fp = fopen($main_info_file, 'r')) {
            $previous_copy_id = fgets($fp) + 0;
            fclose($fp);
            if (is_int($previous_copy_id)) {
                get_virtual_dir($previous_copy_id);
                $previous_version_files = $virtual_files;
                $previous_info_file = correct_path($store . "store." . $previous_copy_id) . "store." . $previous_copy_id . ".info";
                if ($fp = fopen($previous_info_file, 'r')) {
                    $current_copy_id = $previous_copy_id + 1;
                    $lines = file($previous_info_file);
                    foreach ($lines as $line_numFOR => $lineFOR) {
                        $explodeFOR = explode("\t", $lineFOR);
                        //show($explodeFOR);
                        //$previous_version_files[tmlspecialchars($line) . "<br />\n";
                    }
                    //show($previous_version_files);
                    fclose($fp);
                } else {
                    show_fatal_error("Невозможно открыть файл {$previous_info_file}", __FILE__, __LINE__);
                }
            } else {
                show_fatal_error("Главный информационный файл хранилища {$main_info_file} существует." . $eol . "Но первая строка данного файла не содержит целое число.", __FILE__, __LINE__);
            }
        } else {
            show_fatal_error("Не удается открыть главный информационный файл хранилища {$main_info_file}", __FILE__, __LINE__);
        }
    } else {
        $previous_version_files = array();
        $current_copy_id = 0;
    }
    /*Получаем массив version_files*/
    get_files_array($dir, $dir);
    //show($version_files);
    //show($virtual_files);
    /*Записываем информацию об измененных файлах*/
    $current_store_dir = correct_path($store . "store." . $current_copy_id);
    $current_info_file = $current_store_dir . "store." . $current_copy_id . ".info";
    $copy_info = get_changes($version_files, $previous_version_files, PHP_EOL);
    //Записываем информацию о текущей копии в главный информационный файл хранилища
    file_easy_write($main_info_file, $current_copy_id);
    if (!file_exists($current_store_dir)) {
        mkdir($current_store_dir);
    }
    file_easy_write($current_info_file, $copy_info);
    show_message("Создана версия №" . $current_copy_id);
}
コード例 #3
0
ファイル: index.php プロジェクト: nickgrossman/TheBoard
} elseif ($_GET['project_id']) {
    $project_id = $_REQUEST['project_id'];
    require_once 'edit_project.php';
} elseif ($_POST['action'] == 'edit_project') {
    $project_id = $_REQUEST['project_id'];
    $new_name = $_POST['project_name'];
    $new_url = $_POST['project_url'];
    $new_parked = $_POST['parked'];
    edit_project($project_id, $new_name, $new_url, $new_parked);
} elseif ($_GET['person_id']) {
    $person_id = $_REQUEST['person_id'];
    require_once 'edit_person.php';
} elseif ($_POST['action'] == 'add_person') {
    $person_name = $_REQUEST['person_name'];
    $person_long_name = $_REQUEST['person_long_name'];
    $person_role = $_REQUEST['person_role'];
    add_person($person_name, $person_long_name, $person_role);
} elseif ($_POST['action'] == 'edit_person') {
    $person_id = $_REQUEST['person_id'];
    $new_name = $_POST['person_name'];
    $new_long_name = $_POST['person_long_name'];
    $new_role = $_POST['person_role'];
    edit_person($person_id, $new_name, $new_long_name, $new_role);
} elseif ($_GET['action'] == 'list_latest_changes') {
    list_latest_changes(get_changes());
} else {
    require_once 'trac.php';
    require_once 'display.php';
}
/* close MySQL connection */
mysql_close();
コード例 #4
0
ファイル: display.inc.php プロジェクト: nickgrossman/TheBoard
<?php

/* Get Projects */
$projects = get_projects('unparked');
$parked_projects = get_projects('parked');
$all_projects = get_projects('all');
/* Setup Calendar */
if (isset($_GET['startdate'])) {
    $mondays = get_mondays($_GET['startdate']);
} else {
    $lastweek = date("Y-m-d", mktime(0, 0, 0, date('m'), date('d') - 7, date('Y')));
    /* get calendar starting with previous week */
    $mondays = get_mondays($lastweek);
}
/* Get People */
$people = get_people();
/* Get recent changes */
$changes = get_changes('50');