Example #1
0
 /**
  * Generates a model for a given schema
  * 
  * @usage ./metal model/create --database=default --schema=public --table=user --related
  * @switch database The name of the database in the conf file
  * @switch schema The name of the schema, default is 'public'
  * @switch table The name of the table to generate the model for
  * @switch related Boolean determines if any related models should be generated.
  */
 public function create()
 {
     $db = Database::Get($this->request->input->database);
     $schemaName = $this->request->input->schema ? $this->request->input->schema : 'public';
     $schema = $db->table($schemaName, $this->request->input->table, $this->request->input->related);
     $rel_classname = '';
     $names = explode('_', $this->request->input->table);
     foreach ($names as $n) {
         $rel_classname .= ucfirst($n);
     }
     $view = new View('index.html', $this, PATH_SYS . 'shell/view/model/');
     $model = $view->render(array('classname' => $rel_classname, 'schema' => $schema, 'database' => $this->request->input->database));
     $path = PATH_APP . 'model/' . $schemaName;
     if (!file_exists($path)) {
         mkdir($path);
     }
     file_put_contents($path . '/' . $schema->tablename . EXT, $model);
     foreach ($schema->related as $table) {
         $rel_classname = '';
         $names = explode('_', $table->tablename);
         foreach ($names as $n) {
             $rel_classname .= ucfirst($n);
         }
         $model = $view->render(array('classname' => $rel_classname, 'schema' => $table, 'database' => $this->request->input->database));
         $path = PATH_APP . 'model/' . $table->schema;
         if (!file_exists($path)) {
             mkdir($path);
         }
         file_put_contents($path . '/' . $table->tablename . EXT, $model);
     }
     die;
 }
Example #2
0
 function actionIndex()
 {
     if (isset($_SESSION['id'])) {
         header("Location: /cabinet");
     }
     if (isset($_GET['result'])) {
         switch (@$_GET['result']) {
             case 'regerror':
                 echo "<script>alert('Введены неверные данные или аккаунт уже существует');</script>";
                 break;
             case 'loginerror':
                 echo "<script>alert('Неверный логин или пароль');</script>";
                 break;
             default:
                 break;
         }
     }
     $main = new Templater();
     $main->import("interface/index.tpl");
     $main->setvar("%URL%", "http://" . $GLOBALS['url']);
     $main->setvar("%LOGIN_URL%", "/index/login");
     $main->setvar("%STORAGE_TPL_URL%", "/storage/tpl");
     $main->setvar("%YEAR%", date("Y"));
     $main->setvar("%CSS%", "<style>" . templater("css/main.css", array("%ROOT%" => "/storage/tpl")) . "</style>");
     $main->setvar("%REGISTER%", template("interface/register.tpl"));
     $cursor = Database::Get("news", array('public' => 1))->sort(array('date' => -1))->limit(1)->getNext();
     $newss = templater("interface/news.tpl", array("%SUBJECT%" => $cursor['title'], "%DATE%" => $cursor['date'], "%ANNOUNCE%" => $cursor['short'], "%LINK_MORE%" => "http://" . $GLOBALS['url'] . "/news/read?id=" . $cursor['_id'], "%ID%" => $cursor['_id']));
     $main->setvar("%NEWS%", $newss);
     $main->setvar("%GAME_TITLE%", $GLOBALS['name']);
     $main->setvar("%STORAGE_STATIC_URL%", "/storage/static");
     $main->renderEcho();
 }
Example #3
0
 protected function setUp()
 {
     $this->db = Database::Get('default');
     try {
         $this->db->execute_file(PATH_ROOT . 'sql/pgsql/blank.sql');
     } catch (Exception $ex) {
     }
     $this->db->execute_file(PATH_ROOT . 'sql/pgsql/schema.sql');
 }
