Exemplo n.º 1
0
/**
 * @deprecated not used anywhere
 * wrapper function for reseting install to default one
 * all data will be lost
 */
function cos_reset_install()
{
    cos_rm_files();
    drop_db_default();
    create_db();
    load_db_default();
    cos_create_files();
    cos_chmod_files();
    cos_install();
}
Exemplo n.º 2
0
function get_db()
{
    $db_file_exists = file_exists(SQL_FILE_PATH);
    $db = sqlite_open(SQL_FILE_PATH, 0666, $sqliteerror);
    if (!$db) {
        die($sqliteerror);
    }
    if (!$db_file_exists) {
        create_db($db);
    }
    return $db;
}
function connect_db($db_server, $db_username, $db_password, $db_name)
{
    if (establish_connection($db_server, $db_username, $db_password)) {
        $database = mysql_select_db($db_name);
        if ($database) {
            return 1;
        } else {
            create_db($db_name);
        }
        return 1;
    } else {
        die("Couldn't establish connection to database");
    }
}
Exemplo n.º 4
0
function create_client($subdomain, $client_name, $client_username, $client_email, $client_password)
{
    if ($db = create_db($subdomain) !== false) {
        try {
            $con = new wpdb(MYSQL_ROUTING_USER, MYSQL_ROUTING_PASSWORD, MYSQL_ROUTING_DB, MYSQL_ROUTING_HOST);
            $result = $con->insert('client', array('subdomain' => $subdomain, 'email' => $client_email, 'name' => $client_name, 'admin_username' => $client_username, 'admin_password' => base64_encode($client_password), 'status' => 0, 'db_driver' => 'mysql', 'db_host' => 'localhost', 'db_name' => $db["db_name"], 'db_user' => $db["db_user"], 'db_pass' => $db["db_pass"], 'db_charset' => 'utf8', 'db_collation' => 'utf8_unicode_ci', 'db_prefix' => '', 'created_at' => date("Y-m-d H:i:s")), array('%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s'));
            if ($result) {
                return true;
            }
        } catch (Exception $e) {
            return false;
        }
    }
    return false;
}
ob_end_clean();
if (!$link) {
    output("`\$Blast!  I wasn't able to connect to the database server with the information you provided!");
    output("`2This means that either the database server address, database username, or database password you provided were wrong, or else the database server isn't running.");
    output("The specific error the database returned was:");
    rawoutput("<blockquote>" . $error . "</blockquote>");
    output("If you believe you provided the correct information, make sure that the database server is running (check documentation for how to determine this).");
    output("Otherwise, you should return to the previous step, \"Database Info\" and double-check that the information provided there is accurate.");
    $session['stagecompleted'] = 3;
} else {
    output("`^Yahoo, I was able to connect to the database server!");
    output("`2This means that the database server address, database username, and database password you provided were probably accurate, and that your database server is running and accepting connections.`n");
    output("`nI'm now going to attempt to connect to the LoGD database you provided.`n");
    if (httpget("op") == "trycreate") {
        require_once 'lib/installer/installer_functions.php';
        create_db($session['dbinfo']['DB_NAME']);
    }
    if (!db_select_db($session['dbinfo']['DB_NAME'])) {
        output("`\$Rats!  I was not able to connect to the database.");
        $error = db_error();
        if ($error == "Unknown database '{$session['dbinfo']['DB_NAME']}'") {
            output("`2It looks like the database for LoGD hasn't been created yet.");
            output("I can attempt to create it for you if you like, but in order for that to work, the account you provided has to have permissions to create a new database.");
            output("If you're not sure what this means, it's safe to try to create this database, but you should double check that you've typed the name correctly by returning to the previous stage before you try it.`n");
            output("`nTo try to create the database, <a href='installer.php?stage=4&op=trycreate'>click here</a>.`n", true);
        } else {
            output("`2This is probably because the username and password you provided doesn't have permission to connect to the database.`n");
        }
        output("`nThe exact error returned from the database server was:");
        rawoutput("<blockquote>{$error}</blockquote>");
        $session['stagecompleted'] = 3;
Exemplo n.º 6
0
function write_db($stm, $table, $days)
{
    global $postfix_dir, $config, $g;
    conf_mount_rw();
    $do_sync = array();
    print "writing to database...";
    foreach ($days as $day) {
        if (strlen($stm[$day]) > 10 && is_array($config['installedpackages']['postfixsync']['config'])) {
            foreach ($config['installedpackages']['postfixsync']['config'] as $rs) {
                foreach ($rs['row'] as $sh) {
                    $sync_to_ip = $sh['ipaddress'];
                    $sync_type = $sh['sync_type'];
                    $password = $sh['password'];
                    $sql_file = '/var/db/postfix/' . $sync_to_ip . '.sql';
                    ${$sync_to_ip} = "";
                    if (file_exists($sql_file)) {
                        ${$sync_to_ip} = file_get_contents($sql_file);
                    }
                    if ($sync_to_ip && $sync_type == "share") {
                        ${$sync_to_ip} .= serialize(array('day' => $day, 'sql' => base64_encode(gzcompress($stm[$day] . "COMMIT;", 9)))) . "\n";
                        if (!in_array($sync_to_ip, $do_sync)) {
                            $do_sync[] = $sync_to_ip;
                        }
                    }
                }
            }
            /* Write local db file */
            create_db($day . ".db");
            if ($debug) {
                print "writing to local db {$day}...";
            }
            $dbhandle = sqlite_open($postfix_dir . $day . ".db", 0666, $error);
            if (!$dbhandle) {
                die($error);
            }
            //file_put_contents("/tmp/" . $key . '-' . $update['day'] . ".sql", gzuncompress(base64_decode($update['sql'])), LOCK_EX);
            $ok = sqlite_exec($dbhandle, $stm[$day] . "COMMIT;", $error);
            if (!$ok) {
                print "Cannot execute query. {$error}\n" . $stm[$day] . "COMMIT;\n";
            } elseif ($debug) {
                print "ok\n";
            }
            sqlite_close($dbhandle);
        }
    }
    /* Write updated sql files */
    if (count($do_sync) > 0) {
        foreach ($do_sync as $ip) {
            file_put_contents('/var/db/postfix/' . $ip . '.sql', ${$ip}, LOCK_EX);
        }
    }
    conf_mount_ro();
    /* Write local file */
}
Exemplo n.º 7
0
define('DOING_UPGRADE', true);
require_once 'init.php';
require_once 'include/data_upgrade.php';
/* @var $db ADOConnection */
if (defined('CURRENT_SCHEMA') && (int) CURRENT_SCHEMA >= (int) REQUIRED_SCHEMA) {
    ?>
<html><head><title>Upgrade complete</title></head>
<body><h1>Upgrade Complete</h1><p>Scriptmind::Links database is at the same
version as the installed copy of the software.</p>
<p><a href="index.php">Return</a>
to to index.</p></body></html><?php 
    exit;
}
echo "Updating database schema<br/>\n";
flush();
$create = create_db(false);
if ($create[0]) {
    echo "Result: Ok: " . $create[1] . "<br/><br/>\n\n";
} else {
    echo "Result: Failed: " . $create[1] . " " . $create[2] . "<br/><br/>\n\n";
    echo "Either fix the problem or restore the database and package software.<br/>\n";
    exit;
}
if (!defined('CURRENT_SCHEMA')) {
    define('CURRENT_SCHEMA', '0');
    $template = $tables['config']['data'][0];
    $row = array();
    foreach ($template as $fld => $val) {
        switch ($fld) {
            case 'VALUE':
                $row['VALUE'] = CURRENT_SCHEMA;
 protected function setUp()
 {
     global $SYSCONF_DIR;
     global $DB_COMMAND;
     global $DB_NAME;
     $SYSCONF_DIR = "/usr/local/etc/fossology/";
     $DB_NAME = "fossology";
     $DB_COMMAND = "../../../testing/db/createTestDB.php";
     print "Starting functional test for delagent. \n";
     create_db();
     add_user();
     replace_repo();
     scheduler_operation();
     $this->upload_testdata();
 }
Exemplo n.º 9
0
<?php

// set up database
require_once "../file-includes.php";
$conn = get_conn(false);
// create database
$db_name = "ajx_org_db";
create_db($conn, $db_name);
$conn->close();
$conn = get_conn();
// create users table
$query = "create table ajx_org_users(\n\t\t  username varchar(35) unique not null,\n\t\t  password varchar(60) not null,\n\t\t  userID bigint not null auto_increment,\n\t\t  primary key(userID)\n\t\t  )";
get_result($conn, $query);
// create addressbook table
$query = "create table ajx_org_address_book(\n\t      userID bigint not null,\n\t\t  name varchar(50) not null,\n\t\t  address varchar(200),\n\t\t  phone_number varchar(20),\n\t\t  email varchar(200),\n\t\t  contact_group varchar(50),\n\t\t  contactID bigint not null auto_increment,\n\t\t  primary key(contactID)\n\t\t  )";
get_result($conn, $query);
// create notes table
$query = "create table ajx_org_notes(\n\t      userID bigint not null, \n\t\t  title varchar(50) not null,\n\t\t  content varchar(500),\n\t\t  date_made varchar(20) not null,\n\t\t  last_edited varchar(20) not null,\n\t\t  noteID bigint not null auto_increment,\n\t\t  primary key(noteID)\n\t\t  )";
get_result($conn, $query);
// create to do list table
$query = "create table ajx_org_todo(\n\t\t  userID bigint not null,\n\t\t  task varchar(50) not null,\n\t\t  importance int not null,\n\t\t  date_made varchar(20) not null,\n\t\t  last_edited varchar(20) not null,\n\t\t  complete varchar(10) not null,\n\t\t  taskID bigint not null auto_increment,\n\t\t  primary key(taskID)\n\t\t  )";
get_result($conn, $query);
$conn->close();
Exemplo n.º 10
0
 /**
  *    配置表单的处理脚本
  *
  *    @author    Garbin
  *    @return    void
  */
 function config_done()
 {
     $missing_items = array();
     foreach ($_POST as $key => $value) {
         if (empty($value) && $key != 'db_pass') {
             $missing_items[] = $key;
         }
     }
     if (!empty($missing_items)) {
         $this->_doing = $this->_done;
         $this->assign('missing_items', $missing_items);
         $this->config();
         return false;
     }
     extract($_POST);
     if (!eregi('^http(s?)://', $site_url)) {
         $this->_doing = $this->_done;
         $this->assign('site_url_error', true);
         $this->config();
         return false;
     }
     if (!is_email($admin_email)) {
         $this->_doing = $this->_done;
         $this->assign('admin_email_error', true);
         $this->config();
         return false;
     }
     if ($admin_pass != $pass_confirm) {
         $this->_doing = $this->_done;
         $this->assign('pass_error', true);
         $this->config();
         return false;
     }
     /* 检查输入的数据库配置信息*/
     /* 检查是否能连上数据库 */
     $con = @mysql_connect($db_host . ':' . $db_port, $db_user, $db_pass);
     if (!$con) {
         $this->_doing = $this->_done;
         $this->assign('mysql_error', mysql_error());
         $this->config();
         return false;
     }
     /* 检查数据库是否存在 */
     $selected_db = @mysql_select_db($db_name);
     if (!$selected_db) {
         /* 如果不存在,尝试创建该数据库 */
         $created_db = @create_db($db_name, $con);
         /* 创建不成功,则显示错误 */
         if (!$created_db) {
             $this->_doing = $this->_done;
             $this->assign('create_db_error', mysql_error());
             $this->config();
             return false;
         }
     } else {
         /* 如果存在,检查是否已安装过ECMall */
         $query = @mysql_query("SHOW TABLES LIKE '{$db_prefix}%'");
         /* 如果安装过,检查是否同意强制安装 */
         $has_ecmall = false;
         while ($row = mysql_fetch_assoc($query)) {
             $has_ecmall = true;
             break;
         }
         /* 有ECMall,但不同意强制安装,则显示错误 */
         if ($has_ecmall && empty($_POST['force_install'])) {
             $this->_doing = $this->_done;
             $this->assign('has_ecmall', true);
             $this->config();
             return false;
         }
         /* 没有装过ECMall或有ECMall但同意强制安装,则直接通过 */
     }
     return true;
 }
Exemplo n.º 11
0
            foreach ($db->errors as $error) {
                echo $error . '<br />';
            }
            echo '<p class="step"><a href="setup.php?step=1" class="button">Go Back</a></p>';
            exit;
        }
        $c = new config();
        $c->setFile('config.php');
        $c->openFile();
        $c->insert("mysql_db_name", $dbname);
        $c->insert("mysql_db_user", $uname);
        $c->insert("mysql_db_passwd", $pwd);
        $c->insert("mysql_db_host", $dbhost);
        $c->insert("table_prefix", $prefix);
        $c->closeFile();
        create_db($db, $prefix);
        $db->close();
        ?>
<p>All right sparky! You've made it through this part of the
installation. Now the IPN recorder database has been created. If you are
ready, time now to&hellip;</p>

<p class="step"><a href="control.php" class="button">Go To Control Panel</a></p>
<?php 
        break;
}
function display_header($type = '')
{
    switch ($type) {
        default:
            $title = "Setup Page";
Exemplo n.º 12
0
        /*$pdo->exec("create database my_db2");  //создаем базу данных
        		$pdo->exec("use my_db2");  // подключаемся к базе данных
        		$pdo->exec("create table experiments(id_exp INT not null prymary key, data INT, lastname CHAR)");//т.эксп.
        		$pdo->exec("create table bricks (id_exp INT, numb INT , score INT, fraction FLOAT)");  //создаем таблицу результатов
        	*/
    } catch (PDOException $ex) {
        die("Error: " . $ex->getMessage());
    }
    return $pdo;
}
/*---------------------------------------подключаемся к бд с пом. pdo------------------------------------------*/
try {
    $pdo = new PDO("mysql:host=localhost;dbname=my_db2", "root");
} catch (PDOException $ex) {
    if ($ex->getCode() == 1049) {
        $pdo = create_db();
    } else {
        die("Error: " . $ex->getMessage());
    }
}
if (isset($_GET['ln'])) {
    $ln = $_GET['ln'];
}
if (isset($_GET['nexp'])) {
    $nexp = $_GET['nexp'];
    $exper = "<h3>{$nexp}</h3><table class='my_table'><tr><td>Кол-во<br>очков</td><td>Ск. раз<br>выпало</td><td>\n\tВ %<br>соотн-ии</td></tr><tr>";
    //заг. табл.эксп-нтов
    /*----------------------------выводим результаты для данного эксперимента--------------------------------------*/
    $rez = $pdo->query('SELECT numb, score, fraction FROM bricks WHERE id_exp=' . $nexp . ' ORDER BY numb')->fetchAll(PDO::FETCH_ASSOC);
    for ($i = 0; $i < count($rez); $i++) {
        foreach ($rez[$i] as $key => $val) {
Exemplo n.º 13
0
function install_db($db_details)
{
    global $tpl;
    if (!is_array($db_details) || empty($db_details)) {
        $tpl->assign('form_error', _L('Could not process input data.'));
        return 0;
    }
    $ret = update_config('config/config.php', array('LANGUAGE' => $db_details['language'], 'DB_DRIVER' => $db_details['db_driver'], 'DB_HOST' => $db_details['db_host'], 'DB_NAME' => $db_details['db_name'], 'DB_USER' => $db_details['db_user'], 'DB_PASSWORD' => $db_details['db_password']));
    if ($ret !== true) {
        $tpl->assign('form_error', $ret);
        return 0;
    }
    $ret = create_db(true, $db_details['db_driver'], $db_details['db_host'], $db_details['db_name'], $db_details['db_user'], $db_details['db_password']);
    if (!$ret[0]) {
        // Database creation error
        $tpl->assign('form_error', $ret[1]);
        $tpl->assign('sql_error', $ret[2]);
        return 0;
    } else {
        // Database was created/updated
        $tpl->assign('message', $ret[1]);
        return 1;
    }
}
Exemplo n.º 14
0
        }
    } else {
        //use get latest stable url for remote
        $uri = Get_latest_version_url($versions[$_POST['ver']]['lang_code']);
        $download_ok = http_get_file($uri, 'latest.zip');
    }
    //unzip
    if ($download_ok) {
        $done_zip = extract_zip('latest.zip', $_POST['folder']);
    } else {
        echo '<br/> File dosen\'t exists, try downloading the latest version.';
        die;
    }
    //create database
    if (isset($_POST['mk_db']) && $_POST['mk_db'] == 'mkdb') {
        create_db($_POST['db_user'], $_POST['db_pass'], $_POST['server'], $_POST['db_name']);
    }
    //redirect to installer
    if ($done_zip) {
        ?>
    <div style="display: none;">
      <?php 
        includejQuery();
        ?>
      <form action="<?php 
        echo $_POST['folder'] . '/wp-admin/setup-config.php?step=2';
        ?>
" method="post" id="insa">
      <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
      <table class="form-table">
        <tbody><tr>
Exemplo n.º 15
0
include_once 'ressources/class.influx.inc';
$users = new usersMenus();
if (!$users->AsWebStatisticsAdministrator) {
    echo FATAL_ERROR_SHOW_128("{ERROR_NO_PRIVS}");
    die;
}
if (isset($_GET["popup"])) {
    table();
    exit;
}
if (isset($_GET["search"])) {
    search();
    exit;
}
if (isset($_POST["new-db"])) {
    create_db();
    exit;
}
if (isset($_REQUEST["delete-db"])) {
    delete_db();
    exit;
}
if (isset($_GET["delete-db-js"])) {
    delete_db_js();
    exit;
}
js();
function js()
{
    $t = time();
    $page = CurrentPageName();
Exemplo n.º 16
0
<?php

/**
 *
 * @copyright  2014 izend.org
 * @version    1
 * @link       http://www.izend.org
 */
require_once 'blocks/configure' . $scheme . '.php';
$db_admin_user = $scheme == 'mysql' ? 'root' : 'postgres';
$db_admin_password = '******';
$db_host = 'localhost';
$db_name = 'test';
$db_user = '******';
$db_password = '******';
recover_db($db_admin_user, $db_admin_password, $db_host, $db_name, $db_user);
create_db($db_admin_user, $db_admin_password, $db_host, $db_name, $db_user, $db_password);
$db_prefix = 'test_';
$site_admin_user = '******';
$site_admin_password = '******';
$site_admin_mail = '*****@*****.**';
$default_language = 'fr';
$msecs = microtime(true);
init_db($db_host, $db_name, $db_user, $db_password, $db_prefix, $site_admin_user, $site_admin_password, $site_admin_mail, $default_language);
echo sprintf('%.4f', microtime(true) - $msecs), PHP_EOL;
Exemplo n.º 17
0
 /**
  *    配置表单的处理脚本
  *
  *    @author    Garbin
  *    @return    void
  */
 function config_done()
 {
     $missing_items = array();
     foreach ($_POST as $key => $value) {
         if (empty($value) && $key != 'db_pass') {
             $missing_items[] = $key;
         }
     }
     if (!empty($missing_items)) {
         //pecho($_POST);
         //pecho($missing_items);
         self::$_doing = self::$_done;
         //$this->assign('missing_items', $missing_items);
         self::config(compact('missing_items'));
         return false;
     }
     extract($_POST);
     if (!preg_match("/^http(s?):\\/\\//i", $site_url)) {
         self::$_doing = self::$_done;
         //$this->assign('site_url_error', true);
         self::config(array('site_url_error' => true));
         return false;
     }
     if (!is_email($admin_email)) {
         self::$_doing = self::$_done;
         //$this->assign('admin_email_error', true);
         self::config(array('admin_email_error' => true));
         return false;
     }
     if ($admin_pass != $pass_confirm) {
         self::$_doing = self::$_done;
         //$this->assign('pass_error', true);
         self::config(array('pass_error' => true));
         return false;
     }
     /* 检查输入的数据库配置信息*/
     /* 检查是否能连上数据库 */
     $con = @mysql_connect($db_host . ':' . $db_port, $db_user, $db_pass);
     if (!$con) {
         self::$_doing = self::$_done;
         //$this->assign('mysql_error', mysql_error());
         self::config(array('mysql_error' => mysql_error()));
         return false;
     }
     /* 检查数据库是否存在 */
     $selected_db = @mysql_select_db($db_name);
     if (!$selected_db) {
         /* 如果不存在,尝试创建该数据库 */
         $created_db = create_db($db_name, $con);
         /* 创建不成功,则显示错误 */
         if (!$created_db) {
             self::$_doing = self::$_done;
             //$this->assign('create_db_error', mysql_error());
             self::config(array('create_db_error' => mysql_error()));
             return false;
         }
     } else {
         /* 如果存在,检查是否已安装过MyOffice */
         $query = @mysql_query("SHOW TABLES LIKE '{$db_prefix}%'");
         /* 如果安装过,检查是否同意强制安装 */
         $has_myoffice = false;
         while ($row = mysql_fetch_assoc($query)) {
             $has_myoffice = true;
             break;
         }
         /* 有MyOffice,但不同意强制安装,则显示错误 */
         if ($has_myoffice && empty($_POST['force_install'])) {
             self::$_doing = self::$_done;
             //$this->assign('has_myoffice', true);
             self::config(array('has_myoffice' => true));
             return false;
         }
         /* 没有装过MyOffice或有MyOffice但同意强制安装,则直接通过 */
     }
     return true;
 }
Exemplo n.º 18
0
function step_5()
{
    if (request_confirm('Start_Installation') || request_confirm('step') && request_get('step') === 3) {
        $access = false;
        if (request_confirm('Start_Installation')) {
            if (create_db()) {
                //install_bdd();
                $access = true;
            }
        }
        if (request_confirm('step') && request_get('step') === 3) {
            $access = true;
        }
        if ($access) {
            if (request_confirm('Start_Installation')) {
                install_edit_step_record(3);
            }
            mmorpg_init();
            // creatio des levels
            ?>
				Installation de caranille terminée avec succès<br />
				Dans la suite de l'installation vous allez devoir configurer les bases de votre MMORPG<br />
				
				<form method="POST" action="<?php 
            echo get_link("Install") . "&step=4";
            ?>
">
				<input type="submit" name="Configure" value="Configurer mon MMORPG"/>
				</form>
<?php 
        }
    }
}
Exemplo n.º 19
0
    header('Location: login.php');
    exit;
}
if (logged_in()) {
    admin_header();
    ?>
        <?php 
    if (isset($_POST['update']) && $_POST['update'] == 'updated') {
        $updated_page = $_POST;
        $update_query = "UPDATE pages\n                                SET `p_name` = \"{$updated_page['p_name']}\",\n                                `content` = \"{$updated_page['content']}\"\n                                WHERE `id` = {$updated_page['id']}\n                                ";
        update_db($update_query);
    }
    if (isset($_POST['create']) && $_POST['create'] == 'created') {
        $new_page = $_POST;
        $create_query = "INSERT INTO `pages`(\n                                `p_name`, `content`)\n                                VALUES (\"{$new_page['p_name']}\",\n                                \"{$new_page['content']}\"\n                                )";
        create_db($create_query);
    }
    if (isset($_GET['delete'])) {
        $delete_query = "DELETE FROM `pages`\n                                WHERE `id` = {$_GET['delete']}";
        delete_db($delete_query);
    }
    ?>
        <div class="content content-all-pages">
            <table>
                <tr>
                    <th>Page Name</th>
                    <th>Content</th>     
                </tr>
                <?php 
    $query = "Select * from pages";
    foreach (get_data($query) as $key => $value) {
Exemplo n.º 20
0
function cube()
{
    define("Q", 36000);
    $d = "";
    $c2 = 0;
    $c3 = 0;
    $c4 = 0;
    $c5 = 0;
    $c6 = 0;
    $c7 = 0;
    $c8 = 0;
    $c9 = 0;
    $c10 = 0;
    $c11 = 0;
    $c12 = 0;
    $d = [];
    $e = [];
    //$lastname=array("Симка","Нолик","Мася","Папус","Фаер","Верта","Игрек","Шпуля");  //массив экспериментаторов
    $exp = rand(2, 5);
    //кол-во экспериментов
    $r = "<table class='my_table'><tr><td>№<br>эксп.</td><td>Кол-во<br>очков</td><td>Сколько раз<br>выпало</td><td>\n\t\tВ % соотн-ии</td></tr><tr>";
    //заголовок таблицы результатов
    $exper = "<table class='my_table'><tr><td>№<br>эксп.</td><td>Дата</td><td>Фамилия</td></tr><tr>";
    //заг. табл.эксп-нтов
    try {
        $pdo = new PDO("mysql:host=localhost;dbname=my_db2", "root");
    } catch (PDOException $ex) {
        if ($ex->getCode() == 1049) {
            $pdo = create_db();
        } else {
            die("Error: " . $ex->getMessage());
        }
    }
    $pdo->exec("DROP TABLE experiments");
    //удаляем таблицу экспериментов
    $pdo->exec("DROP TABLE bricks");
    //удаляем таблицу результатов
    $pdo->exec("CREATE TABLE IF NOT EXISTS experiments (id_exp INT, data char(30), lastname CHAR(30))");
    //создаем табл. экспериментов
    $pdo->exec("CREATE TABLE IF NOT EXISTS bricks (id_exp INT, numb INT, score INT, fraction decimal(5,2))");
    //созд.т.рез-тов
    for ($j = 1; $j <= $exp; $j++) {
        //эксперимент
        $day = rand(1, 30);
        if ($day < 10) {
            $day = "0" . $day;
        }
        $month = rand(1, 12);
        if ($month < 10) {
            $month = "0" . $month;
        }
        $data = $day . "." . $month . ".15";
        $ln = $lastname[rand(0, count($lastname) - 1)];
        $pdo->prepare("INSERT INTO experiments (id_exp, data, lastname) VALUES(:id, :d, :ln)")->execute(array(':id' => $j, ':d' => $data, ':ln' => $ln));
        for ($i = 0; $i < 36000; $i++) {
            $c = rand(1, 6) + rand(1, 6);
            switch ($c) {
                case 2:
                    $d[2] = $c2++;
                    $e[2] = $c2 / Q * 100;
                    break;
                case 3:
                    $d[3] = $c3++;
                    $e[3] = $c3 / Q * 100;
                    break;
                case 4:
                    $d[4] = $c4++;
                    $e[4] = $c4 / Q * 100;
                    break;
                case 5:
                    $d[5] = $c5++;
                    $e[5] = $c5 / Q * 100;
                    break;
                case 6:
                    $d[6] = $c6++;
                    $e[6] = $c6 / Q * 100;
                    break;
                case 7:
                    $d[7] = $c7++;
                    $e[7] = $c7 / Q * 100;
                    break;
                case 8:
                    $d[8] = $c8++;
                    $e[8] = $c8 / Q * 100;
                    break;
                case 9:
                    $d[9] = $c9++;
                    $e[9] = $c9 / Q * 100;
                    break;
                case 10:
                    $d[10] = $c10++;
                    $e[10] = $c10 / Q * 100;
                    break;
                case 11:
                    $d[11] = $c11++;
                    $e[11] = $c11 / Q * 100;
                    break;
                case 12:
                    $d[12] = $c12++;
                    $e[12] = $c12 / Q * 100;
                    break;
            }
        }
        ksort($d);
        $cube = $pdo->prepare("INSERT INTO bricks (id_exp, numb, score, fraction) VALUES(:id, :n, :s, :f)");
        for ($i = 2; $i <= 12; $i++) {
            $cube->execute(array(':id' => $j, ':n' => $i, ':s' => $d[$i], ':f' => $e[$i]));
        }
    }
    /*
        $rez=$pdo->query('SELECT * FROM bricks')->fetchAll(PDO::FETCH_ASSOC);
        for ($i=0;$i<count($rez);$i++){
            foreach($rez[$i] as $key => $val)
                {$r.="<td>".$val."</td>";}
            $r.="</tr>";
        }
        $r.="</table>";
        echo $r;*/
    $experim = $pdo->query('SELECT * FROM experiments')->fetchAll(PDO::FETCH_ASSOC);
    for ($i = 0; $i < count($experim); $i++) {
        foreach ($experim[$i] as $key => $val) {
            $j = $i + 1;
            $exper .= "<td><a style='text-decoration:none;color:black' href='rezult.php?name={$j}' target='blank'>\n\t\t\t{$val}</a></td>";
        }
        $exper .= "</tr>";
    }
    $exper .= "</table>";
    echo $exper;
}
Exemplo n.º 21
-1
function configure($lang)
{
    global $system_languages;
    global $base_url;
    $writable_files = array(CONFIG_DIRNAME . DIRECTORY_SEPARATOR . DB_INC, CONFIG_DIRNAME . DIRECTORY_SEPARATOR . CONFIG_INC, CONFIG_DIRNAME . DIRECTORY_SEPARATOR . ALIASES_INC, LOGOS_DIRNAME . DIRECTORY_SEPARATOR . SITELOGO_PNG, SITEMAP_XML, ROBOTS_TXT, AVATARS_DIRNAME, LOG_DIRNAME, TMP_DIRNAME, PHPQRCODECACHE_DIRNAME);
    $bad_write_permission = false;
    foreach ($writable_files as $fname) {
        $fpath = ROOT_DIR . DIRECTORY_SEPARATOR . $fname;
        clearstatcache(true, $fpath);
        if (!is_writable($fpath)) {
            if (!is_array($bad_write_permission)) {
                $bad_write_permission = array();
            }
            $bad_write_permission[] = $fname;
        }
    }
    $token = false;
    if (isset($_POST['configure_token'])) {
        $token = readarg($_POST['configure_token']);
    }
    $action = 'init';
    if (isset($_POST['configure_configure'])) {
        $action = 'configure';
    }
    $sitename = $webmaster = '';
    $content_languages = false;
    $default_language = false;
    $db_flag = false;
    $db_type = 'mysql';
    $db_reuse = false;
    $db_host = 'localhost';
    $db_admin_user = $db_admin_password = '';
    $db_name = $db_user = $db_password = $db_prefix = '';
    $site_admin_user = $site_admin_password = '';
    switch ($action) {
        case 'init':
            $sitename = 'mysite.net';
            $webmaster = '*****@*****.**';
            $content_languages = array($lang);
            $default_language = $lang;
            $db_flag = true;
            $db_reuse = false;
            $db_name = 'mysite';
            $db_user = '******';
            $db_prefix = 'mysite_';
            do {
                $db_password = newpassword(8);
            } while (!validate_password($db_password));
            break;
        case 'configure':
            if (isset($_POST['configure_sitename'])) {
                $sitename = readarg($_POST['configure_sitename']);
            }
            if (isset($_POST['configure_webmaster'])) {
                $webmaster = readarg($_POST['configure_webmaster']);
            }
            if (isset($_POST['configure_content_languages'])) {
                $content_languages = readarg($_POST['configure_content_languages']);
            }
            if (isset($_POST['configure_default_language'])) {
                $default_language = readarg($_POST['configure_default_language']);
            }
            if (isset($_POST['configure_db_flag'])) {
                $db_flag = readarg($_POST['configure_db_flag']) == 'yes' ? true : false;
            }
            if (isset($_POST['configure_db_type'])) {
                $db_type = readarg($_POST['configure_db_type']);
            }
            if (isset($_POST['configure_db_reuse'])) {
                $db_reuse = readarg($_POST['configure_db_reuse']) == 'yes' ? true : false;
            }
            if (isset($_POST['configure_db_admin_user'])) {
                $db_admin_user = readarg($_POST['configure_db_admin_user']);
            }
            if (isset($_POST['configure_db_admin_password'])) {
                $db_admin_password = readarg($_POST['configure_db_admin_password']);
            }
            if (isset($_POST['configure_db_name'])) {
                $db_name = readarg($_POST['configure_db_name']);
            }
            if (isset($_POST['configure_db_host'])) {
                $db_host = readarg($_POST['configure_db_host']);
            }
            if (isset($_POST['configure_db_user'])) {
                $db_user = readarg($_POST['configure_db_user']);
            }
            if (isset($_POST['configure_db_password'])) {
                $db_password = readarg($_POST['configure_db_password']);
            }
            if (isset($_POST['configure_db_prefix'])) {
                $db_prefix = readarg($_POST['configure_db_prefix']);
            }
            if (isset($_POST['configure_site_admin_user'])) {
                $site_admin_user = readarg($_POST['configure_site_admin_user']);
            }
            if (isset($_POST['configure_site_admin_password'])) {
                $site_admin_password = readarg($_POST['configure_site_admin_password']);
            }
            break;
        default:
            break;
    }
    $bad_token = false;
    $missing_sitename = false;
    $missing_webmaster = false;
    $missing_content_languages = false;
    $bad_content_languages = false;
    $missing_default_language = false;
    $bad_default_language = false;
    $missing_db_admin_user = false;
    $missing_db_admin_password = false;
    $bad_db_type = false;
    $missing_db_name = false;
    $bad_db_name = false;
    $bad_db_prefix = false;
    $missing_db_host = false;
    $bad_db_host = false;
    $missing_db_user = false;
    $bad_db_user = false;
    $missing_db_password = false;
    $weak_db_password = false;
    $missing_site_admin_user = false;
    $bad_site_admin_user = false;
    $missing_site_admin_password = false;
    $weak_site_admin_password = false;
    $db_error = false;
    $file_error = false;
    $internal_error = false;
    switch ($action) {
        case 'configure':
            if (!isset($_SESSION['configure_token']) or $token != $_SESSION['configure_token']) {
                $bad_token = true;
            }
            if (empty($sitename)) {
                $missing_sitename = true;
            }
            if (empty($webmaster)) {
                $missing_webmaster = true;
            }
            if (empty($content_languages)) {
                $missing_content_languages = true;
            } else {
                if (!is_array($content_languages)) {
                    $bad_content_languages = true;
                } else {
                    foreach ($content_languages as $clang) {
                        if (!in_array($clang, $system_languages)) {
                            $bad_content_languages = true;
                            break;
                        }
                    }
                    if (empty($default_language)) {
                        $default_language = $content_languages[0];
                    } else {
                        if (!in_array($default_language, $content_languages)) {
                            $bad_default_language = true;
                        }
                    }
                }
            }
            if ($db_flag) {
                if (empty($db_name)) {
                    $missing_db_name = true;
                } else {
                    if (!$db_reuse and !validate_db_name($db_name)) {
                        $bad_db_name = true;
                    }
                }
                if (empty($db_type) or !in_array($db_type, array('mysql', 'pgsql'))) {
                    $bad_db_type = true;
                }
                if (!empty($db_prefix) and !validate_db_name($db_prefix)) {
                    $bad_db_prefix = true;
                }
                if (!$db_reuse) {
                    if (empty($db_admin_user)) {
                        $missing_db_admin_user = true;
                    }
                    if (empty($db_admin_password)) {
                        $missing_db_admin_password = true;
                    }
                }
                if (empty($db_host)) {
                    $missing_db_host = true;
                } else {
                    if (!(validate_host_name($db_host) or validate_ip_address($db_host))) {
                        $bad_db_host = true;
                    }
                }
                if (empty($db_user)) {
                    $missing_db_user = true;
                } else {
                    if (!$db_reuse and !validate_db_name($db_user)) {
                        $bad_db_user = true;
                    }
                }
                if (empty($db_password)) {
                    $missing_db_password = true;
                } else {
                    if (!$db_reuse and !validate_password($db_password)) {
                        $weak_db_password = true;
                    }
                }
                if (empty($site_admin_user)) {
                    $missing_site_admin_user = true;
                } else {
                    if (!validate_db_name($site_admin_user)) {
                        $bad_site_admin_user = true;
                    }
                }
                if (empty($site_admin_password)) {
                    $missing_site_admin_password = true;
                } else {
                    if (!validate_password($site_admin_password)) {
                        $weak_site_admin_password = true;
                    }
                }
            }
            break;
        default:
            break;
    }
    switch ($action) {
        case 'configure':
            if ($bad_token or $bad_write_permission or $missing_sitename or $missing_webmaster or $missing_content_languages or $bad_default_language or $missing_db_admin_user or $missing_db_admin_password or $missing_db_name or $bad_db_name or $bad_db_type or $missing_db_host or $bad_db_host or $missing_db_user or $bad_db_user or $missing_db_password or $weak_db_password or $missing_site_admin_user or $bad_site_admin_user or $missing_site_admin_password or $weak_site_admin_password) {
                break;
            }
            $site_admin_mail = $site_admin_user . '@' . $sitename;
            $languages = array($default_language);
            foreach ($content_languages as $clang) {
                if ($clang != $default_language) {
                    $languages[] = $clang;
                }
            }
            if ($db_flag) {
                switch ($db_type) {
                    case 'pgsql':
                        require_once 'configurepgsql.php';
                        break;
                    case 'mysql':
                    default:
                        require_once 'configuremysql.php';
                        break;
                }
                if (!$db_reuse) {
                    try {
                        create_db($db_admin_user, $db_admin_password, 'localhost', $db_name, $db_user, $db_password);
                    } catch (PDOException $e) {
                        $db_error = $e->getMessage();
                        break;
                    }
                }
                try {
                    init_db($db_host, $db_name, $db_user, $db_password, $db_prefix, $site_admin_user, $site_admin_password, $site_admin_mail, $default_language);
                } catch (PDOException $e) {
                    $db_error = $e->getMessage();
                    break;
                }
                $img = identicon($site_admin_user, AVATAR_SIZE);
                @imagepng($img, AVATARS_DIR . DIRECTORY_SEPARATOR . $site_admin_user . '.png');
                $db_inc = build_db_inc($db_host, $db_name, $db_user, $db_password, $db_prefix, $db_type);
                $config_inc = build_config_inc($sitename, $webmaster, $site_admin_user, 1, 'home', 'page', $languages);
                $features = array('captcha', 'avatar', 'rssfeed', 'home', 'contact', 'user', 'nobody', 'account', 'password', 'newuser', 'search', 'suggest', 'download', 'admin', 'adminuser', 'pagecontent', 'pagevisit', 'page', 'editpage', 'folder', 'folderedit', 'story', 'storyedit', 'book', 'bookedit', 'newsletter', 'newsletteredit', 'newslettersubscribe', 'newsletterunsubscribe', 'thread', 'threadedit', 'node', 'editnode', 'donation', 'paypalreturn', 'paypalcancel', 'sslverifyclient', 'saction');
                $aliases_inc = build_aliases_inc($features, $languages);
            } else {
                $db_inc = build_db_inc(false, false, false, false, false, false);
                $config_inc = build_config_inc($sitename, $webmaster, $site_admin_user, false, 'homepage', 'anypage', $languages);
                $features = array('captcha', 'avatar', 'rssfeed', 'homepage', 'contact', 'donation', 'paypalreturn', 'paypalcancel', 'sslverifyclient', 'saction');
                $aliases_inc = build_aliases_inc($features, $languages);
            }
            if (!$db_inc or !$config_inc or !$aliases_inc) {
                $internal_error = true;
                break;
            }
            if (!@file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . DB_INC, array('<?php', $db_inc))) {
                $file_error = true;
                break;
            }
            if (!@file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . CONFIG_INC, array('<?php', $config_inc))) {
                $file_error = true;
                break;
            }
            if (!@file_put_contents(CONFIG_DIR . DIRECTORY_SEPARATOR . ALIASES_INC, array("<?php", $aliases_inc))) {
                $file_error = true;
                break;
            }
            $sitemap_xml = build_sitemap_xml($sitename, $languages);
            @file_put_contents(ROOT_DIR . DIRECTORY_SEPARATOR . SITEMAP_XML, array('<?xml version="1.0" encoding="UTF-8"?>', "\n", $sitemap_xml));
            $robots_txt = build_robots_txt($sitename, $languages);
            @file_put_contents(ROOT_DIR . DIRECTORY_SEPARATOR . ROBOTS_TXT, $robots_txt);
            $logo = strlogo($sitename);
            @imagepng($logo, LOGOS_DIR . DIRECTORY_SEPARATOR . SITELOGO_PNG, 9, PNG_ALL_FILTERS);
            imagedestroy($logo);
            session_reopen();
            reload($base_url);
            return false;
        default:
            break;
    }
    $_SESSION['configure_token'] = $token = token_id();
    $errors = compact('bad_write_permission', 'missing_sitename', 'missing_webmaster', 'missing_content_languages', 'bad_default_language', 'missing_db_admin_user', 'missing_db_admin_password', 'bad_db_type', 'missing_db_name', 'bad_db_name', 'missing_db_host', 'bad_db_host', 'bad_db_prefix', 'missing_db_user', 'bad_db_user', 'missing_db_password', 'weak_db_password', 'missing_site_admin_user', 'bad_site_admin_user', 'missing_site_admin_password', 'weak_site_admin_password');
    $output = view('configure', $lang, compact('token', 'sitename', 'webmaster', 'db_error', 'file_error', 'internal_error', 'content_languages', 'default_language', 'db_flag', 'db_type', 'db_reuse', 'db_admin_user', 'db_admin_password', 'db_name', 'db_host', 'db_prefix', 'db_user', 'db_password', 'site_admin_user', 'site_admin_password', 'errors'));
    return $output;
}