{
/**passcode for admin.php*/
private $adminpass=false;
+ private $adminuser=false;
//public function __construct();
public abstract function tryConnect();
/**set the admin passcode*/
- public function setAdminPassCode($p)
+ public function setAdminPassCode($u,$p)
{
+ $this->adminuser=$u;
$this->adminpass=$p;
}
+ /**check admin credentials*/
+ public function checkAdmin()
+ {
+ global $_SERVER;
+ if(!$this->canAdministrate())return false;
+ if(!isset($_SERVER["PHP_AUTH_USER"]) || !isset($_SERVER["PHP_AUTH_PW"])){
+ return false;
+ }
+ return $_SERVER["PHP_AUTH_USER"]==$this->adminuser && $_SERVER["PHP_AUTH_PW"]==$this->adminpass;
+ }
+
/**returns whether a passcode is known and admin.php may be used*/
public function canAdministrate()
{
- return $this->adminpass!==false;
+ return $this->adminpass!==false && $this->adminuser!==false;
}
/**returns the version of the DB layout that is required by this version of Magic Smoke*/
/**gets some data from the database; $table is the name of the table, $cols is the list of columns to return or "*" for all, $where is the where clause of the SQL-statement; returns array of rows, which are in *_fetch_array format; returns false on error*/
protected abstract function select($table,$cols,$where);
+ /**creates a table; the argument is an array of the form "col-name" => array("col-type", "flags"...); use sqlCreate() etc. to create the actual statement*/
+ protected abstract function createTable($tablename,$table);
+
+ /**returns the correct type name for the required abstract data type;
+ types that must be understood are: int32 (INTEGER), int64 (LONG INTEGER), autoint32 (auto-incrementing int), autoint64, string:$length (text up to 255 chars, length is optional, default is 255; VARCHAR($length)), text (unlimited text)*/
+ protected function dataType($type)
+ {
+ if($type=="int32")return "INTEGER";
+ if($type=="int64")return "LONG INTEGER";
+ if(strncmp(7,$type,"string:")){
+ return "VARCHAR("."??".")";
+ }
+ return false;
+ }
+
+ /**returns the correct name/coding of a flag:
+ primarykey, notnull, unique (implies notnull), foreignkey:$table:$col, defaultint:$val, defaultstr:$val, index*/
+ protected function columnFlag($flag)
+ {
+ if($flag=="primarykey")return "PRIMARY KEY";
+ if($flag=="notnull")return "NOT NULL";
+ if($flag=="unique")return "NOT NULL,UNIQUE";
+ if($flag=="index")return "INDEX";
+ }
+
+ /**creates a SQL92 statement for creating a table*/
+ protected function sqlCreateTable($tablename,$table)
+ {
+ }
+
/**returns a configuration setting*/
public function getConfig($key)
{
--- /dev/null
+<?
+class DbScheme {
+ private static $scheme;
+ function __construct()
+ {
+ $this->scheme["users"]=array(
+ "uname" => array("string:64","primarykey"),
+ "passwd" => array("string","notnull")
+ );
+ $this->scheme["userrole"]=array(
+ "uname" =>array("string:64","notnull","foreignkey:users:uname","index"),
+ "role" =>array("string:32","notnull")
+ );
+ }
+};
+$dbScheme=new DbScheme;
+?>
\ No newline at end of file