summaryrefslogtreecommitdiffstats
path: root/code
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2006-03-05 18:38:05 +0100
committerneoraider <devnull@localhost>2006-03-05 18:38:05 +0100
commit13644bec358f3e51a085337c75aaaa2b9704bfbe (patch)
tree7772d25df6c259043802fc3feebfe8ae853922b9 /code
parentb4e4ea85fff81c47a4aa5a3b46c17340e4192d08 (diff)
downloadneon-13644bec358f3e51a085337c75aaaa2b9704bfbe.tar
neon-13644bec358f3e51a085337c75aaaa2b9704bfbe.zip
Seiten-Verwaltung intern ueberarbeitet.
Diffstat (limited to 'code')
-rw-r--r--code/links.inc.php2
-rw-r--r--code/pages.inc.php128
-rw-r--r--code/user.inc.php24
3 files changed, 106 insertions, 48 deletions
diff --git a/code/links.inc.php b/code/links.inc.php
index 9fbaae3..5c48f54 100644
--- a/code/links.inc.php
+++ b/code/links.inc.php
@@ -4,7 +4,7 @@
class Links {
function GetNeonLink($page, $extra = '', $html = true) {
if($GLOBALS['pages']->HasAccess($page, 'c')) {
- if($GLOBALS['user']->GetLoginType() == 'url')
+ if($GLOBALS['user']->login_type == 'url')
$ret = 'index.php?page=' . $page . '&login=' . $GLOBALS['user']->GetLoginKey()
. ($extra ? '&' . $extra : '');
diff --git a/code/pages.inc.php b/code/pages.inc.php
index 09cd525..d57bb17 100644
--- a/code/pages.inc.php
+++ b/code/pages.inc.php
@@ -4,58 +4,132 @@
require_once('code/handlers.inc.php');
class Pages {
- function Get($name, $type, $extra = null) {
- if(!$this->Exists($name, $type))
- return array('title' => $name,
- 'content' => ErrorMessage('PageNotFound', array('page' => $name)));
+ function Get($page, $type = null, $extra = null) {
+ if(!$this->Exists($page, $type))
+ return array('title' => $page,
+ 'content' => ErrorMessage('PageNotFound', array('page' => $page)));
- $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ if($type) $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE name = ? AND type = ?', array($page, $type));
+ else $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE id = ?', $page);
- if(!$this->HasAccess($name, $type))
- return array('title' => $name,
- 'content' => ErrorMessage('Forbidden', array('page' => $name)));
+ if(!$this->HasAccess($page, $type))
+ return array('title' => $res->fields[1],
+ 'content' => ErrorMessage('Forbidden', array('page' => $res->fields[1])));
- parse_str($res->fields[2], $data);
+ parse_str($res->fields[4], $data);
$data = array_map('Unquote', $data);
if($extra) $data = array_merge($data, $extra);
$data['_id'] = $res->fields[0];
- $data['_page'] = $name;
+ $data['_page'] = $res->fields[1];
+ $data['_type'] = $res->fields[2];
- return $GLOBALS['handlers'][$res->fields[1]]->Get($data);
+ return $GLOBALS['handlers'][$res->fields[3]]->Get($data);
}
- function Edit($name, $type) {
- if(!$this->Exists($name, $type))
- return array('title' => $name,
- 'content' => ErrorMessage('PageNotFound', array('page' => $name)));
+ function GetEditor($page, $type = null) {
+ if(!$this->Exists($page, $type))
+ return array('title' => $page,
+ 'content' => ErrorMessage('PageNotFound', array('page' => $page)));
- $res = $GLOBALS['db']->Execute('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ if($type) $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE name = ? AND type = ?', array($page, $type));
+ else $res = $GLOBALS['db']->Execute('SELECT id, name, type, handler, data FROM pages WHERE id = ?', $page);
if(!$GLOBALS['user']->IsAdmin())
- return array('title' => $name,
- 'content' => ErrorMessage('Forbidden', array('page' => $name)));
+ return array('title' => $res->fields[1],
+ 'content' => ErrorMessage('Forbidden', array('page' => $res->fields[1])));
- parse_str($res->fields[2], $data = null);
+ parse_str($res->fields[4], $data = null);
$data = array_map('Unquote', $data);
$data['_id'] = $res->fields[0];
- $data['_page'] = $name;
- $data['_type'] = $type;
+ $data['_page'] = $res->fields[1];
+ $data['_type'] = $res->fields[2];
- return $this->Get($res->fields[1], 'e', array('_data' => $data));
+ return $this->Get($res->fields[3], 'e', array('_data' => $data));
}
- function Exists($name, $type) {
- $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ function GetName($id) {
+ $res = $GLOBALS['db']->Execute('SELECT name FROM pages WHERE id = ?', $id);
+
+ return $res->fields[0];
+ }
+
+ function GetType($id) {
+ $res = $GLOBALS['db']->Execute('SELECT type FROM pages WHERE id = ?', $id);
+
+ return $res->fields[0];
+ }
+
+ function Exists($page, $type = null) {
+ if($type) $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE name = ? AND type = ?', array($page, $type));
+ else $res = $GLOBALS['db']->Execute('SELECT id FROM pages WHERE id = ?', $page);
return ($res->RecordCount() > 0);
}
- function HasAccess($name, $type) {
- $gid = $GLOBALS['user']->GetGid();
- $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ function HasAccess($page, $type = null) {
+ $gid = $GLOBALS['user']->gid;
+ if($type) $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE name = ? AND type = ?', array($page, $type));
+ else $res = $GLOBALS['db']->Execute('SELECT access FROM pages WHERE id = ?', $page);
return ($GLOBALS['user']->IsAdmin() || (ord($res->fields[0][$gid/8]) & (1 << ($gid%8))) != 0);
}
+
+ function Add($name, $handler, $type) {
+ if($this->Exists($name, $type)) return 0;
+
+ $GLOBALS['db']->Execute('INSERT INTO pages (name, handler, access, data, type) VALUES (?, ?, 0, "", ?)',
+ array($name, $handler, $type));
+
+ return $GLOBALS['db']->Insert_ID();
+ }
+
+ function Edit($page, $data, $type = null) {
+ $string = '';
+
+ foreach($data as $key => $val)
+ $string .= urlencode($key) . '=' . urlencode($val) . '&';
+
+ if($type) $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE name = ? AND type = ?',
+ array(substr($string, 0, -1), $page, $type));
+ else $GLOBALS['db']->Execute('UPDATE pages SET data = ? WHERE id = ?',
+ array(substr($string, 0, -1), $page));
+ }
+
+ function Rename($page, $new_name, $type = null) {
+ if($type) {
+ if($this->Exists($new_name, $type)) return;
+
+ $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE name = ? AND type = ?', array($new_name, $page, $type));
+ }
+ else {
+ if($this->Exists($new_name, $this->GetType($type))) return;
+
+ $GLOBALS['db']->Execute('UPDATE pages SET name = ? WHERE id = ?', array($new_name, $page));
+ }
+ }
+
+ function Copy($page, $new_name, $type = null) {
+ if($type) {
+ if($this->Exists($new_name, $type)) return;
+
+ $res = $GLOBALS['db']->Execute('SELECT * FROM pages WHERE name = ? AND type = ?', array($page, $type));
+ }
+ else {
+ if($this->Exists($new_name, $this->GetType($type))) return;
+
+ $res = $GLOBALS['db']->Execute('SELECT handler, data, type FROM pages WHERE id = ?', $page);
+ }
+
+ $GLOBALS['db']->Execute('INSERT INTO pages (name, handler, access, data, type) VALUES (?, ?, 0, ?, ?)',
+ array($new_name, $res->fields[0], $res->fields[1], $res->fields[2]));
+
+ return $GLOBALS['db']->Insert_ID();
+ }
+
+ function Delete($page, $type = null) {
+ if($type) $GLOBALS['db']->Execute('DELETE FROM pages WHERE name = ? AND type = ?', array($page, $type));
+ else $GLOBALS['db']->Execute('DELETE FROM pages WHERE id = ?', $page);
+ }
}
$GLOBALS['pages'] = new Pages;
diff --git a/code/user.inc.php b/code/user.inc.php
index 5aa76d5..373c5e8 100644
--- a/code/user.inc.php
+++ b/code/user.inc.php
@@ -3,7 +3,7 @@
class User {
var $uid = 0, $gid = 0;
- var $key = '', $type = '';
+ var $key = '', $login_type = '';
function User() {
if($_COOKIE['login']) {
@@ -29,7 +29,7 @@
$this->uid = $res->fields[0];
$this->gid = $res->fields[1];
- $this->type = 'url';
+ $this->login_type = 'url';
$this->key = $_GET['login'];
}
}
@@ -47,7 +47,7 @@
$this->uid = $id;
$this->gid = $res->fields[1];
- $this->type = 'url';
+ $this->login_type = 'url';
$this->key = $sid . $id;
setcookie('login', $this->key);
@@ -64,7 +64,7 @@
$this->uid = 0;
$this->gid = 0;
- $this->type = '';
+ $this->login_type = '';
$this->key = '';
setcookie('login');
@@ -73,22 +73,6 @@
function IsAdmin() {
return ($this->uid != 0 && $this->gid == 0);
}
-
- function GetUid() {
- return $this->uid;
- }
-
- function GetGid() {
- return $this->gid;
- }
-
- function GetLoginType() {
- return $this->type;
- }
-
- function GetLoginKey() {
- return $this->key;
- }
}
$GLOBALS['user'] = new User;