summaryrefslogtreecommitdiff
path: root/src/views/pages/users/index.php
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-08-01 01:22:36 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-08-01 01:22:36 -0400
commit09dfe32eb6b538225686fd6ed0220240010bc574 (patch)
tree29c1afc5e79519ba8689a3d5d170c312d3cf5033 /src/views/pages/users/index.php
initial commit.
Partway through a rewrite. I have some old files I didn't want to entirely delete.
Diffstat (limited to 'src/views/pages/users/index.php')
-rw-r--r--src/views/pages/users/index.php116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/views/pages/users/index.php b/src/views/pages/users/index.php
new file mode 100644
index 0000000..d801faf
--- /dev/null
+++ b/src/views/pages/users/index.php
@@ -0,0 +1,116 @@
+<?php global $mm;
+
+$logged_in_user = $mm->getAuthObj($mm->isLoggedIn());
+if (!$logged_in_user->isUser()) {
+ include(VIEWPATH.'/pages/users/401.php');
+ exit();
+}
+
+function attrib($key, $name, $check=false) {
+ return array('key'=>$key, 'name'=>$name, 'checkbox'=>$check);
+}
+
+function getSetConf($user, $key) {
+ global $mm;
+ $logged_in_user = $mm->getAuthObj($mm->isLoggedIn());
+ $uid = $user->getUID();
+ $post_key = $key."[$uid]";
+ @$value = $_POST[$post_key];
+ $editable = $user->canEdit();
+ $edit = isset($_POST[$post_key]);
+
+ switch ($key) {
+ case 'auth_name':
+ if ($editable && $edit) $user->setName($value);
+ $value = $user->getName();
+ break;
+ case 'auth_user':
+ $editable = $editable && $logged_in_user->isAdmin();
+ if ($editable && $edit) $user->setUser($value=='true');
+ $value = $user->isUser();
+ break;
+ case 'auth_admin':
+ $editable = $editable && $logged_in_user->isAdmin();
+ if ($editable && $edit) $user->setAdmin($value=='true');
+ $value = $user->isAdmin();
+ break;
+ default:
+ if ($editable && $edit) $user->setConf($key, $value);
+ $value = $user->getConf($key);
+ break;
+ }
+
+ return array(
+ 'value'=>$value,
+ 'post_key'=>$post_key,
+ 'editable'=>$editable);
+}
+
+$attribs = array(attrib('auth_user', 'Active', true),
+ attrib('lastname','Last'),
+ attrib('firstname','First'),
+ attrib('hsclass','Class of'),
+ attrib('phone','Phone number'),
+ attrib('email','Email'),
+ attrib('auth_name', 'Username'),
+ );
+
+////////////////////////////////////////////////////////////////////////////////
+
+$t = $mm->template();
+$mm->header('Users');
+
+$t->openTag('form', array('action'=>$mm->baseUrl().'users',
+ 'method'=>'post'));
+
+$t->openTag('table');
+
+$t->openTag('tr');
+foreach ($attribs as $attrib) {
+ $t->tag('th', array(), $attrib['name']);
+}
+$t->tag('th');
+$t->closeTag('tr');
+
+$uids = $mm->listUsers();
+foreach ($uids as $uid) {
+ $user = $mm->getAuthObj($uid);
+ $t->openTag('tr');
+
+ foreach ($attribs as $attrib) {
+ $props = getSetConf($user, $attrib['key']);
+
+ $arr = array('name'=>$props['post_key']);
+ if (!$props['editable']) {
+ $arr['readonly'] = 'readonly';
+ if ($attrib['checkbox']) $arr['disabled'] = $disabled;
+ }
+ if ($attrib['checkbox']) {
+ if ($props['value'])
+ $arr['checked'] = 'checked';
+ $arr['value'] = 'true';
+ $arr['type'] = 'checkbox';
+ } else {
+ $arr['value'] = $props['value'];
+ $arr['type'] = 'text';
+ }
+
+ $t->openTag('td');
+ $t->tag('input', $arr);
+ $t->closeTag('td');
+ }
+
+ $t->openTag('td');
+ $t->link($mm->baseUrl().'users/'.$user->getName(), 'More');
+ $t->closeTag('td');
+
+ $t->closeTag('tr');
+}
+
+$t->closeTag('table');
+
+$t->tag('input', array('type'=>'submit',
+ 'value'=>'Save/Update'));
+$t->closeTag('form');
+
+$mm->footer(); \ No newline at end of file