updates system

This commit is contained in:
Ulf Gebhardt 2013-04-21 17:27:57 +02:00
parent a6feed60e1
commit c9d498a595
75 changed files with 1076 additions and 402 deletions

View File

@ -1,7 +0,0 @@
<?php
$autoload = SYSTEM\autoload::getInstance();
$autoload->registerFolder(dirname(__FILE__).'/db/','DBD');
$autoload->registerFolder(dirname(__FILE__).'/tbl/','DBD');
$autoload->registerFolder(dirname(__FILE__).'/tbl/analysis/','DBD\ANALYSIS');

View File

@ -1,9 +0,0 @@
<?php
namespace DBD;
class system extends \SYSTEM\DB\DBInfo {
public function __construct() {
throw new Exception('DEFINE ME ADMIN! NOW!');
parent::__construct('DBNAME', 'USER', 'PASSWORD', 'HOST');}
}

View File

@ -1,19 +0,0 @@
<?php
namespace DBD;
class APITable {
const NAME = 'APICalls';
const FIELD_ID = 'ID';
const FIELD_FLAG = 'Flag';
const FIELD_PARENTID = 'ParentID';
const FIELD_PARENTVALUE = 'ParentValue';
const FIELD_NAME = 'Name';
// const FIELD_ISCHACHED = 'IsCached'; use flagfield!
const FIELD_ALLOWEDVALUES = 'AllowedValues';
const VALUE_FLAG_COMMAND = 0;
const VALUE_FLAG_PARAM = 1;
}

View File

@ -1,19 +0,0 @@
<?php
namespace DBD;
class PAGETable {
const NAME = 'PAGECalls';
const FIELD_ID = 'ID';
const FIELD_FLAG = 'Flag';
const FIELD_PARENTID = 'ParentID';
const FIELD_PARENTVALUE = 'ParentValue';
const FIELD_NAME = 'Name';
// const FIELD_ISCHACHED = 'IsCached'; use flagfield!
const FIELD_ALLOWEDVALUES = 'AllowedValues';
const VALUE_FLAG_COMMAND = 0;
const VALUE_FLAG_PARAM = 1;
}

View File

@ -1,11 +0,0 @@
<?php
namespace DBD;
class UserRightsTable {
const NAME = 'user_rights';
const FIELD_USERID = 'userid';
const FIELD_RIGHTID = 'rightid';
}

View File

@ -1,14 +0,0 @@
<?php
namespace DBD;
class UserTable {
const NAME = 'user';
const FIELD_ID = 'id';
const FIELD_USERNAME = 'username';
const FIELD_PASSWORD = 'password';
const FIELD_EMAIL = 'email';
const FIELD_CREATIONTIMESTAMP = 'creationTimestamp';
}

View File