Example #4
0
    public function index($database,$table)
    {
	$db=Database::Get($database);

	$name=explode('.',$table);
	$schema=$name[0];
	$table=$name[1];

	$tableschema=$db->table($schema,$table,true,false);

	$classname='';
	$names=explode('_',$table);
	$filename='';
	foreach($names as $name)
	{
	    $filename.=strtolower($name).'_';
	    $classname.=ucfirst($name);
	}

	$filename=trim($name,'_');

	$data=array(
	    'classname' => $classname,
	    'schema' => $schema,
	    'filename' => $filename,
	    'table' => $table,
	    'database' => $database,
	    'tableschema' => $tableschema
	);


	$view=new View(PATH_APP.'view/shell/', 'create/model/base.txt');
	$base=$view->render($data);

	$view=new View(PATH_APP.'view/shell/', 'create/model/child.txt');
	$child=$view->render($data);

	$path=PATH_APP."model/$schema/";
	if (!file_exists($path))
	    mkdir($path,0777,true);

	$data['base']=$path.'base_'.$filename.EXT;
	file_put_contents($path.'base_'.$filename.EXT, $base);
	
	if ((!file_exists($path.$filename.EXT)) || ((file_exists($path.$filename.EXT)) && ($this->post->overwrite)))
	{
	    file_put_contents($path.$filename.EXT, $child);
	    $data['child']=$path.$filename.EXT;
	}

	return $data;
    }
Example #5
0
 public function actionHandler()
 {
     $last_id = isset($_POST['last_id']) ? (int) $_POST['last_id'] : 0;
     $result = array();
     if (!empty($_POST['text'])) {
         $sth = Database::Insert("chat", array('user' => char()->name, 'text' => $_POST['text'], 'date' => time()));
     }
     $sth = Database::Get("chat", array('date' => array('$gt' => $last_id)))->sort(array('date' => 1));
     foreach ($sth as $o) {
         $result[] = $o;
     }
     echo json_encode($result);
 }
Example #6
0
 /**
  * Function for reading a session
  *
  * Will use the given id to load a session from the database.
  *
  * @param string $id A PHP session id to search for in the database
  *
  * @return string Will return an empty string if session does not exist - session data otherwise
  */
 public function read($id)
 {
     if (Database::Exists(LWC::QUERY_SESSION_READ, [':id', $id, PDO::PARAM_STR])) {
         $data = base64_decode(Database::Get("data"));
         // Decode the session data from the database
         $this->checksum = md5($data);
         // Calculate a checksum of the data
         return $data;
         // Return the data
     } else {
         return '';
     }
     // Return an empty string - PHP will know the session does not exist.
 }
Example #7
0
 function actionIndex()
 {
     $main = new Templater();
     $main->import("interface/news_list.tpl");
     $main->setvar("%URL%", "http://" . $GLOBALS['url']);
     $main->setvar("%STORAGE_TPL_URL%", "/storage/tpl");
     $main->setvar("%YEAR%", date("Y"));
     $main->setvar("%GAME_TITLE%", $GLOBALS['name']);
     $main->setvar("%STORAGE_STATIC_URL%", "/storage/static");
     $news = Database::Get("news", array('public' => 1))->sort(array('date' => -1));
     $html = '';
     foreach ($news as $array) {
         $html .= templater("interface/news.tpl", array("%SUBJECT%" => $array['title'], "%DATE%" => $array['date'], "%ANNOUNCE%" => $array['short'], "%LINK_MORE%" => "http://" . $GLOBALS['url'] . "/news/read?id=" . $array['_id'], "%ID%" => $array['_id']));
     }
     $main->setvar("%CONTENT%", $html);
     $main->renderEcho();
 }
