diff options
Diffstat (limited to 'src/views/pages/users')
-rw-r--r-- | src/views/pages/users/include.php | 60 | ||||
-rw-r--r-- | src/views/pages/users/index.csv.php | 4 | ||||
-rw-r--r-- | src/views/pages/users/index.html.php | 4 | ||||
-rw-r--r-- | src/views/pages/users/index.php | 116 | ||||
-rw-r--r-- | src/views/pages/users/individual.html.php | 38 | ||||
-rw-r--r-- | src/views/pages/users/individual.php | 89 |
6 files changed, 39 insertions, 272 deletions
diff --git a/src/views/pages/users/include.php b/src/views/pages/users/include.php deleted file mode 100644 index 6e8c90b..0000000 --- a/src/views/pages/users/include.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php global $mm; - -require_once('User.class.php'); - -/** - * This will take care of possibly updating and displaying a value in the - * 'users' table. - */ -function inputText($user, $name, $label, $hint='') { - if ($user->canEdit()) { - if (isset($_POST["user_$name"])) { - $user->setConf($name, $_POST["user_$name"]); - } - } - - $current_setting = $user->getConf($name); - - global $mm; - $t = $mm->template(); - $t->inputText("user_$name", $label, $hint, $current_setting, - !$user->canEdit()); -} - -function inputArray($user, $name, $arr) { - global $mm; - $t = $mm->template(); - - if (isset($_POST[$name]) && is_array($_POST[$name])) { - $user->setConfArray($name, $_POST[$name]); - } - $defaults = $user->getConfArray($name); - - foreach ($arr as $value => $label) { - $t->inputBool($name, $value, $label, - in_array($value, $defaults), !$user->canEdit()); - } -} - -function inputNewPassword($user, $name, $label) { - @$password1 = $_POST[$name ]; - @$password2 = $_POST[$name.'_verify']; - - // Check the verify box, not main box, so that we don't get tripped by - // browsers annoyingly autocompleting the password. - $is_set = ($password2 != ''); - - global $mm; - $t = $mm->template(); - - if ($is_set) { - $matches = ( $password1 == $password2 ); - if ($matches) { - $user->setPassword($password1); - $t->inputP('Password successfully updated.'); - } else { - $t->inputP("Passwords don't match.", true); - } - } - $t->inputNewPassword($name, $label); -} diff --git a/src/views/pages/users/index.csv.php b/src/views/pages/users/index.csv.php index 527e508..0a69cee 100644 --- a/src/views/pages/users/index.csv.php +++ b/src/views/pages/users/index.csv.php @@ -1,5 +1,5 @@ <?php global $VARS; -$attribs = $VARS['template']; +$attribs = $VARS['attribs']; $users = $VARS['users']; function escape($value) { @@ -7,7 +7,7 @@ function escape($value) { return ($value?'true':'false'); } else { $chars = "'" . '"' . '\\' . ','; - return addcslashes($str, $chars); + return addcslashes($value, $chars); } } diff --git a/src/views/pages/users/index.html.php b/src/views/pages/users/index.html.php index 5f1ab02..c268c87 100644 --- a/src/views/pages/users/index.html.php +++ b/src/views/pages/users/index.html.php @@ -1,10 +1,12 @@ <?php global $VARS; $t = $VARS['template']; -$attribs = $VARS['template']; +$attribs = $VARS['attribs']; $users = $VARS['users']; $t->header('Users'); +$t->paragraph($t->link($t->url('users.csv'), "Download this as a spreadsheet.")); + $t->openTag('form', array('action'=>$t->url('users/index'), 'method'=>'post')); diff --git a/src/views/pages/users/index.php b/src/views/pages/users/index.php deleted file mode 100644 index d801faf..0000000 --- a/src/views/pages/users/index.php +++ /dev/null @@ -1,116 +0,0 @@ -<?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 diff --git a/src/views/pages/users/individual.html.php b/src/views/pages/users/individual.html.php index 4d6e4fc..9e3048a 100644 --- a/src/views/pages/users/individual.html.php +++ b/src/views/pages/users/individual.html.php @@ -8,6 +8,12 @@ function inputText($user, $key, $label, $hint='') { $t->inputText("user_$key", $label, $hint, $current_setting, !$user->canEdit()); } +function inputTextarea($user, $key, $label, $hint='') { + global $VARS; $t = $VARS['template']; + $current_setting = $user->getConf($key); + $t->inputTextarea("user_$key", $label, $hint, $current_setting, + !$user->canEdit()); +} function inputArray($user, $key, $arr) { global $VARS; $t = $VARS['template']; @@ -19,12 +25,27 @@ function inputArray($user, $key, $arr) { } } +function inputField($user, $arr) { + $fieldname = $arr[0]; + $fieldlabel = $arr[1]; + $fieldtype = $arr[2]; + + switch ($fieldtype) { + case 'text': + inputText($user, $fieldname, $fieldlabel, ''); + break; + case 'textarea': + inputTextarea($user, $fieldname, $fieldlabel, ''); + break; + } +} //////////////////////////////////////////////////////////////////////////////// +$username = $user->getName(); $t->header("Users: $username"); -$t->tag('h1', array(), ($user->canEdit()?'Edit':'View')." User (UID: $uid)"); +$t->tag('h1', array(), ($user->canEdit()?'Edit':'View')." User <q>$username</q> (UID: ".$user->getUID().")"); if ($user->canEdit()) { $t->openTag('form', array('method'=>'post', @@ -53,17 +74,26 @@ if (@$VARS['pw_updated']===true) { if (@$VARS['pw mixmatch']===true) { $t->inputP("Passwords don't match.", true); } -if ($user->canEdit()) inputNewPassword($user, 'auth_password','Reset Password'); +if ($user->canEdit()) $t->inputNewPassword('auth_password','Reset Password'); //////////////////////////////////////////////////////////////////////////////// $t->closeFieldset(); +/* $t->openFieldset("Information"); inputText($user, 'firstname','First Name',''); inputText($user, 'lastname','Last Name',''); inputText($user, 'hsclass','Highschool Class of', 'Please put the full year (ex: 2012)'); $t->closeFieldset(); +*/ +foreach ($VARS['config_options'] as $groupname=>$options) { + $t->openFieldset($groupname); + foreach ($options as $option) { + inputField($user, $option); + } + $t->closeFieldset(); +} $t->openFieldset("Contact"); // TODO: I should make this a setting for admins to set. @@ -80,9 +110,9 @@ $use_arr = array(); foreach ($CONTACT_METHODS as $method) { inputText($user, $method->addr_slug, - ucwords($method->addr_word), + ucwords($method->addr_text), $hints[$method->addr_slug]); - $use_arr[$method->verb_slug] = ucwords($method->verb_word); + $use_arr[$method->verb_slug] = ucwords($method->verb_text); } $t->inputP("When I recieve a message, notify me using the following methods:"); diff --git a/src/views/pages/users/individual.php b/src/views/pages/users/individual.php deleted file mode 100644 index 2483e6b..0000000 --- a/src/views/pages/users/individual.php +++ /dev/null @@ -1,89 +0,0 @@ -<?php global $mm, $uid; -// Honestly, the functions in this include should be in this file, but that -// would make this file too messy. -require_once(VIEWPATH.'/pages/users/include.php'); - -$user = $mm->getAuthObj($uid); - -if (!$user->canRead()) { - include(VIEWPATH.'/pages/users/401.php'); - exit(); -} - -// Read/Change the username -$username = $user->getName(); -if (isset($_POST['auth_name'])) { - $new_name = $_POST['auth_name']; - if ($new_name != $username) { - global $illegal_names; - if (!in_array($new_name, $illegal_names)) { - $changed_name = $user->setName($new_name); - $username = $user->getName(); - } - } -} - -//////////////////////////////////////////////////////////////////////////////// - -$t = $mm->template(); -$mm->header("Users: $username"); - -$t->tag('h1', array(), ($user->canEdit()?'Edit':'View')." User (UID: $uid)"); - -if ($user->canEdit()) { - $t->openTag('form', array('method'=>'post', - 'action'=>$mm->baseUrl()."users/$username")); -} else { - $t->openTag('form'); -} - -$t->openFieldset("Login / Authentication"); -if (isset($changed_name) && !$changed_name) { - $t->inputP("Error setting username to ". - "<q>$new_name</q>. This is probably because". - " a user with that name already exists.", - true); -} - -$t->inputText('auth_name','Username', - "This is the name you use to log in, but it is also a ". - "short name that is used in various places, think of it ". - "as a sort of <q>Twitter name</q>.", - $username,!$user->canEdit()); -if ($user->canEdit()) inputNewPassword($user, 'auth_password','Reset Password'); -$t->closeFieldset(); - -$t->openFieldset("Information"); -inputText($user, 'firstname','First Name',''); -inputText($user, 'lastname','Last Name',''); -inputText($user, 'hsclass','Highschool Class of','Please put the full year (ex: 2012)'); -$t->closeFieldset(); - -$t->openFieldset("Contact"); -inputText($user, 'email', 'Email', - "Right now you can only have one email address, ". - "but I'm working on making it so you can have ". - "multiple."); -inputText($user, 'phone', 'Cell Number', - "A home phone number isn't much use here because it is ". - "used to text-message you (if you enable it), and ". - "contact you at competition."); -$t->inputP("When I recieve a message, notify me using the following methods:"); -inputArray($user, 'use', array('email'=>'Email', - 'sms'=>'Text Message')); -$t->closeFieldSet(); - -$t->openFieldSet('Groups'); -$groups = $mm->listGroupNames(); -$group_arr = array(); -foreach ($groups as $group_name) { - $group_arr[$group_name] = ucwords($group_name); -} -inputArray($user, 'groups', $group_arr); -$t->closeFieldset(); - -if ($user->canEdit()) { - $t->tag('input', array('type'=>'submit', 'value'=>'Save')); -} -$t->closeTag('form'); -$mm->footer(); |