@ -52,88 +52,75 @@ class Api {
// returns resultstring
public function CALL($call = array()){
if( !isset($call) ||
!is_array($call) ||
count($call) <= 0){
throw new \Exception("No call given for the api");
return null;}
if( !isset($call) || !is_array($call) || count($call) <= 0){
throw new \SYSTEM\LOG\ERROR("No call given for the api");}
//Get the Databasetree
$tree = array();
if($this->m_dbinfo instanceof \SYSTEM\DB\DBInfo){
$tree = self::getApiTree();}
else {
$tree = self::getApiTree();
if(!is_array($tree)){
throw new \SYSTEM\LOG\ERROR("Database Tree for Api empty - cannot proced!");}
} else {
if(!is_array($this->m_dbinfo)){
throw new Exception('No Connectioninfo and no call table given to the api');}
throw new \SYSTEM\LOG\ERROR('No Connectioninfo and no call table given to the api');}
$tree = $this->m_dbinfo;
}
//print_r($tree);
if(!is_array($tree)){
throw new \Exception("Database Tree for Api empty - cannot proced!");}
}
//Commands
$commands = array();
$parentid = -1;
foreach($tree as $item){
if( $item[\DBD\APITable::FIELD_FLAG] == \DBD\APITable::VALUE_FLAG_COMMAND &&
$item[\DBD\APITable::FIELD_PARENTID] == $parentid &&
isset($call[$item[\DBD\APITable::FIELD_NAME]])){
if( isset($item[\DBD\APITable::FIELD_PARENTVALUE]) &&
$commands[count($commands)-1][1] != $item[\DBD\APITable::FIELD_PARENTVALUE]){
continue;}
$commands[] = array($item,$call[$item[\DBD\APITable::FIELD_NAME]]);
$parentid = $item[\DBD\APITable::FIELD_ID];
foreach($tree as $item){
if( intval($item[\DBD\SYSTEM\APITable::FIELD_FLAG]) == \DBD\SYSTEM\APITable::VALUE_FLAG_COMMAND &&
intval($item[\DBD\SYSTEM\APITable::FIELD_PARENTID]) == $parentid &&
isset($call[$item[\DBD\SYSTEM\APITable::FIELD_NAME]])){
if( isset($item[\DBD\SYSTEM\APITable::FIELD_PARENTVALUE]) &&
$commands[count($commands)-1][1] != $item[\DBD\SYSTEM\APITable::FIELD_PARENTVALUE]){
continue;
}
$commands[] = array($item,$call[$item[\DBD\SYSTEM\APITable::FIELD_NAME]]);
$parentid = intval($item[\DBD\SYSTEM\APITable::FIELD_ID]);
}
}
//Parameters
$parameters = array();
$lastCommand = $commands[count($commands)-1][0];
foreach($tree as $item){
if( $item[\DBD\APITable::FIELD_FLAG] == \DBD\APITable::VALUE_FLAG_PARAM &&
$item[\DBD\APITable::FIELD_PARENTID] == $lastCommand[\DBD\APITable::FIELD_ID]){
if( intval($item[\DBD\SYSTEM\APITable::FIELD_FLAG]) == \DBD\SYSTEM\APITable::VALUE_FLAG_PARAM &&
intval($item[\DBD\SYSTEM\APITable::FIELD_PARENTID]) == $lastCommand[\DBD\SYSTEM\APITable::FIELD_ID]){
if( isset($item[\DBD\APITable::FIELD_PARENTVALUE]) &&
$commands[count($commands)-1][1] != $item[\DBD\APITable::FIELD_PARENTVALUE]){
if( isset($item[\DBD\SYSTEM\APITable::FIELD_PARENTVALUE]) &&
$commands[count($commands)-1][1] != $item[\DBD\SYSTEM\APITable::FIELD_PARENTVALUE]){
continue;}
if(!isset($call[$item[\DBD\APITable::FIELD_NAME]])){
throw new \Exception('Parameter missing: '.$item[\DBD\APITable::FIELD_NAME]);}
if(!isset($call[$item[\DBD\SYSTEM\APITable::FIELD_NAME]])){
throw new \SYSTEM\LOG\ERROR('Parameter missing: '.$item[\DBD\SYSTEM\APITable::FIELD_NAME]);}
if( !method_exists($this->m_verifyclass, $item[\DBD\APITable::FIELD_ALLOWEDVALUES]) ||
!$this->m_verifyclass->$item[\DBD\APITable::FIELD_ALLOWEDVALUES]($call[$item[\DBD\APITable::FIELD_NAME]])){
throw new \Exception('Parameter type missmacht or Missing Verifier. Param: '.$item[\DBD\APITable::FIELD_NAME].' Verifier: '.$item[\DBD\APITable::FIELD_ALLOWEDVALUES]);}
if( !method_exists($this->m_verifyclass, $item[\DBD\SYSTEM\APITable::FIELD_ALLOWEDVALUES]) ||
!$this->m_verifyclass->$item[\DBD\SYSTEM\APITable::FIELD_ALLOWEDVALUES]($call[$item[\DBD\SYSTEM\APITable::FIELD_NAME]])){
throw new \SYSTEM\LOG\ERROR('Parameter type missmacht or Missing Verifier. Param: '.$item[\DBD\SYSTEM\APITable::FIELD_NAME].' Verifier: '.$item[\DBD\SYSTEM\APITable::FIELD_ALLOWEDVALUES]);}
$parameters[] = array($item, $call[$item[\DBD\APITable::FIELD_NAME]]);
$parameters[] = array($item, $call[$item[\DBD\SYSTEM\APITable::FIELD_NAME]]);
}
}
//Check
/*echo "<pre>";
print_r($commands);
echo "</pre>";
echo "</br>---</br>";
print_r($parameters);
echo "</br>---</br>";
print_r($call);
echo "</br>---</br>";
echo count($call).'-'.count($parameters).'-'.count($commands);*/
if(count($call) != count($parameters) + count($commands)){
throw new \Exception("Unhandled or misshandled parameters - api query is invalid");}
}
if(count($call) != (count($parameters) + count($commands)) ){
throw new \SYSTEM\LOG\ERROR('Unhandled or misshandled parameters - api query is invalid');}
//Function Name
$command_call = "";
foreach($commands as $com){
if(!\preg_match('^[0-9A-Za-z_]+$^', $com[1])){
throw new \Exception("Call Command can only have letters!");}
throw new \SYSTEM\LOG\ERROR('Call Command can only have letters!');}
if($com[0][\DBD\APITable::FIELD_ALLOWEDVALUES] == 'FLAG'){
$command_call .= '_flag_'.$com[0][\DBD\APITable::FIELD_NAME];
if($com[0][\DBD\SYSTEM\APITable::FIELD_ALLOWEDVALUES] == 'FLAG'){
$command_call .= '_flag_'.$com[0][\DBD\SYSTEM\APITable::FIELD_NAME];
} else {
$command_call .= '_'.$com[0][\DBD\APITable::FIELD_NAME].'_'.\strtolower($com[1]);}
$command_call .= '_'.$com[0][\DBD\SYSTEM\APITable::FIELD_NAME].'_'.\strtolower($com[1]);}
}
$command_call = substr($command_call, 1);
@ -143,7 +130,7 @@ class Api {
$parameter_call[] = $param[1];}
if(!\method_exists($this->m_apiclass, $command_call)){
throw new \Exception("API call is not implemented in API: ".$command_call);}
throw new \SYSTEM\LOG\ERROR("API call is not implemented in API: ".$command_call);}
//Call Function
return \call_user_func_array(array($this->m_apiclass,$command_call),$parameter_call);
@ -152,11 +139,11 @@ class Api {
private function getApiTree(){
$con = new \SYSTEM\DB\Connection($this->m_dbinfo);
$res = $con->query("SELECT * FROM ".\DBD\APITable::NAME." ORDER BY ".\DBD\APITable::FIELD_ID);
$res = $con->query('SELECT * FROM '.\DBD\SYSTEM\APITable::NAME.' ORDER BY "'.\DBD\SYSTEM\APITable::FIELD_ID.'"');
unset($con);
if(!$res){
throw new \Exception("Sql Error ".mysqli_error());}
throw new \SYSTEM\LOG\ERROR('Database Error '.pg_last_error($con));}
$result = array();
while($row = $res->next()){

View File

@ -2,10 +2,7 @@
namespace SYSTEM\API;
abstract class apiloginclass extends \SYSTEM\API\apiclass {
protected abstract static function getUserDBInfo();
class apiloginclass extends \SYSTEM\API\apiclass {
/*
INSERT INTO `APICalls` (`ID`, `Flag`, `ParentID`, `ParentValue`, `Name`, `AllowedValues`) VALUES (0, 0, -1, NULL, 'call', NULL);
INSERT INTO `APICalls` (`ID`, `Flag`, `ParentID`, `ParentValue`, `Name`, `AllowedValues`) VALUES (60, 0, 0, 'account', 'action', NULL);
@ -22,14 +19,14 @@ abstract class apiloginclass extends \SYSTEM\API\apiclass {
INSERT INTO `APICalls` (`ID`, `Flag`, `ParentID`, `ParentValue`, `Name`, `AllowedValues`) VALUES (68, 1, 60, 'create', 'hashed', 'ALL');
*/
public static function call_account_action_login($username, $password, $hashed){
return \SYSTEM\SECURITY\Security::login(static::getUserDBInfo(), $username, $password, $hashed);}
public static function call_account_action_login($username, $password_sha, $password_md5){
return \SYSTEM\SECURITY\Security::login(new \DBD\SYSTEM\systemPostgres(), $username, $password_sha, $password_md5);}
public static function call_account_action_logout(){
return \SYSTEM\SECURITY\Security::logout();}
public static function call_account_action_isloggedin(){
return \SYSTEM\SECURITY\Security::isLoggedIn();}
public static function call_account_action_check($rightid){
return \SYSTEM\SECURITY\Security::check(static::getUserDBInfo(),$rightid);}
public static function call_account_action_create($username, $password, $email, $hashed){
return \SYSTEM\SECURITY\Security::create(static::getUserDBInfo(), $username, $password, $email, $hashed);}
return \SYSTEM\SECURITY\Security::check(new \DBD\SYSTEM\systemPostgres(),$rightid);}
public static function call_account_action_create($username, $password_sha, $email, $locale){
return \SYSTEM\SECURITY\Security::create(new \DBD\SYSTEM\systemPostgres(), $username, $password_sha, $email, $locale);}
}

45
system/cache/cache.php vendored Normal file
View File

@ -0,0 +1,45 @@
<?php
namespace SYSTEM\CACHE;
class cache {
public static function get(\SYSTEM\DB\DBInfo $dbinfo, $cache_id, $ident){
$con = new \SYSTEM\DB\Connection($dbinfo);
$res = $con->prepare( 'checkCache',
'SELECT "data" FROM system.cache'.
' WHERE "CacheID" = $1 AND'.
' "Ident" = $2;',
array($cache_id,$ident));
if(!($result = $res->next())){
return NULL;}
return pg_unescape_bytea($result['data']);
}
public static function put(\SYSTEM\DB\DBInfo $dbinfo, $cache_id, $ident, $data, $fail_on_exist = false){
if((self::get($dbinfo,$cache_id,$ident) != NULL)){
if($fail_on_exist){
return false;}
self::del($dbinfo, $cache_id, $ident);
}
$con = new \SYSTEM\DB\Connection($dbinfo);
$res = $con->prepare( 'insertCache',
'INSERT INTO system.cache ("CacheID", "Ident", "data")'.
' VALUES ($1,$2,$3);',
array($cache_id,$ident,pg_escape_bytea($data)));
return $res->next() ? $data : NULL;
}
public static function del(\SYSTEM\DB\DBInfo $dbinfo, $cache_id, $ident){
$con = new \SYSTEM\DB\Connection($dbinfo);
$res = $con->prepare( 'deleteCache',
'DELETE FROM system.cache'.
' WHERE "CacheID" = $1 AND'.
' "Ident" = $2;',
array($cache_id,$ident));
return $res->next() ? true : false;
}
}

View File

@ -1,7 +0,0 @@
<?php
namespace SYSTEM\DB;
abstract class Query {
abstract public function getSQL();
}

View File

@ -1,14 +0,0 @@
<?php
namespace SYSTEM\DB;
class QueryString extends Query{
private $sqlstr = NULL;
public function __construct($string){
$this->sqlstr = $string;}
public function getSQL(){
return $this->sqlstr;}
}

View File

@ -0,0 +1,40 @@
<?php
namespace SYSTEM\DB;
class Connection extends ConnectionAbstr{
//The open Connection, either ConnectionPG or ConnectionMYS
private $connection = NULL;
//private $dbinfo = NULL;
//Connects to DB, dependent on DBInfo a connection to a PG or MYS will be established
public function __construct(DBInfo $dbinfo){
//$this->dbinfo = $dbinfo;
if($dbinfo instanceof \SYSTEM\DB\DBInfoPG){
$this->connection = new \SYSTEM\DB\ConnectionPG($dbinfo);
} else if ($dbinfo instanceof \SYSTEM\DB\DBInfoMYS){
$this->connection = new \SYSTEM\DB\ConnectionMYS($dbinfo);
} else if ($dbinfo instanceof \SYSTEM\DB\DBInfoAMQP){
$this->connection = new \SYSTEM\DB\ConnectionAMQP($dbinfo);
} else {
throw new \Exception('Could not understand Database Settings. Check ur Database Settings');}
}
//Destruct connection object.
public function __destruct(){
unset($this->connection);}
//Query connected Database with prepared statements, $stmt = sql string with ?; $values = array of values
public function prepare($stmtName, $stmt, $values){
return $this->connection->prepare($stmtName, $stmt, $values);}
//Close Connection
public function close(){
return $this->connection->close();}
//Query connected Database
public function query($query){
return $this->connection->query($query);}
}

View File

@ -0,0 +1,64 @@
<?php
namespace SYSTEM\DB;
class ConnectionAMQP extends ConnectionAbstr {
private $connection = NULL;
public function __construct(DBInfo $dbinfo){
$this->connection = new \AMQPConnection(
array(
'host' => $dbinfo->m_host,
'vhost' => $dbinfo->m_database,
'port' => $dbinfo->m_port,
'login' => $dbinfo->m_user,
'password' => $dbinfo->m_password
));
$this->connection->connect();
if(!$this->connection || !$this->connection->isConnected()){
throw new \SYSTEM\LOG\ERROR('Cannot connect to the amqp queue!');}
}
public function send($msg){
$channel = new \AMQPChannel($this->connection);
$exchange = new \AMQPExchange($channel);
$exchange->setFlags(AMQP_DURABLE);
$exchange->setName('exchange2');
$exchange->setType('direct');
$exchange->declare();
$queue = new \AMQPQueue($channel);
$queue->setName('series');
$queue->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
$queue->declare();
$queue->bind('exchange2','series');
$channel->startTransaction();
$message = $exchange->publish(json_encode($msg), 'series', AMQP_MANDATORY,
array('content_type' => 'application/json',
'delivery_mode' => 2));
$channel->commitTransaction();
if(!$message) {
throw new \SYSTEM\LOG\ERROR("Error: Message '".$message."' was not sent to queue.!");
}
}
public function __destruct(){
$this->close();
}
public function close(){
if (!$this->connection->disconnect()) {
throw new Exception("Could not disconnect !");
}
}
public function query($query){ }
public function prepare($stmtName, $stmt, $values){}
}

View File

@ -0,0 +1,28 @@
<?php
namespace SYSTEM\DB;
abstract class ConnectionAbstr {
//Connects to Database with given DBInfos
abstract public function __construct(DBInfo $dbinfo);
//Close Connection to Database
abstract public function __destruct();
//Close Connection to Database
abstract public function close();
//Query Database with prepared Statement with $stmtName = name of the stament(pg only) $stmt = string and $values = array()
abstract public function prepare($stmtName, $stmt, $values);
//Query Database with normal Statement with $query = SQLString
abstract public function query($query);
//Convert Prepared Values to SQL Type identifiers
protected static function getPrepareValueType($value){
if(is_double($value)){
return 'd';}
if(is_integer($value)){
return 'i';}
if(is_string($value)){
return 's';}
//blob
return 'b';
}
}

View File

@ -2,83 +2,56 @@
namespace SYSTEM\DB;
class Connection {
class ConnectionMYS extends ConnectionAbstr {
private $connection = NULL;
private $dbinfo = NULL;
//private $dbinfo = NULL;
public function __construct(DBInfo $dbinfo, $new_link = false, $client_flag = 0){
//$this->dbinfo = $dbinfo;
public function __construct(DBInfo $dbinfo, $new_link = false, $client_flag = 0){
$this->dbinfo = $dbinfo;
$this->connection = mysqli_connect($dbinfo->m_host, $dbinfo->m_user, $dbinfo->m_password, $new_link, $client_flag);
if(!$this->connection){
if(!$this->connection){
throw new \Exception('Could not connect to Database. Check ur Database Settings');}
if(!mysqli_select_db($this->connection, $dbinfo->m_database)){
mysqli_close($this->connection);
throw new \Exception('Could not select Database. Check ur Database Settings: '.mysqli_error($this->connection));}
}
public function __destruct(){
public function __destruct(){
$this->close();}
private static function getPrepareValueType($value){
if(is_double($value)){
return 'd';}
if(is_integer($value)){
return 'i';}
if(is_string($value)){
return 's';}
//blob
return 'b';
}
//stmt = sql string with ?
//values = array of values
public function prepare($stmt, $values){
public function prepare($stmtName, $stmt, $values){
$prepStmt = \mysqli_prepare($this->connection, $stmt);
if(!$prepStmt){
throw new \Exception('Prepared Statement prepare fail: '. \mysqli_error($this->connection));}
$types = '';
$binds = array($prepStmt,null);
for($i =0; $i < \count($values);$i++){
$types .= self::getPrepareValueType($values[$i]);
$binds[] = &$values[$i];
}
$binds[1] = $types;
}
$binds[1] = $types;
\call_user_func_array('mysqli_stmt_bind_param', $binds);
if(!mysqli_stmt_execute($prepStmt)){
throw new \Exception("Could not execute prepare statement: ". \mysqli_stmt_error($prepStmt));}
return new ResultMysqliPrepare($prepStmt);
}
public function close(){
public function close(){
return mysqli_close($this->connection);}
public function query($query){
$_query = NULL;
if(\is_string($query)){
$_query = new QueryString($query);
} elseif($query instanceof Query) {
$_query = $query;
} else {
throw new \Exception('Could not understand given Query: '.$query);
}
$result = mysqli_query($this->connection, $_query->getSQL());
public function query($query){
$result = mysqli_query($this->connection, $query);
if(!$result){
throw new \Exception('Could not query Database. Check ur Query Syntax or required Rights: '.mysqli_error($this->connection));}
if($result === TRUE){
return TRUE;}
return new ResultMysqli($result);
}
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace SYSTEM\DB;
class ConnectionPG extends ConnectionAbstr {
private $connection = NULL;
//private $dbinfo = NULL;
public function __construct(DBInfo $dbinfo){
//$this->dbinfo = $dbinfo;
$this->connection = pg_connect("host=".$dbinfo->m_host." port=".$dbinfo->m_port." dbname=".$dbinfo->m_database."
user=".$dbinfo->m_user." password=".$dbinfo->m_password."");
if(!$this->connection){
throw new \SYSTEM\LOG\ERROR('Could not connect to Database. Check ur Database Settings');}
}
public function __destruct(){}
public function prepare($stmtName, $stmt, $values){
$result = pg_query_params($this->connection, 'SELECT name FROM pg_prepared_statements WHERE name = $1', array($stmtName));
//var_dump($stmt);
//var_dump($values);
if (pg_num_rows($result) == 0) {
$result = \pg_prepare($this->connection, $stmtName, $stmt);
}
if(!$result)
throw new \SYSTEM\LOG\ERROR('Prepared Statement prepare fail: '. \pg_last_error($this->connection));
$result = \pg_execute($this->connection, $stmtName, $values);
if(!$result)
throw new \SYSTEM\LOG\ERROR("Could not execute prepare statement: ". \pg_last_error($this->connection));
return new ResultPostgres($result);
}
public function close(){
return pg_close($this->connection);}
public function query($query){
$result = pg_query($this->connection, $query);
if(!$result){
throw new \SYSTEM\LOG\ERROR('Could not query Database. Check ur Query Syntax or required Rights: '.pg_last_error($this->connection));}
if($result === TRUE){
return TRUE;}
return new ResultPostgres($result);
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace SYSTEM\DB;
abstract class DBInfo {
public $m_database = null;
public $m_user = null;
public $m_password = null;
public $m_host = null;
public $m_port = null;
abstract public function __construct($database , $user , $password, $host, $port = null);
}

View File

@ -0,0 +1,19 @@
<?php
namespace SYSTEM\DB;
class DBInfoAMQP extends \SYSTEM\DB\DBInfo {
public function __construct($vhost , $user , $password, $host, $port = null){
$this->m_database = $vhost;
$this->m_user = $user;
$this->m_password = $password;
$this->m_host = $host;
$this->m_port = $port;
if( $this->m_database == null ||
$this->m_user == null ||
$this->m_password == null ||
$this->m_host == null){
throw new \Exception("AMQP Connection Info not correct, vhost, user, password or host are null");}
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace SYSTEM\DB;
class DBInfoMYS extends \SYSTEM\DB\DBInfo {
public function __construct($database , $user , $password, $host, $port = null){
$this->m_database = $database;
$this->m_user = $user;
$this->m_password = $password;
$this->m_host = $host;
$this->m_port = $port;
if( $this->m_database == null ||
$this->m_user == null ||
$this->m_password == null ||
$this->m_host == null){
throw new \Exception("DBInfo not correct, database, user, password or host are null");}
}
}

View File

@ -1,18 +1,14 @@
<?php
namespace SYSTEM\DB;
class DBInfo {
public $m_database = null;
public $m_user = null;
public $m_password = null;
public $m_host = null;
class DBInfoPG extends \SYSTEM\DB\DBInfo {
public function __construct($database , $user , $password, $host){
public function __construct($database , $user , $password, $host, $port = null){
$this->m_database = $database;
$this->m_user = $user;
$this->m_password = $password;
$this->m_host = $host;
$this->m_port = $port;
if( $this->m_database == null ||
$this->m_user == null ||
@ -20,5 +16,4 @@ class DBInfo {
$this->m_host == null){
throw new \Exception("DBInfo not correct, database, user, password or host are null");}
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace SYSTEM\DB;
class ResultAMQP extends \SYSTEM\DB\Result{ // < maybe not ? check if amqpchannel is compatible with dbresult.
private $res = NULL;
private $current = NULL;
//Result from mysql_query
public function __construct($res){
$this->res = $res;}
public function __destruct(){
$this->close();}
public function close(){
pg_free_result($this->res);}
public function count(){
return pg_num_rows($this->res);}
public function affectedRows(){
throw new \SYSTEM\LOG\ERROR("Not Supported!");}
public function next($object = false, $result_type = MYSQL_BOTH){
if($object){
$this->current = pg_fetch_object($this->res);
} else {
$this->current = pg_fetch_assoc($this->res);
}
return $this->current;
}
public function seek($row_number){
return pg_data_seek($this->res,$row_number);}
}

View File

@ -0,0 +1,37 @@
<?php
namespace SYSTEM\DB;
class ResultPostgres extends \SYSTEM\DB\Result{
private $res = NULL;
private $current = NULL;
//Result from mysql_query
public function __construct($res){
$this->res = $res;}
public function __destruct(){
$this->close();}
public function close(){
pg_free_result($this->res);}
public function count(){
return pg_num_rows($this->res);}
public function affectedRows(){
return pg_affected_rows($this->res);}
public function next($object = false, $result_type = MYSQL_BOTH){
if($object){
$this->current = pg_fetch_object($this->res);
} else {
$this->current = pg_fetch_assoc($this->res);
}
return $this->current;
}
public function seek($row_number){
return pg_data_seek($this->res,$row_number);}
}

View File

@ -0,0 +1,9 @@
<?php
$autoload = SYSTEM\autoload::getInstance();
$autoload->registerFolder(dirname(__FILE__).'/db/','DBD');
$autoload->registerFolder(dirname(__FILE__).'/tbl/system/','DBD\SYSTEM');
//$autoload->registerFolder(dirname(__FILE__).'/tbl/definitions/','DBD\DEFINITIONS');
//$autoload->registerFolder(dirname(__FILE__).'/tbl/data/','DBD\DATA');
//$autoload->registerFolder(dirname(__FILE__).'/tbl/data_processed/','DBD\DATA_PROCESSED');

View File

@ -0,0 +1,7 @@
<?php
namespace DBD\SYSTEM;
class systemPostgres extends \SYSTEM\DB\DBInfoPG {
public function __construct() {
parent::__construct('', '', '', '', '');}
}

View File

@ -0,0 +1,19 @@
<?php
namespace DBD\SYSTEM;
class APITable {
const NAME = 'system.api_calls';
const FIELD_ID = 'ID';
const FIELD_FLAG = 'flag';
const FIELD_PARENTID = 'parentID';
const FIELD_PARENTVALUE = 'parentValue';
const FIELD_NAME = 'name';
// const FIELD_ISCHACHED = 'IsCached'; use flagfield!
const FIELD_ALLOWEDVALUES = 'allowedValues';
const VALUE_FLAG_COMMAND = 0;
const VALUE_FLAG_PARAM = 1;
}

View File

@ -0,0 +1,19 @@
<?php
namespace DBD\SYSTEM;
class PAGETable {
const NAME = 'system.page_calls';
const FIELD_ID = 'ID';
const FIELD_FLAG = 'flag';
const FIELD_PARENTID = 'parentID';
const FIELD_PARENTVALUE = 'parentValue';
const FIELD_NAME = 'name';
// const FIELD_ISCHACHED = 'IsCached'; use flagfield!
const FIELD_ALLOWEDVALUES = 'allowedValues';
const VALUE_FLAG_COMMAND = 0;
const VALUE_FLAG_PARAM = 1;
}

View File

@ -0,0 +1,14 @@
<?php
namespace DBD\SYSTEM;
class UserLoginsTable {
const NAME = 'system.user_logins';
const FIELD_ID = 'id';
const FIELD_USERID = 'userID';
const FIELD_IP = 'IP';
const FIELD_SUCC = 'succ';
const FIELD_TIMESTAMP = 'timestamp';
}

View File

@ -0,0 +1,11 @@
<?php
namespace DBD\SYSTEM;
class UserRightsTable {
const NAME = 'system.user_to_rights';
const FIELD_USERID = 'userID';
const FIELD_RIGHTID = 'rightID';
}

View File

@ -0,0 +1,18 @@
<?php
namespace DBD\SYSTEM;
class UserTable {
const NAME = 'system.user';
const FIELD_ID = 'id';
const FIELD_USERNAME = 'username';
const FIELD_PASSWORD_SHA = 'password_sha';
const FIELD_PASSWORD_MD5 = 'password_md5';
const FIELD_EMAIL = 'email';
const FIELD_JOINDATE = 'joindate';
const FIELD_LOCALE = 'locale';
const FIELD_LAST_ACTIVE = 'last_active';
const FIELD_ACCOUNT_FLAG = 'account_flag';
}

View File

@ -1,17 +1,20 @@
<?php
namespace DBD;
namespace DBD\SYSTEM;
class locale_string {
const NAME = 'locale_string';
const NAME = 'system.locale_string';
const FIELD_ID = 'id';
const FIELD_CATEGORY = 'category';
const FIELD_EN_US = 'enUS';
const FIELD_DE_DE = 'deDE';
const VALUE_CATEGORY_TEST1 = 1;
const VALUE_CATEGORY_TEST2 = 2;
const VALUE_CATEGORY_SYSTEM = 10;
const VALUE_CATEGORY_SYSTEM_ERROR = 11;
const VALUE_CATEGORY_DASENSE = 100;
const VALUE_CATEGORY_DASENSE_DEFAULTPAGE = 110;

96
system/log/LOG.php Normal file
View File

@ -0,0 +1,96 @@
<?php
namespace SYSTEM\LOG;
class LOG {
//Singleton
private $handlers = array();
private static $instance = null;
public static function getInstance(){
if (null === self::$instance) {
self::$instance = new self;}
return self::$instance;
}
private function __construct(){}
private function __clone(){}
//$handler = string with classname
public function registerHandler($handler){
if( !class_exists($handler) ||
!\method_exists($handler,'MASK') ||
!\method_exists($handler,'CALL')){
die("You registered an invalid Errorhandler!");}
$this->handlers[] = $handler;
set_error_handler('\SYSTEM\LOG\LOG::__error_handler');
set_exception_handler('\SYSTEM\LOG\LOG::__exception_handler');
}
private function call_handlers(\Exception $E, $errno, $thrown = false){
foreach($this->handlers as $handler){
if( ((call_user_func(array($handler,'MASK')) & $errno)) &&
call_user_func_array(array($handler,'CALL'),array($E,$errno, $thrown))){
return true;
}
}
return false;
}
//Static
//Exceptions
public static function __exception_handler(\Exception $E, $thrown = true){
if($E instanceof \SYSTEM\LOG\ERROR) { return self::LOG_EXCEPTION($E, E_USER_ERROR, $thrown);} //Dies
if($E instanceof \SYSTEM\LOG\WARNING) { return self::LOG_EXCEPTION($E, E_USER_WARNING, $thrown);} //Continues
if($E instanceof \SYSTEM\LOG\INFO) { return self::LOG_EXCEPTION($E, E_NOTICE, $thrown);} //Continues
if($E instanceof \SYSTEM\LOG\DEPRECATED){ return self::LOG_EXCEPTION($E, E_USER_DEPRECATED, $thrown);} //Continues
self::LOG_EXCEPTION($E, E_USER_ERROR, $thrown); //Dies
}
//Triggers error, if not handled by registered Handlers(double check -> but only this way we can keep the original Exception class)
protected static function LOG_EXCEPTION(\Exception $E,$errno = E_USER_ERROR, $thrown = false){
self::__error_handler_e($E, $errno, $thrown);}
//Errors
public static function __error_handler($errno, $errstr, $errfile, $errline){
$e = new \SYSTEM\LOG\ERROR($errstr,$errno);
return self::__error_handler_e($e ,$errno, true);}
public static function __error_handler_e(\Exception $E, $errno, $thrown){
switch ($errno) {
//Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
case E_ERROR: return self::_DIE($E,$errno,true);
//Run-time warnings (non-fatal errors). Execution of the script is not halted.
case E_WARNING: return self::_CONTINUE($E,$errno,true);
//Compile-time parse errors. Parse errors should only be generated by the parser.
case E_PARSE: return self::_DIE($E,$errno,true);
//Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
case E_NOTICE: return self::_CONTINUE($E,$errno,false | $thrown);
//Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP.
case E_CORE_ERROR: return self::_DIE($E,$errno,true);
//Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP.
case E_CORE_WARNING: return self::_CONTINUE($E,$errno,true);
//Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.
case E_COMPILE_ERROR: return self::_DIE($E,$errno,true);
//Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine.
case E_COMPILE_WARNING: return self::_CONTINUE($E,$errno,true);
//User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error().
case E_USER_ERROR: return self::_DIE($E,$errno,false | $thrown);
//User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error().
case E_USER_WARNING: return self::_CONTINUE($E,$errno,false | $thrown);
//Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. Since PHP 5 but not included in E_ALL until PHP 5.4.0 rated in PHP code by using the PHP function trigger_error().
case E_STRICT: return self::_CONTINUE($E,$errno,true);
//Catchable fatal error. It indicates that a probably dangerous error occurred, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR. Since PHP 5.2.0
case E_RECOVERABLE_ERROR: return self::_CONTINUE($E,$errno,true);
//Run-time notices. Enable this to receive warnings about code that will not work in future versions. Since PHP 5.3.0
case E_DEPRECATED: return self::_CONTINUE($E,$errno,true);
//User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error(). Since PHP 5.3.0
case E_USER_DEPRECATED: return self::_CONTINUE($E,$errno,false | $thrown);
default: return false; //Not handled Error use std php handler
}
}
private static function _DIE(\Exception $E, $errno, $thrown = false){
if(self::getInstance()->call_handlers($E, $errno, $thrown)){die();}}
private static function _CONTINUE(\Exception $E, $errno, $thrown = false){
return self::getInstance()->call_handlers($E, $errno, $thrown);}
}

View File

@ -0,0 +1,10 @@
<?php
namespace SYSTEM\LOG;
abstract class error_handler {
//Error Mask E_ALL, E_NOTICE ...
abstract public static function MASK();
//Errorhandler
abstract public static function CALL(\Exception $E, $errno, $thrown);
}

View File

@ -0,0 +1,22 @@
<?php
namespace SYSTEM\LOG;
//Register this before every other handler, cuz this will need to handle every single error.
//And only the first ErrorHandler will be called if he returns true in CALL.
abstract class error_handler_dbwriter extends \SYSTEM\LOG\error_handler {
public static function CALL(\Exception $E, $errno, $thrown){
try{
$con = new \SYSTEM\DB\Connection(static::getDBInfo());
$con->prepare( 'sysLogStmt', 'INSERT INTO system.sys_log '.
'(class, message, code, file, line, trace, ip, querytime) '.
'VALUES ($1, $2, $3, $4, $5, $6, $7, $8);',
array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(),
getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5)));
} catch (\Exception $E){} //Error -> Ignore
return false; //We just log and do not handle the error!
}
abstract protected static function getDBInfo();
}

View File

@ -0,0 +1,15 @@
<?php
namespace SYSTEM\LOG;
class error_handler_jsonoutput extends \SYSTEM\LOG\error_handler {
//Only those who die!
public static function MASK(){ return \E_ALL;} //\E_ERROR | \E_USER_ERROR | \E_CORE_ERROR | \E_COMPILE_ERROR; }
public static function CALL(\Exception $E, $errno, $thrown){
if($thrown){
//TODO move jsonresult into system
echo \SYSTEM\LOG\JsonResult::error($E);
die(); //we can have only one json result per page call else -> multiple headers are sent
}
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace SYSTEM\LOG;
class DEPRECATED extends \Exception {
public function __construct($message = "", $code = 0, $previous = NULL){
parent::__construct($message, $code, $previous);
\SYSTEM\LOG\LOG::__exception_handler($this,false);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace SYSTEM\LOG;
class ERROR extends \Exception {
public function __construct($message = "", $code = 0, $previous = NULL){
parent::__construct($message, $code, $previous);
\SYSTEM\LOG\LOG::__exception_handler($this,false);
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace SYSTEM\LOG;
class INFO extends \Exception {
public function __construct($message = "", $code = 0, $previous = NULL){
parent::__construct($message, $code, $previous);
\SYSTEM\LOG\LOG::__exception_handler($this,false);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace SYSTEM\LOG;
class TranslatableError extends \SYSTEM\LOG\ERROR {
public function __construct($string_id, $code = 0, $previous = NULL , $locale = NULL){
$message = \SYSTEM\locale::getStrings(array($string_id), $locale);
//print_r($message);
if(!isset($message[$string_id])){
throw new \SYSTEM\LOG\ERROR("Could not retrive Errortranslation: ".$string_id);}
parent::__construct($message[$string_id], $code, $previous);
\SYSTEM\LOG\LOG::__exception_handler($this,false);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace SYSTEM\LOG;
class WARNING extends \Exception {
public function __construct($message = "", $code = 0, $previous = NULL){
parent::__construct($message, $code, $previous);
\SYSTEM\LOG\LOG::__exception_handler($this,false);
}
}

View File

@ -0,0 +1,2 @@
<?php
class DEPRECATED extends \SYSTEM\LOG\DEPRECATED {}

View File

@ -0,0 +1,2 @@
<?php
class ERROR extends \SYSTEM\LOG\ERROR {}

View File

@ -0,0 +1,3 @@
<?php
class INFO extends \SYSTEM\LOG\INFO {}

View File

@ -0,0 +1,2 @@
<?php
class WARNING extends \SYSTEM\LOG\WARNING {}

View File

@ -0,0 +1,2 @@
<?php
\SYSTEM\LOG\LOG::getInstance()->registerHandler('\SYSTEM\LOG\error_handler_jsonoutput');

View File

@ -0,0 +1,2 @@
<?php
\SYSTEM\autoload::getInstance()->registerFolder(dirname(__FILE__).'/exceptions_shortcut','');

View File

@ -0,0 +1,2 @@
<?php
\SYSTEM\autoload::getInstance()->registerFolder(dirname(__FILE__).'/result_shortcut','');

View File

@ -0,0 +1,15 @@
<?php
namespace SYSTEM\LOG;
class AbstractResult {
//Returns the result as a string
public static function toString($json_array, $status , $start_time){
throw new RuntimeException("Unimplemented");}
//Return Exception as string
public static function error(\Exception $e){
throw new RuntimeException("Unimplemented");}
//Returns OK status
public static function ok(){
throw new RuntimeException("Unimplemented");}
}

View File

@ -0,0 +1,42 @@
<?php
namespace SYSTEM\LOG;
class JsonResult extends \SYSTEM\LOG\AbstractResult {
const JSONRESULT_OK = true;
const JSONRESULT_ERROR = false;
public static function toString($json_array, $status = self::JSONRESULT_OK, $start_time = NULL){
//send Header
\SYSTEM\HEADER::JSON();
if($start_time == NULL){
$start_time = \SYSTEM\time::getStartTime();}
$json = array();
$json['querytime'] = round(microtime(true) - $start_time,5);
$json['status'] = $status;
$json['result'] = $json_array;
return json_encode($json);
}
//Return Exception as string
public static function error(\Exception $e){
$error = array();
$error['class'] = get_class($e);
$error['message'] = htmlentities($e->getMessage());
$error['code'] = $e->getCode();
$error['file'] = $e->getFile();
$error['line'] = $e->getLine();
$error['trace'] = array_slice(explode('#', $e->getTraceAsString()), 1, -1);;
return self::toString($error, self::JSONRESULT_ERROR);
}
//Returns OK status
public static function ok(){
return self::toString(array());}
}

View File

@ -0,0 +1,3 @@
<?php
class JsonResult extends \SYSTEM\LOG\JsonResult {}

View File

@ -42,7 +42,7 @@ class PageApi {
$tree = self::getPageTree();}
else {
if(!is_array($this->m_dbinfo)){
throw new Exception('No Connectioninfo and no call table given to the api');}
throw new \SYSTEM\LOG\ERROR('No Connectioninfo and no call table given to the api');}
$tree = $this->m_dbinfo;
}
@ -50,15 +50,15 @@ class PageApi {
$commands = array();
$parentid = -1;
foreach($tree as $item){
if( $item[\DBD\PAGETable::FIELD_FLAG] == \DBD\PAGETable::VALUE_FLAG_COMMAND &&
$item[\DBD\PAGETable::FIELD_PARENTID] == $parentid &&
isset($call[$item[\DBD\PAGETable::FIELD_NAME]])){
if( $item[\DBD\SYSTEM\PAGETable::FIELD_FLAG] == \DBD\SYSTEM\PAGETable::VALUE_FLAG_COMMAND &&
$item[\DBD\SYSTEM\PAGETable::FIELD_PARENTID] == $parentid &&
isset($call[$item[\DBD\SYSTEM\PAGETable::FIELD_NAME]])){
if( isset($item[\DBD\PAGETable::FIELD_PARENTVALUE]) &&
$commands[count($commands)-1][1] != $item[\DBD\PAGETable::FIELD_PARENTVALUE]){
if( isset($item[\DBD\SYSTEM\PAGETable::FIELD_PARENTVALUE]) &&
$commands[count($commands)-1][1] != $item[\DBD\SYSTEM\PAGETable::FIELD_PARENTVALUE]){
continue;}
$commands[] = array($item,$call[$item[\DBD\PAGETable::FIELD_NAME]]);
$parentid = $item[\DBD\PAGETable::FIELD_ID];
$commands[] = array($item,$call[$item[\DBD\SYSTEM\PAGETable::FIELD_NAME]]);
$parentid = $item[\DBD\SYSTEM\PAGETable::FIELD_ID];
}
}
@ -68,34 +68,34 @@ class PageApi {
if(count($commands) > 0){
$lastCommand = $commands[count($commands) -1 ][0];
foreach($tree as $item){
if( $item[\DBD\PAGETable::FIELD_FLAG] == \DBD\PAGETable::VALUE_FLAG_PARAM &&
$item[\DBD\PAGETable::FIELD_PARENTID] == $lastCommand[\DBD\PAGETable::FIELD_ID]){
if( $item[\DBD\SYSTEM\PAGETable::FIELD_FLAG] == \DBD\SYSTEM\PAGETable::VALUE_FLAG_PARAM &&
$item[\DBD\SYSTEM\PAGETable::FIELD_PARENTID] == $lastCommand[\DBD\SYSTEM\PAGETable::FIELD_ID]){
if( isset($item[\DBD\PAGETable::FIELD_PARENTVALUE]) &&
$commands[count($commands)-1][1] != $item[\DBD\PAGETable::FIELD_PARENTVALUE]){
if( isset($item[\DBD\SYSTEM\PAGETable::FIELD_PARENTVALUE]) &&
$commands[count($commands)-1][1] != $item[\DBD\SYSTEM\PAGETable::FIELD_PARENTVALUE]){
continue;}
if(!isset($call[$item[\DBD\PAGETable::FIELD_NAME]])){
throw new \Exception('Parameter missing: '.$item[\DBD\PAGETable::FIELD_NAME]);}
if(!isset($call[$item[\DBD\SYSTEM\PAGETable::FIELD_NAME]])){
throw new \SYSTEM\LOG\ERROR('Parameter missing: '.$item[\DBD\SYSTEM\PAGETable::FIELD_NAME]);}
if( !method_exists($this->m_verifyclass, $item[\DBD\PAGETable::FIELD_ALLOWEDVALUES]) ||
!$this->m_verifyclass->$item[\DBD\PAGETable::FIELD_ALLOWEDVALUES]($call[$item[\DBD\PAGETable::FIELD_NAME]])){
throw new \Exception('Parameter type missmacht or Missing Verifier. Param: '.$item[\DBD\PAGETable::FIELD_NAME].' Verifier: '.$item[\DBD\PAGETable::FIELD_ALLOWEDVALUES]);}
if( !method_exists($this->m_verifyclass, $item[\DBD\SYSTEM\PAGETable::FIELD_ALLOWEDVALUES]) ||
!$this->m_verifyclass->$item[\DBD\SYSTEM\PAGETable::FIELD_ALLOWEDVALUES]($call[$item[\DBD\SYSTEM\PAGETable::FIELD_NAME]])){
throw new \SYSTEM\LOG\ERROR('Parameter type missmacht or Missing Verifier. Param: '.$item[\DBD\SYSTEM\PAGETable::FIELD_NAME].' Verifier: '.$item[\DBD\SYSTEM\PAGETable::FIELD_ALLOWEDVALUES]);}
$parameters[] = array($item, $call[$item[\DBD\PAGETable::FIELD_NAME]]);
$parameters[] = array($item, $call[$item[\DBD\SYSTEM\PAGETable::FIELD_NAME]]);
}
}
//Function Name
foreach($commands as $com){
if(!\preg_match('^[0-9A-Za-z_]+$^', $com[1])){
throw new \Exception("Call Command can only have letters!");}
throw new \SYSTEM\LOG\ERROR("Call Command can only have letters!");}
if($com[0][\DBD\PAGETable::FIELD_ALLOWEDVALUES] == 'FLAG'){
$command_call .= '_flag_'.$com[0][\DBD\PAGETable::FIELD_NAME];
if($com[0][\DBD\SYSTEM\PAGETable::FIELD_ALLOWEDVALUES] == 'FLAG'){
$command_call .= '_flag_'.$com[0][\DBD\SYSTEM\PAGETable::FIELD_NAME];
} else {
$command_call .= '_'.$com[0][\DBD\PAGETable::FIELD_NAME].'_'.\strtolower($com[1]);}
$command_call .= '_'.$com[0][\DBD\SYSTEM\PAGETable::FIELD_NAME].'_'.\strtolower($com[1]);}
}
$command_call = substr($command_call, 1);
}
@ -110,7 +110,7 @@ class PageApi {
}
if(!\method_exists($this->m_pageclass, $command_call)){
throw new \Exception("Page call is not implemented in PageApi: ".$command_call);}
throw new \SYSTEM\LOG\ERROR("Page call is not implemented in PageApi: ".$command_call);}
//Call Function
return \call_user_func_array(array($this->m_pageclass,$command_call),$parameter_call);
@ -119,10 +119,10 @@ class PageApi {
private function getPageTree(){
$con = new \SYSTEM\DB\Connection($this->m_dbinfo);
$res = $con->query("SELECT * FROM ".\DBD\PAGETable::NAME." ORDER BY ".\DBD\PAGETable::FIELD_ID);
$res = $con->query('SELECT * FROM '.\DBD\SYSTEM\PAGETable::NAME.' ORDER BY "'.\DBD\SYSTEM\PAGETable::FIELD_ID.'"');
if(!$res){
throw new \Exception("Sql Error ".mysqli_error());}
throw new \SYSTEM\LOG\ERROR("Database Error ". pg_last_error());}
$result = array();
while($row = $res->next()){

View File

@ -3,5 +3,6 @@
namespace SYSTEM\PAGE;
abstract class PageClass {
public abstract static function default_page();
public static function default_page(){
throw new RuntimeException("Unimplemented");}
}

View File

@ -3,6 +3,7 @@
require_once 'saigui.php';
//TODO database
new \SYSTEM\LOG\DEPRECATED("database");
$sai = new \SYSTEM\SAI\saigui(/*new \DBD\system()*/ new \DBD\dasenseuser());
echo $sai->html();

View File

@ -1,12 +0,0 @@
<?php
namespace SYSTEM\SAI;
class SaiApi extends \SYSTEM\PAGE\PageClass {
public static function action_module($module){
return new \SYSTEM\SAI\default_page($module);}
public static function default_page(){
return new \SYSTEM\SAI\default_page();}
}

View File

@ -4,9 +4,10 @@ $autoload = SYSTEM\autoload::getInstance();
$autoload->registerFolder(dirname(__FILE__),'SYSTEM\SAI');
$autoload->registerFolder(dirname(__FILE__).'/page','SYSTEM\SAI');
$autoload->registerFolder(dirname(__FILE__).'/page/action_test','SYSTEM\SAI');
$autoload->registerFolder(dirname(__FILE__).'/page/default_page','SYSTEM\SAI');
$autoload->registerFolder(dirname(__FILE__).'/page/login_page','SYSTEM\SAI');
$autoload->registerFolder(dirname(__FILE__).'/modules','SYSTEM\SAI');
$autoload->registerFolder(dirname(__FILE__).'/modules/badge_creator','SYSTEM\SAI');
require_once dirname(__FILE__).'/modules/register_modules.php';

View File

@ -122,8 +122,7 @@
</div>
<script src="dasense/page/default_developer/js/libs/jquery.miniColors.js"></script>
<script src="dasense/page/default_developer/js/badgecreator.js"></script>
${js}
</body>
</html>

View File

@ -0,0 +1,15 @@
<?php
namespace SYSTEM\SAI;
class saimod_dasense_badge_creator extends \SYSTEM\SAI\SaiModule {
public static function html_js(){ return '<script src="'.\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'sai/page/default_page/js/libs/jquery.miniColors.js').'"></script>'.
'<script src="'.\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'sai/modules/badge_creator/badgecreator.js').'"></script>';}
public static function html_css(){return '';}
public static function html_content(){
return \SYSTEM\PAGE\replace::replaceFile( \SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'sai/modules/badge_creator/badgecreator.tpl'),
array( 'js' => self::html_js()));}
public static function html_li_menu(){return '<li><a href="#" id=".SYSTEM.SAI.saimod_dasense_badge_creator">Badge Creator</a></li>';}
}

View File

@ -1,10 +0,0 @@
<?php
namespace SYSTEM\SAI;
class saimod_dasense_badge_creator extends \SYSTEM\SAI\SaiModule {
public static function html_js(){ return '';}
public static function html_css(){return '';}
public static function html_content(){return 'SYS';}
public static function html_li_menu(){return '<li><a href="#" id="badgecreator">Badge Creator</a></li>';}
}

View File

@ -91,5 +91,5 @@ class saimod_sys_api extends \SYSTEM\SAI\SaiModule {
return $result;
}
public static function html_li_menu(){return '<li><a href="#" id="SYS API">SYS API</a></li>';}
public static function html_li_menu(){return '<li><a href="#" id=".SYSTEM.SAI.saimod_sys_api">SYS API</a></li>';}
}

View File

@ -1,9 +0,0 @@
<?php
namespace SYSTEM\SAI;
class action_test extends \SYSTEM\PAGE\Page {
public function html(){
return "123";
}
}

View File

@ -7,35 +7,35 @@
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item">
<img class="carousel-img" src="dasense/page/default_developer/img/carousel/webseite.jpg" alt="">
<img class="carousel-img" src="./sai/page/default_page/img/carousel/webseite.jpg" alt="">
<div class="carousel-caption">
<h4>TK Forschungspraktikum WS 2012/2013</h4>
<p>Das Team</p>
</div>
</div>
<div class="item">
<img class="carousel-img" src="dasense/page/default_developer/img/carousel/verteidigung_immanuel.jpg" alt="">
<img class="carousel-img" src="./sai/page/default_page/img/carousel/verteidigung_immanuel.jpg" alt="">
<div class="carousel-caption">
<h4>Betreuer: "Hööööy sieee.." ;-D</h4>
<p>Verteidigung Immanuel (Dezember 2012)</p>
</div>
</div>
<div class="item">
<img class="carousel-img" src="dasense/page/default_developer/img/carousel/webseite.jpg" alt="">
<img class="carousel-img" src="./sai/page/default_page/img/carousel/webseite.jpg" alt="">
<div class="carousel-caption">
<h4>Noisemap 3.0 Release</h4>
<p>Die neue Noisemap Version 3.0 ist jetzt für Android und iOS verfügbar.</p>
</div>
</div>
<div class="item">
<img class="carousel-img" src="dasense/page/default_developer/img/carousel/webseite.jpg" alt="">
<img class="carousel-img" src="./sai/page/default_page/img/carousel/webseite.jpg" alt="">
<div class="carousel-caption">
<h4>da_sense</h4>
<p>Neues Webseiten Design. Nice.</p>
</div>
</div>
<div class="item">
<img class="carousel-img" src="dasense/page/default_developer/img/carousel/webseite.jpg" alt="">
<img class="carousel-img" src="./sai/page/default_page/img/carousel/webseite.jpg" alt="">
<div class="carousel-caption">
<h4>Presse: Echo Artikel</h4>
<p>Sogar die Presse hat Interesse ;-P</p>

View File

@ -1,20 +0,0 @@
<?php
/**
* Represents the 'about' menu with the necessary information in relation to the project
*/
class default_developer extends SYSTEM\PAGE\Page {
/**
* assign placeholder with the corresponding values
*
* @tested => true
* @return type template-content with substituted placeholders
*/
public function html(){
}
}

View File

@ -5,9 +5,11 @@ namespace SYSTEM\SAI;
class default_page extends \SYSTEM\PAGE\Page {
private $module = NULL;
private $pg = NULL;
public function __construct($module = NULL){
$this->module = \str_replace('%', '\\', $module);}
public function __construct($module = NULL, $pg = NULL){
$this->module = \str_replace('.', '\\', $module);
$this->pg = $pg;}
private function menu(){
$mods = \SYSTEM\SAI\sai::getInstance()->getModules();
@ -20,12 +22,11 @@ class default_page extends \SYSTEM\PAGE\Page {
private function content(){
$mods = \SYSTEM\SAI\sai::getInstance()->getModules();
if( $this->module &&
\array_search($this->module, $mods) !== false){
return \call_user_func(array($this->module, 'html_content'));}
return 'Welcome to the System Admin Interface.';
return \call_user_func(array($this->module, 'html_content'),array($this->pg));}
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'sai/page/default_page/carousel.tpl'), array());
}
private function css(){
@ -60,12 +61,16 @@ class default_page extends \SYSTEM\PAGE\Page {
$vars['js'] = $this->js();
$vars['menu'] = $this->menu();
//$vars['content'] = $this->content();
//TODO
new \SYSTEM\LOG\DEPRECATED();
if($this->module != NULL){
return $this->content();}
//$vars['PATH_IMG'] = SYSTEM\WEBPATH(new PPAGE(),'default_developer/img/');
//$vars['PATH_LIB'] = SYSTEM\WEBPATH(new PLIB());
//$vars['PATH_JS'] = SYSTEM\WEBPATH(new PJS());
//$vars = array_merge($vars, SYSTEM\locale::getStrings(\DBD\locale_string::VALUE_CATEGORY_DASENSE));
//$vars = array_merge($vars, SYSTEM\locale::getStrings(\DBD\SYSTEM\locale_string::VALUE_CATEGORY_DASENSE));
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'sai/page/default_page/sai.tpl'), $vars);
}
}

View File

@ -3,7 +3,7 @@
$(document).ready(function() {
// initialize content
$('div#content-wrapper').load('./dasense/page/default_developer/carousel.html', function() {
$('div#content-wrapper').load('./?action=module&module=SAI', function() {
$('.carousel').carousel();
});
@ -30,7 +30,7 @@ $(document).ready(function() {
});
function loadModuleContent(id){
$('div#content-wrapper').load('./dasense/page/default_developer/modules/'+id+'/main.html', function(){
$('div#content-wrapper').load('./?action=module&module='+id, function(){
init();
});
}

View File

@ -0,0 +1,17 @@
Not logged in or missing rights. Please login a valid account!
<form id='login' action='#' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Login</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for='username' >UserName:</label>
<input type='text' name='username' id='username' maxlength="50" />
<label for='password' >Password:</label>
<input type='password' name='password' id='password' maxlength="50" />
<input type='submit' name='Submit' value='Submit' />
</fieldset>
</form>

View File

@ -0,0 +1,19 @@
<?php
namespace SYSTEM\SAI;
class login_page extends \SYSTEM\PAGE\Page {
public function html(){
if( isset($_POST['username']) && isset($_POST['password']) &&
\SYSTEM\SECURITY\Security::login(new \DBD\dasenseuser(), $_POST['username'], $_POST['password'], false)){
//TODO connection
new \SYSTEM\LOG\DEPRECATED("connection");
$default = new \SYSTEM\SAI\default_page();
return $default->html();
}
$vars = array();
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'sai/page/login_page/login.tpl'), $vars);
}
}

View File

@ -14,18 +14,13 @@ class saigui extends \SYSTEM\PAGE\Page {
public function html(){
/*if(! \SYSTEM\SECURITY\Security::check($this->sys_dbinfo ? $this->sys_dbinfo : new \DBD\system() , \SYSTEM\SECURITY\RIGHTS::SYS_SAI)){
throw new \Exception("YOU SHALL NOT PASS!");
}*/
$call = array( array(\DBD\PAGETable::FIELD_ID=>0, \DBD\PAGETable::FIELD_FLAG=>0, \DBD\PAGETable::FIELD_PARENTID=>-1, \DBD\PAGETable::FIELD_PARENTVALUE=>'', \DBD\PAGETable::FIELD_NAME=>'action', \DBD\PAGETable::FIELD_ALLOWEDVALUES=>'ALL'),
array(\DBD\PAGETable::FIELD_ID=>1, \DBD\PAGETable::FIELD_FLAG=>1, \DBD\PAGETable::FIELD_PARENTID=>0, \DBD\PAGETable::FIELD_PARENTVALUE=>'module', \DBD\PAGETable::FIELD_NAME=>'module', \DBD\PAGETable::FIELD_ALLOWEDVALUES=>'ALL'));
$sai = new \SYSTEM\PAGE\PageApi( $call, new \SYSTEM\verifyclass(), new \SYSTEM\SAI\SaiApi());
try{
return $sai->CALL(array_merge($_POST,$_GET))->html();
} catch(Exception $e) {
return $e;
if(!\SYSTEM\SECURITY\Security::check($this->sys_dbinfo ? $this->sys_dbinfo : new \DBD\system() , \SYSTEM\SECURITY\RIGHTS::SYS_SAI)){
$login = new \SYSTEM\SAI\login_page();
return $login->html();
}
$pg = array_merge($_POST,$_GET);
$sai = new \SYSTEM\SAI\default_page ($pg['module'],$pg);
return $sai->html();
}
}

View File

@ -15,70 +15,100 @@ class Security {
const AVAILABLE_FAIL = false;
const AVAILABLE_OK = true;
public static function create(\SYSTEM\DB\DBInfo $dbinfo, $username, $password, $email, $hashed){
@session_start();
public static function create(\SYSTEM\DB\DBInfo $dbinfo, $username, $password, $email, $locale, $advancedResult=false, $checkAvailable = true){
self::startSession();
$con = new \SYSTEM\DB\Connection($dbinfo);
$result = $con->prepare('SELECT COUNT(*) as count FROM '.\DBD\UserTable::NAME.
' WHERE '.\DBD\UserTable::FIELD_USERNAME.' like ? '.
' LIMIT 1;',
array($username));
if(!($res = $result->next()) || $res['count'] != 0){
return self::REGISTER_FAIL;}
unset($result);
$result = $con->prepare('INSERT INTO '.\DBD\UserTable::NAME.
' ('.\DBD\UserTable::FIELD_USERNAME.','.\DBD\UserTable::FIELD_PASSWORD.','.\DBD\UserTable::FIELD_EMAIL.','.\DBD\UserTable::FIELD_CREATIONTIMESTAMP.')'.
' VALUES (?, ?, ?, ?);',
array( $username, ($hashed ? $password : md5($password)),
$email, (microtime(true)*1000))
);
if(!$result){
return self::REGISTER_FAIL;}
if(!self::login($dbinfo, $username, $password, $hashed)){
return self::REGISTER_FAIL;}
return self::REGISTER_OK;
}
public static function login(\SYSTEM\DB\DBInfo $dbinfo, $username, $password, $hashed){
@session_start();
// check availability of username (in non-compatibility mode, otherwise it is already checked in DasenseAccount)
if($checkAvailable && !self::available($dbinfo, $username)){
return self::REGISTER_FAIL;}
$con = new \SYSTEM\DB\Connection($dbinfo);
$result = $con->prepare( 'SELECT * FROM '.\DBD\UserTable::NAME.
' WHERE '.\DBD\UserTable::FIELD_USERNAME.' = ?'.
' AND '.\DBD\UserTable::FIELD_PASSWORD.' = ?;',
array($username,($hashed ? $password : md5($password))));
//Database check
if(!$result){
$_SESSION['user'] = NULL;
return self::LOGIN_FAIL;
}
$row = $result->next();
if(!$row){
$con = new \SYSTEM\DB\Connection($dbinfo);
$result = $con->prepare('createAccountStmt','INSERT INTO '.\DBD\SYSTEM\UserTable::NAME.
' ('.\DBD\SYSTEM\UserTable::FIELD_USERNAME.','.\DBD\SYSTEM\UserTable::FIELD_PASSWORD_SHA.','
.\DBD\SYSTEM\UserTable::FIELD_EMAIL.','.\DBD\SYSTEM\UserTable::FIELD_LOCALE.','.\DBD\SYSTEM\UserTable::FIELD_ACCOUNT_FLAG.')'.
' VALUES ($1, $2, $3, $4, $5) RETURNING *;',
array( $username , $password, $email, $locale, 1 ));
if( !$result || !self::login($dbinfo, $username, $password, $locale)){
return self::REGISTER_FAIL;}
return ($advancedResult ? $result->next() : self::REGISTER_OK);
}
public static function login(\SYSTEM\DB\DBInfo $dbinfo, $username, $password_sha, $password_md5, $locale=NULL, $advancedResult=false){
self::startSession();
if(!isset($password_sha)){
self::trackLogins($dbinfo, NULL, self::LOGIN_FAIL);
$_SESSION['user'] = NULL;
return self::LOGIN_FAIL;}
$_SESSION['user'] = new User( $row[\DBD\UserTable::FIELD_ID],
$row[\DBD\UserTable::FIELD_USERNAME],
$row[\DBD\UserTable::FIELD_EMAIL],
$row[\DBD\UserTable::FIELD_CREATIONTIMESTAMP],
time(), //TODO put in database
getenv('REMOTE_ADDR'), //TODO put in database
0, //TODO put in database
NULL); //TODO put in database
return self::LOGIN_OK;
}
$con = new \SYSTEM\DB\Connection($dbinfo);
if(isset($password_md5)){
$result = $con->prepare('loginAccountStmt',
'SELECT * FROM '.\DBD\SYSTEM\UserTable::NAME.
' WHERE lower('.\DBD\SYSTEM\UserTable::FIELD_USERNAME.') LIKE lower($1)'.
' AND ('.\DBD\SYSTEM\UserTable::FIELD_PASSWORD_SHA.' = $2 OR '.\DBD\SYSTEM\UserTable::FIELD_PASSWORD_MD5.' = $3 );',
array($username, $password_sha, $password_md5) );
}else{
$result = $con->prepare('loginAccountStmtSHA',
'SELECT * FROM '.\DBD\SYSTEM\UserTable::NAME.
' WHERE lower('.\DBD\SYSTEM\UserTable::FIELD_USERNAME.') LIKE lower($1)'.
' AND '.\DBD\SYSTEM\UserTable::FIELD_PASSWORD_SHA.' = $2;',
array($username, $password_sha) );
}
//Database check
if(!$result){
self::trackLogins($dbinfo, NULL, self::LOGIN_FAIL);
$_SESSION['user'] = NULL;
return self::LOGIN_FAIL;}
$row = $result->next();
if(!$row){
self::trackLogins($dbinfo, NULL, self::LOGIN_FAIL);
$_SESSION['user'] = NULL;
return self::LOGIN_FAIL;}
// set password_sha if it is empty
if(!$row[\DBD\SYSTEM\UserTable::FIELD_PASSWORD_SHA]){
$res = $con->prepare( 'updatePasswordSHAStmt',
'UPDATE '.\DBD\SYSTEM\UserTable::NAME.' SET '.\DBD\SYSTEM\UserTable::FIELD_PASSWORD_SHA.' = $1 WHERE '.\DBD\SYSTEM\UserTable::FIELD_ID.' = $2'.' RETURNING '.\DBD\SYSTEM\UserTable::FIELD_PASSWORD_SHA.';',
array($password_sha,$row[\DBD\SYSTEM\UserTable::FIELD_ID]));
$res = $res->next();
$row[\DBD\SYSTEM\UserTable::FIELD_PASSWORD_SHA] = $res[\DBD\SYSTEM\UserTable::FIELD_PASSWORD_SHA];
}
// set session variables
$_SESSION['user'] = new User( $row[\DBD\SYSTEM\UserTable::FIELD_ID],
$row[\DBD\SYSTEM\UserTable::FIELD_USERNAME],
$row[\DBD\SYSTEM\UserTable::FIELD_EMAIL],
$row[\DBD\SYSTEM\UserTable::FIELD_JOINDATE],
time(),
getenv('REMOTE_ADDR'),
0,
NULL);
if(isset($locale)){
\SYSTEM\locale::set($locale);}
// track succesful user login
self::trackLogins($dbinfo, $row[\DBD\SYSTEM\UserTable::FIELD_ID], self::LOGIN_OK);
return ($advancedResult ? $row : self::LOGIN_OK);
}
private static function trackLogins(\SYSTEM\DB\DBInfo $dbinfo, $userID, $succ){
$con = new \SYSTEM\DB\Connection($dbinfo);
$con->prepare( 'trackLoginAccountStmt',
'INSERT INTO '.\DBD\SYSTEM\UserLoginsTable::NAME.' ("'.\DBD\SYSTEM\UserLoginsTable::FIELD_USERID.'","'.
\DBD\SYSTEM\UserLoginsTable::FIELD_IP.'",'.\DBD\SYSTEM\UserLoginsTable::FIELD_SUCC.') VALUES ($1,$2,$3)',
array(isset($userID) ? $userID : -1, getenv('REMOTE_ADDR'), (int)$succ ));
}
public static function getUser(){
if(!self::isLoggedIn()){
return NULL;}
return $_SESSION['user'];
}
return $_SESSION['user'];}
/**
* Determine if username exists
@ -87,12 +117,13 @@ class Security {
*/
public static function available(\SYSTEM\DB\DBInfo $dbinfo, $username){
$con = new \SYSTEM\DB\Connection($dbinfo);
$res = $con->prepare( 'SELECT COUNT(*) as count FROM '.\DBD\UserTable::NAME.
' WHERE '.\DBD\UserTable::FIELD_USERNAME.' like ? ;',
$res = $con->prepare( 'availableStmt',
'SELECT COUNT(*) as count FROM '.\DBD\SYSTEM\UserTable::NAME.
' WHERE lower('.\DBD\SYSTEM\UserTable::FIELD_USERNAME.') like lower($1) ;',
array($username));
if(!($res = $res->next())){
throw new Exception("Problem!");}
throw new \SYSTEM\LOG\ERRROR("Cannot determine the availability of username!");}
if($res['count'] != 0){
return self::AVAILABLE_FAIL;}
@ -114,7 +145,7 @@ class Security {
array($user->id, $rightid));
if(!($res = $res->next())){
throw new Exception("Problem!");}
throw new \SYSTEM\LOG\ERROR("Cannot determine if you have the required rights!");}
if($res['count'] == 0){
return false;}
@ -123,22 +154,41 @@ class Security {
//Session
public static function logout(){
@session_start();
self::startSession();
session_destroy();
return self::LOGOUT_OK;
}
public static function save($key,$value){
@session_start();
self::startSession();
$_SESSION['values'][$key] = $value;}
public static function load($key){
@session_start();
self::startSession();
if(!isset($_SESSION['values'][$key])){
return NULL;}
return $_SESSION['values'][$key];
}
public static function isLoggedIn(){
@session_start();
self::startSession();
return (isset($_SESSION['user']) && $_SESSION['user'] instanceof User);}
private static function startSession(){
if(!isset($_SESSION)){
session_start();}
}
//This functions is called from \SYSTEM\locale::set()
public static function _db_setLocale($dbinfo, $lang){
$user = self::getUser();
if(!$user){
throw new \SYSTEM\LOG\ERROR("You need to be logged in");}
$con = new \SYSTEM\DB\Connection($dbinfo);
$res = $con->prepare( 'updateUserLocaleStmt',
'UPDATE '.\DBD\SYSTEM\UserTable::NAME.' SET '.\DBD\SYSTEM\UserTable::FIELD_LOCALE.' = $1 '.
'WHERE '.\DBD\SYSTEM\UserTable::FIELD_ID.' = $2'.' RETURNING '.\DBD\SYSTEM\UserTable::FIELD_LOCALE.';',
array($lang, $user->id));
if(!$res->next()){
throw new \SYSTEM\LOG\ERROR("Problem updating the User!");}
}
}

View File

@ -13,7 +13,10 @@ class locale {
if(!self::isLang($lang)){
return false;}
\SYSTEM\SECURITY\Security::save(self::SESSION_KEY, $lang);
\SYSTEM\SECURITY\Security::save(self::SESSION_KEY, $lang);
if(\SYSTEM\SECURITY\Security::isLoggedIn()){
\SYSTEM\SECURITY\Security::_db_setLocale(new \DBD\SYSTEM\systemPostgres(), $lang);} //TODO: connection def move somewhere?
return true;
}
@ -25,7 +28,7 @@ class locale {
return $value;
}
public static function isLang($lang){
public static function isLang($lang){
if(!\in_array($lang, unserialize(LANGS))){
return false;}
return true;
@ -49,29 +52,29 @@ class locale {
foreach($request as $strid){
if(!\preg_match("^[a-zA-Z0-9_]+$^", $strid) != 0){
throw new \Exception("Requested id contains inpropper symbols: ".$strid);}
$where .= 'OR '.\DBD\locale_string::FIELD_ID.' = ? ';
$where .= 'OR "'.\DBD\SYSTEM\locale_string::FIELD_ID.'" = $1 ';
}
$where = substr($where,2);
$con = new \SYSTEM\DB\Connection(new \DBD\dasensedata());
$res = $con->prepare( 'SELECT '.$lang.','.\DBD\locale_string::FIELD_ID.' FROM '.\DBD\locale_string::NAME.' WHERE '.$where,
$con = new \SYSTEM\DB\Connection(new \DBD\dasensePostgres());
$res = $con->prepare( 'localeArrStmt', 'SELECT "'.$lang.'","'.\DBD\SYSTEM\locale_string::FIELD_ID.'" FROM '.\DBD\SYSTEM\locale_string::NAME.' WHERE '.$where,
$request);
$result = array();
while($r = $res->next()){
$result[$r[\DBD\locale_string::FIELD_ID]] = $r[$lang];}
$result[$r[\DBD\SYSTEM\locale_string::FIELD_ID]] = $r[$lang];}
return $result;
} else if(\intval($request)){
$cat = \intval($request);
$con = new \SYSTEM\DB\Connection(new \DBD\dasensedata());
$res = $con->prepare( 'SELECT '.$lang.','.\DBD\locale_string::FIELD_ID.' FROM '.\DBD\locale_string::NAME.' WHERE '.\DBD\locale_string::FIELD_CATEGORY.' = ?;',
$con = new \SYSTEM\DB\Connection(new \DBD\dasensePostgres());
$res = $con->prepare( 'localeStmt', 'SELECT "'.$lang.'","'.\DBD\SYSTEM\locale_string::FIELD_ID.'" FROM '.\DBD\SYSTEM\locale_string::NAME.' WHERE '.\DBD\SYSTEM\locale_string::FIELD_CATEGORY.' = $1;',
array($cat));
$result = array();
while($r = $res->next()){
$result[$r[\DBD\locale_string::FIELD_ID]] = $r[$lang];}
$result[$r[\DBD\SYSTEM\locale_string::FIELD_ID]] = $r[$lang];}
return $result;
}

View File

@ -1,10 +1,24 @@
<?php
$autoload = system\autoload::getInstance();
$autoload = \SYSTEM\autoload::getInstance();
$autoload->registerFolder(dirname(__FILE__),'SYSTEM');
$autoload->registerFolder(dirname(__FILE__).'/../log/result','SYSTEM\LOG');
$autoload->registerFolder(dirname(__FILE__).'/../log','SYSTEM\LOG');
$autoload->registerFolder(dirname(__FILE__).'/../log/exceptions','SYSTEM\LOG');
$autoload->registerFolder(dirname(__FILE__).'/../log/error_handler','SYSTEM\LOG');
$autoload->registerFolder(dirname(__FILE__).'/../api','SYSTEM\API');
$autoload->registerFolder(dirname(__FILE__).'/../page','SYSTEM\PAGE');
$autoload->registerFolder(dirname(__FILE__).'/../db','SYSTEM\DB');
$autoload->registerFolder(dirname(__FILE__).'/../db/dbinfo','SYSTEM\DB');
$autoload->registerFolder(dirname(__FILE__).'/../db/connection','SYSTEM\DB');
$autoload->registerFolder(dirname(__FILE__).'/../db/result','SYSTEM\DB');
$autoload->registerFolder(dirname(__FILE__).'/../security','SYSTEM\SECURITY');
$autoload->registerFolder(dirname(__FILE__).'/../cache','SYSTEM\CACHE');
$autoload->registerFolder(dirname(__FILE__).'/../sai','SYSTEM\SAI');

21
system/system/time.php Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace SYSTEM;
class time {
private static $instance = null;
private $start_time = NULL;
private static function getInstance(){
if (null === self::$instance) {
self::$instance = new self;}
return self::$instance;
}
private function __construct(){}
private function __clone(){}
public static function start(){
self::getInstance()->start_time = microtime(true);}
public static function getStartTime(){
return self::getInstance()->start_time;}
}