Example #8
0
 function actionMakechar()
 {
     $error = '';
     if (isset($_POST['name'])) {
         $maxchars = Database::GetOne("config", array("mod" => "auth"))['maxchars'];
         $chars = Database::Get("characters", array("player" => $_SESSION['id']))->count();
         if ($chars >= $maxchars) {
             echo "Исчерпан лимит персонажей на одного игрока (" . $maxchars . ")";
         } else {
             $id = Char::create(array("name" => $_POST['name'], "gender" => $_POST['gender'], "about" => $_POST['about']));
             if ($id != false) {
                 header("Location: /");
             } else {
                 $error = "Персонаж уже существует";
             }
         }
     }
 }
 public static function mapchars($array)
 {
     $ccchar = Database::Get("characters", array("map" => (string) $array['map'], 'online' => array('$gt' => time())));
     $answer = array();
     foreach ($ccchar as $c) {
         if (__toString($c['_id']) == $_SESSION['cid']) {
             continue;
         }
         $c['_id'] = __toString($c['_id']);
         $answer[$c['_id']]['id'] = $c['_id'];
         $answer[$c['_id']]['name'] = $c['name'];
         $answer[$c['_id']]['x'] = $c['pos_x'];
         $answer[$c['_id']]['y'] = $c['pos_y'];
         $answer[$c['_id']]['skin'] = $c['skin'];
         $answer[$c['_id']]['dir'] = $c['dir'];
     }
     $answer = json_encode($answer, JSON_FORCE_OBJECT);
     return $answer;
 }
Example #10
0
}
?>
            </div>
        </div>
    </div>
    <!-- /.col-sm-4 -->
    <div class="col-sm-4">
        <div class="panel panel-success">
            <div class="panel-heading">
                <h3 class="panel-title">Персонажи</h3>
            </div>
            <div class="panel-body">
                <ul>
                    <?php 
$a1 = Database::Get("characters", array("player" => $_GET['id']));
$a2 = Database::Get("characters", array("player" => toId($_GET['id'])));
foreach ($a1 as $array) {
    echo '<li><a href="/admin/char?id=' . $array['_id'] . '">' . $array['name'] . '</a></li>';
}
foreach ($a2 as $array) {
    echo '<li><a href="/admin/char?id=' . $array['_id'] . '">' . $array['name'] . '</a></li>';
}
?>
                </ul>
            </div>
			</div>
        <div class="panel panel-info">
            <div class="panel-heading">
                <h3 class="panel-title">Добавить поле БД</h3>
            </div>
            <div class="panel-body">
Example #11
0
function checkTimers()
{
    $ts = Database::Get("timers", array());
    foreach ($ts as $array) {
        if ($array['time'] <= time()) {
            eval($array['code']);
            Database::Remove('timers', array("id" => $array['id']));
        }
    }
}
Example #12
0
 /**
  * 表格内容
  * 
  * @params params 参数列表
  *
  */
 private function getContent()
 {
     $MyDatabase = Database::Get();
     $Table = '`' . DB_TABLE_PRE . $this->params['table'] . '`';
     $SqlWhere = @$this->params['where'];
     $SqlOrderBy = @$this->params['order'];
     if ($SqlOrderBy != '') {
         $SqlOrderBy = 'ORDER BY ' . $SqlOrderBy;
     }
     $SqlLimit = ' LIMIT ' . ($this->params['page'] - 1) * $this->params['pagesize'] . ' ,' . $this->params['pagesize'] . ';';
     $SqlStr = ' SELECT COUNT( * ) FROM ' . $Table;
     $SqlStr .= $SqlWhere;
     $MyDatabase->SqlStr = $SqlStr;
     if ($MyDatabase->Query()) {
         $this->recordcount = $MyDatabase->ResultArr[0][0];
     }
     $SqlStr = 'SELECT ' . $this->params['column'] . ' FROM ' . $Table;
     $SqlStr .= $SqlWhere;
     $SqlStr .= $SqlOrderBy;
     $SqlStr .= $SqlLimit;
     $MyDatabase->SqlStr = $SqlStr;
     DebugStr($SqlStr);
     if ($MyDatabase->Query2()) {
         $this->columns = $MyDatabase->ResultArr;
     }
     //分页用
     $this->page = $this->params['page'];
     $this->pagesize = $this->params['pagesize'];
 }
