summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/controllers/Users.class.php119
-rw-r--r--src/lib/DB.class.php131
-rw-r--r--src/views/pages/users/index.html.php26
-rw-r--r--src/views/pages/users/individual.html.php12
4 files changed, 195 insertions, 93 deletions
diff --git a/src/controllers/Users.class.php b/src/controllers/Users.class.php
index c7c2180..54e4675 100644
--- a/src/controllers/Users.class.php
+++ b/src/controllers/Users.class.php
@@ -1,6 +1,7 @@
<?php
require_once('Login.class.php');
require_once('Auth.class.php');
+require_once('DB.class.php');
Router::register('users/new' , 'Users', 'new_user');
Router::register('users/index', 'Users', 'index_file');
@@ -77,26 +78,34 @@ class Users extends Controller {
}
public function individual($routed, $remainder) {
- $username = implode('/', $remainder);
-
global $mm; // also used for pluginmanager
$db = $mm->database();
- $uid = $db->getUID($username);
- $user = Auth::getObj($uid);
-
- if ($user->isGroup()) $uid = false; // ignore groups.
-
- if ($uid===false) {
- $this->http404($routed, $remainder);
+ $pm = $mm->pluginManager();
+
+ $username = implode('/', $remainder);
+ if ($username == 'all') {
+ $uids = $db->listUsers();
} else {
+ $uids = array($db->getUID($username));
+ }
+
+ $vars = array();
+
+ if (count($uids)<2) {
+ $user = Auth::getObj($uid);
+
+ if ($user->isGroup()) $uid = false; // ignore groups.
+
+ if ($uid===false) {
+ $this->http404($routed, $remainder);
+ exit();
+ }
if (!$user->canRead()) {
$this->http401($routed, $remainder);
exit();
}
- $vars = array();
$method = $_SERVER['REQUEST_METHOD'];
-
switch ($method) {
case 'PUT': $_POST = $_PUT;
case 'POST':
@@ -106,16 +115,20 @@ class Users extends Controller {
}
break;
}
-
- $config_options = array();
- $mm->pluginManager()->callHook('userConfig', &$config_options);
-
- $vars['config_options'] = $config_options;
- $vars['user'] = $user;
- $vars['groups'] = $db->listGroupNames();
- require_once('ContactMethod.class.php');
- $this->showView('users/individual', $vars);
}
+
+ $config_options = array();
+ $pm->callHook('userConfig', &$config_options);
+
+ $vars['users'] = array();
+ foreach ($uids as $uid) {
+ $vars['users'][] = Auth::getObj($uid);
+ }
+ $vars['username'] = $username;
+ $vars['config_options'] = $config_options;
+ $vars['groups'] = $db->listGroupNames();
+ require_once('ContactMethod.class.php');
+ $this->showView('users/individual', $vars);
}
public function http404($routed, $remainder) {
@@ -176,7 +189,7 @@ class Users extends Controller {
$this->showView('users/500');
} else {
Login::login($username, $password);
- $this->setConf($uid, 'email', $vars['email']);
+ DB::set('users', $uid, 'email', $vars['email']);
$this->showView('users/created',
array('username'=>$username));
}
@@ -272,8 +285,7 @@ class Users extends Controller {
@$value_base = $old[$uid];
$we_changed_it = $value_base != $value;
if ($we_changed_it) {
- $user = Auth::getObj($uid);
- $value_fork = $this->getConf($user,$key);
+ $value_fork = DB::get('users', $uid, $key);
$value_fork = $value_fork['value'];
if ($value_fork===false) $value_fork = 'false';
if ($value_fork===true) $value_fork = 'true';
@@ -293,7 +305,7 @@ class Users extends Controller {
}
}
if ($doit) {
- $this->setConf($uid, $key, $value);
+ DB::set('users', $uid, $key, $value);
}
if ($forked) {
echo "<pre>\n";
@@ -328,73 +340,16 @@ class Users extends Controller {
$vars['users'] = array();
$uids = $db->listUsers();
foreach ($uids as $uid) {
- $user = Auth::getObj($uid);
$vars['users'][$uid] = array();
foreach ($vars['attribs'] as $attrib) {
$key = $attrib['key'];
- $props = $this->getConf($user, $key);
+ $props = DB::get('users', $uid, $key);
$vars['users'][$uid][$key] = $props;
}
}
$this->showView('users/index', $vars);
}
-
- private function getConf($user, $key) {
- $logged_in_user = Auth::getObj(Login::isLoggedIn());
- $uid = $user->getUID();
- $post_key = $key."[$uid]";
- @$value = $_POST[$post_key];
- $editable = $user->canEdit();
-
- switch ($key) {
- case 'auth_name':
- $value = $user->getName();
- break;
- case 'auth_user':
- $editable = $editable && $logged_in_user->isAdmin();
- $value = $user->isUser();
- break;
- case 'auth_admin':
- $editable = $editable && $logged_in_user->isAdmin();
- $value = $user->isAdmin();
- break;
- case 'auth_delete':
- $editable = $editable && $logged_in_user->isAdmin();
- $value = false;
- break;
- default:
- $value = $user->getConf($key);
- if ($value===false) $value='';
- break;
- }
-
- return array('value'=>$value,
- 'post_key'=>$post_key,
- 'editable'=>$editable);
- }
- private function setConf($uid, $key, $value) {
- // So, this rocks because we don't have to check permissions,
- // the User object does that.
- $user = Auth::getObj($uid);
- switch ($key) {
- case 'auth_name':
- $user->setName($value);
- break;
- case 'auth_user':
- $user->setUser($value=='true');
- break;
- case 'auth_admin':
- $user->setAdmin($value=='true');
- break;
- case 'auth_delete':
- if ($value=='true') $user->delete();
- default:
- $user->setConf($key, $value);
- break;
- }
- }
-
function attrib($key, $name) {
return array('key'=>$key, 'name'=>$name);
}
diff --git a/src/lib/DB.class.php b/src/lib/DB.class.php
new file mode 100644
index 0000000..9f14161
--- /dev/null
+++ b/src/lib/DB.class.php
@@ -0,0 +1,131 @@
+<?php
+
+require_once('Auth.class.php');
+require_once('Login.class.php');
+
+class DB {
+ public static function get($table, $unit, $key) {
+ switch ($table) {
+ case 'conf':
+ case 'plugins':
+ return self::admin_get($unit, $key);
+ break;
+ case 'users':
+ return self::user_get($unit, $key);
+ break;
+ default:
+ return false;
+ }
+ }
+ public static function set($table, $unit, $key, $value) {
+ switch ($table) {
+ case 'conf':
+ case 'plugins':
+ return self::admin_get($unit, $key, $value);
+ break;
+ case 'users':
+ return self::user_set($unit, $key, $value);
+ break;
+ default:
+ return false;
+ }
+ }
+
+ private static function user_get($uid, $key) {
+ $user = Auth::getObj($uid);
+ $logged_in_user = Auth::getObj(Login::isLoggedIn());
+
+ $post_key = $key."[$uid]";
+ @$value = $_POST[$post_key];
+ $editable = $user->canEdit();
+
+ switch ($key) {
+ case 'auth_uid':
+ $value = $user->getUID();
+ $editable = false;
+ break;
+ case 'auth_name':
+ $value = $user->getName();
+ break;
+ case 'auth_user':
+ $editable = $editable && $logged_in_user->isAdmin();
+ $value = $user->isUser();
+ break;
+ case 'auth_admin':
+ $editable = $editable && $logged_in_user->isAdmin();
+ $value = $user->isAdmin();
+ break;
+ case 'auth_delete':
+ $editable = $editable && $logged_in_user->isAdmin();
+ $value = false;
+ break;
+ default:
+ $value = $user->getConf($key);
+ if ($value===false) $value='';
+ break;
+ }
+
+ return array('value'=>$value,
+ 'post_key'=>$post_key,
+ 'editable'=>$editable);
+ }
+ private static function user_set($uid, $key, $value) {
+ $user = Auth::getObj($uid);
+
+ switch ($key) {
+ case 'auth_uid':
+ return false;
+ break;
+ case 'auth_name':
+ return $user->setName($value);
+ break;
+ case 'auth_user':
+ return $user->setUser($value=='true');
+ break;
+ case 'auth_admin':
+ return $user->setAdmin($value=='true');
+ break;
+ case 'auth_delete':
+ if ($value=='true') return $user->delete();
+ default:
+ return $user->setConf($key, $value);
+ break;
+ }
+ }
+
+ private static function admin_get($plugin, $key) {
+ global $mm; $db = $mm->database();
+ $user = Auth::getObj(Login::isLoggedIn());
+ if ($user->isAdmin()) {
+ $editable = true;
+ switch ($plugin) {
+ case 'system':
+ $value = $db->getSysConf($key);
+ break;
+ default:
+ $value = $db->getPluginConf($plugin, $key);
+ break;
+ }
+ } else {
+ $editable = false;
+ $value = false;
+ }
+
+ return array('value'=>$value,
+ 'post_key'=>'to be implemented',// FIXME
+ 'editable'=>$editable);
+ }
+ private static function admin_set($plugin, $key, $value) {
+ global $mm; $db = $mm->database();
+ $user = Auth::getObj(Login::isLoggedIn());
+ if (!$user->isAdmin()) {
+ return false;
+ }
+ switch ($plugin) {
+ case 'system':
+ return $db->setSysConf($key, $value);
+ default:
+ return $db->setPluginConf($plugin, $key, $value);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/views/pages/users/index.html.php b/src/views/pages/users/index.html.php
index 7f51592..caedf5c 100644
--- a/src/views/pages/users/index.html.php
+++ b/src/views/pages/users/index.html.php
@@ -13,14 +13,27 @@ $t->openTag('form', array('action'=>$t->url('users/index'),
$t->tag('input', array('type'=>'submit',
'value'=>'Save/Update'));
-$t->openTag('table');
+$t->openTag('table', array('class'=>'sortable', 'id'=>'bar'));
+$t->openTag('thead');
$t->openTag('tr');
foreach ($attribs as $attrib) {
$t->tag('th', array(), $attrib['name']);
}
-$t->tag('th');
+$t->tag('th', array(), '-');
$t->closeTag('tr');
+$t->closeTag('thead');
+
+$t->openTag('tfoot');
+$t->openTag('tr');
+foreach ($attribs as $attrib) {
+ $t->tag('th', array(), $attrib['name']);
+}
+$t->tag('th', array(), '-');
+$t->closeTag('tr');
+$t->closeTag('tfoot');
+
+$t->openTag('tbody');
foreach ($users as $user) {
$t->openTag('tr');
@@ -48,6 +61,7 @@ foreach ($users as $user) {
$arr['value'] = 'true';
$arr['type'] = 'checkbox';
} else {
+ $t->tag('span', array('class'=>'cell_width'), $value);
$arr['value'] = $value;
$arr['type'] = 'text';
}
@@ -66,13 +80,7 @@ foreach ($users as $user) {
$t->closeTag('tr');
}
-$t->openTag('tr');
-foreach ($attribs as $attrib) {
- $t->tag('th', array(), $attrib['name']);
-}
-$t->tag('th');
-$t->closeTag('tr');
-
+$t->closeTag('tbody');
$t->closeTag('table');
$t->tag('input', array('type'=>'submit',
diff --git a/src/views/pages/users/individual.html.php b/src/views/pages/users/individual.html.php
index c630515..39360b7 100644
--- a/src/views/pages/users/individual.html.php
+++ b/src/views/pages/users/individual.html.php
@@ -1,6 +1,7 @@
<?php global $VARS, $CONTACT_METHODS;
$t = $VARS['template'];
-$user = $VARS['user'];
+$users = $VARS['users'];
+$username = $VARS['username'];
function inputText($user, $key, $label, $hint='') {
global $VARS; $t = $VARS['template'];
@@ -56,8 +57,14 @@ function inputField($user, $arr) {
////////////////////////////////////////////////////////////////////////////////
+if (count($users)>1) {
+ $t->header("Users: $username");
+} else {
+ $t->header("User: $username");
+}
+
+foreach($users as $user) {
$username = $user->getName();
-$t->header("User: $username");
$t->tag('h1', array(), ($user->canEdit()?'Edit':'View')." User <q>$username</q> (UID: ".$user->getUID().")");
@@ -136,4 +143,5 @@ if ($user->canEdit()) {
$t->tag('input', array('type'=>'submit', 'value'=>'Save'));
}
$t->closeTag('form');
+}
$t->footer();