Example #13
0
<?php 
$chars = Database::Get("characters", array('online' => array('$gt' => time())))->limit(100);
echo '<h3>В данный момент онлайн ' . $chars->count() . ' персонажей</h3>';
foreach ($chars as $a) {
    echo '<div class="col-lg-2 text-center"><div class="panel panel-default"><div class="panel-body"><a href="/admin/char?id=' . $a['_id'] . '">' . $a['name'] . '</a></div></div></div>';
}
Example #14
0
<?php

//配置函数
if (strpos(' ' . $_SERVER["HTTP_HOST"], 'mingyihui.cc') || strpos(' ' . $_SERVER["HTTP_HOST"], 'localhost')) {
    require 'include/config_local.php';
    //本地调试用Config文件
} else {
    require 'include/config.php';
    //网络用Config文件
}
session_start();
//session
require 'include/function.php';
//函数地址
require 'class/' . DB_TYPE . '.php';
$MyDatabase = Database::Get();
//数据库类
//默认参数
$pagenum = Request('pagenum') + 0;
if ($pagenum == 0) {
    $pagenum = 1;
}
//读取页数
$pagesize = 20;
//每页显示数
$recordcount = 0;
//记录数
$refresh_msg = '[<font color=blue>不成功</font>],返回首页。';
$refresh_txt = '失败';
Example #15
0
<?php 
if (isset($_GET['count'])) {
    $c = $_GET['count'];
} else {
    $c = 10;
}
$reports = Database::Get("reports", array())->limit($c);
echo 'показывать на страницу: <form action="" method="GET"><input type="text" value="' . $c . '" name="count"><input type="submit" value="Показать"></form><hr>';
foreach ($reports as $r) {
    echo '<div class="well"><h3>от ' . $r['author'] . '</h3><p>' . $r['message'] . '</p></div>';
}
Example #16
0
    /**
     * Constructor
     * 
     * @param  mixed $id ID of object, can be null.
     * @param  array $fields Array of Field objects to bind properties to, can be null
     * @param  Database $db Database connection, can be null
     * @param  array	$row Database row to bind to, can be null
     */
    public function __construct($id=null,$fields=null,$db=null,$row=null)
    {
	// If a db object has been passed in, assign it.
	if (isset($db))
		$this->db=$db;
	else
	$this->db=Database::Get($this->database);

	// give the class a chance to describe itself for special case
	// or business rule setup
	$this->describe();
		
		// CRUD:  pre_read hook
        if (isset($id) || isset($fields) || isset($row))

	$this->pre_read();
        
	if (isset($id))
	{
		$this->primary_key_value=$id;
		$this->reload();
	}
	else if (isset($fields))  // someone passed in fields to assign
	{
		// loop through and assign values
		foreach($fields as $key=>$value)
		$this->fields[$key]=$value;
	}
	else if (isset($row))	// someone passsed in a db row for us to bind to.
		$this->bind($row);
        
		// CRUD:  post_read hook
        if (isset($id) || isset($fields) || isset($row))
            $this->post_read();
    }
Example #17
0
 protected function setUp()
 {
     $this->db = Database::Get('default');
     $this->db->execute_file(PATH_ROOT . 'sql/pgsql/test.sql');
 }
    echo "<form action='' method='POST'>\n        <label for='title'>Название страницы</label>\n\t\t<input id='title' type='text' style='width:635px;' name='title'><br>\n\t\t<label for='page_type'>Избранное</label>\n\t\t<input id='page_type' type='radio' name='type'><br>\n        <label for='title'>Алиас (только английские буквы)</label>\n        <input id='title' type='text' style='width:513px;' name='alias'><br>\n        <textarea rows=15 cols=105 name='add'></textarea> <br>\n        <button type='submit' class='btn btn-success'>Добавить</button>\n        </form>\n        <hr>";
} else {
    echo "";
}
?>
<h2>Страницы</h2>
<h5>Страницы справочника: на данной странице их можно создавать, редактировать, читать и удалять<br>
    <br>
    <hr>
    <a href="?add=1" style="margin-top: -20px;">Новая страница</a>
    <div class="table-responsive">
        <table class="table table-bordered table-hover table-striped">
            <thead>
                <tr>
                    <td>Статья</td>
                    <td></td>
                    <td></td>
                </tr>
            </thead>
            <tbody>

                <?php 
$articles = Database::Get('wiki_pages');
foreach ($articles as $item) {
    echo "<tr><td> <b><font size=3>" . $item['title'] . "</font></b> </td><td> <a href='?edit=" . $item['alias'] . "'>Редактировать</a> </td><td> <a href='?remove=" . $item['alias'] . "'>Удалить</a> </td></tr>";
}
?>

            </tbody>
        </table>
    </div>
Example #19
0
 /**
  * returns an instance of the model's database,
  * override in base classes where you have special needs.
  */
 protected function get_db()
 {
     return Database::Get($this->database);
 }
Example #20
0
if (isset($_POST['new'])) {
    $id = new MongoId();
    Database::Insert("news", array("_id" => $id, "short" => '', "title" => '', "full" => '', "date" => raptor_date(), "public" => '1'));
    die("<script>location.href = '/admin/news?edit=" . $id . "';</script>");
}
if (isset($_GET['edit'])) {
    $array = Database::GetOne("news", array("_id" => toId($_GET['edit'])));
    echo "<form action='' method='POST'>\n\t\t<input class='form-control' name='title' value='" . $array['title'] . "' placeholder='Заголовок'>\n\t\t<textarea rows=15 cols=105 placeholder='Анонс (краткое описание)' name='short'>" . $array['short'] . "</textarea> <br>\n        <textarea rows=15 cols=105 placeholder='Полный текст' name='full'>" . $array['full'] . "</textarea> <br>\n        <button type='submit' class='btn btn-default'>Сохранить</button>\n        </form>\n        <hr>";
}
?>

<div class="table-responsive">
    <table class="table table-bordered table-hover table-striped">
        <thead>
            <tr>
                <td>Заголовок</td>
                <td></td>
            </tr>
        </thead>
        <tbody>

            <?php 
$arrays = Database::Get("news", array());
foreach ($arrays as $array) {
    echo "<tr><td> <b><font size=3>" . $array['title'] . "</font></b> </td><td> <a href='?edit=" . $array['_id'] . "'>Редактировать</a> </td></tr>";
}
?>

        </tbody>
    </table>
</div>
Example #21
0
 /**
  * Function to log a user in
  *
  * Will check email/username and password against database.
  *
  * @param string $identifier The username or email address for an account
  * @param string $pasword The password of the account
  *
  * @return bool Will return true if the user was logged in successfully, false otherwise
  */
 static function Login($identifier, $password)
 {
     if (Database::Exists('SELECT password, id, username, rank FROM lw_users WHERE (email = :email OR username = :username) AND enabled = 1', [[':email', $identifier], [':username', $identifier]])) {
         if (password_verify($password, Database::Get('password'))) {
             session('loggedin', true);
             session('userid', Database::Get('id'));
             session('username', Database::Get('username'));
             session('rank', Database::Get('rank'));
             Lightwork::Log('User logged in.', Lightwork::LOG_DEBUG);
             return true;
         }
     }
     Lightwork::Log('User failed to provide proper credentials.', Lightwork::LOG_DEBUG);
     return false;
 }
Example #22
0
<?php

if (SHOW_DEBUG == 1) {
    echo "页面执行时间 <strong>" . getprocesstime($startime) . "</strong> 秒|";
    echo Database::Get()->PrintDebug();
}
Example #23
0
 static function GetUsers()
 {
     if (Authentication::IsLogged()) {
         $id = Session::Get('current_user')->Get('id');
     }
     $db = new Database();
     $users = array();
     $db->Select();
     if (isset($id)) {
         $db->Where('id', $id, '!=');
     }
     $result = $db->Get(Config::Get('db.table'));
     if ($result) {
         foreach ($result as $value) {
             $users[] = new User($value);
         }
         return $users;
     }
     return false;
 }