5222ae4d by Kevin Burton

User manager updates

1 parent ed49c518
function update_listing_preference() {
var pref = jQuery('#profile_preference').val();
if (pref == "Work") {
jQuery('.work-only').show();
} else {
jQuery('.work-only').hide();
}
}
jQuery(function() {
Date.firstDayOfWeek = 0;
......
......@@ -35,6 +35,19 @@ CBV\load('User');
});
function display_users() {
global $wpdb;
// temporary - remove when done...
$query = $wpdb->get_results("SELECT ID FROM {$wpdb->users}");
foreach($query as $user) {
$status = get_user_meta($user->ID, 'status', true);
if (empty($status)) {
update_user_meta($user->ID, 'status', 'active');
}
}
// end temporary.
if ( isset($_GET['action']) && ($_GET['action']=="edit") && isset($_GET['uid']) && ($_GET['uid'] > 0) ) {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'edit_user.php');
......@@ -95,15 +108,15 @@ function get_users($role = null, $pagenum=1, $records_per_page=0, $return_count_
$search_text
ORDER BY last_name ASC, first_name ASC
";
/*
$query = "
SELECT u.ID, u.user_login, CONCAT('{', GROUP_CONCAT(CONCAT('"', m.meta_key, '"', ':', '"', m.meta_value, '"')), '}') AS meta_data, (SELECT meta_value FROM wp_usermeta as mt where meta_key = 'last_name' and mt.user_id = u.ID) AS ln
FROM wp_users as u left join wp_usermeta as m on u.ID = m.user_id where m.meta_key IN ('first_name', 'last_name')
GROUP BY u.ID
ORDER BY ln;
");
*/
/* cB Query:
SELECT u.ID, u.user_login,
CONCAT('{', GROUP_CONCAT(CONCAT('"', m.meta_key, '"', ':', '"', m.meta_value, '"')), '}') AS meta_data
, (SELECT meta_value FROM wp_usermeta as mt where meta_key = 'last_name' and mt.user_id = u.ID) AS ln
FROM wp_users as u left join wp_usermeta as m on u.ID = m.user_id where m.meta_key IN ('first_name', 'last_name') group by u.ID order by ln;
$array = jseon_decode($meta_data);
*/
if ($records_per_page > 0) {
$limit = " LIMIT ".( ($pagenum - 1) * $records_per_page ).", $records_per_page";
......@@ -139,7 +152,11 @@ class ProfileValidation extends Common\Validation {
}
public function first_name($val) {
update_user_meta($_POST['uid'], __FUNCTION__, User\clean_string($val));
if(empty($val)) {
throw new Exception('First name cannot be blank');
} else {
update_user_meta($_POST['uid'], __FUNCTION__, User\clean_string($val));
}
}
public function initial($val) {
......@@ -147,7 +164,11 @@ class ProfileValidation extends Common\Validation {
}
public function last_name($val) {
update_user_meta($_POST['uid'], __FUNCTION__, User\clean_string($val));
if(empty($val)) {
throw new Exception('Last name cannot be blank');
} else {
update_user_meta($_POST['uid'], __FUNCTION__, User\clean_string($val));
}
}
public function degrees($val) {
......
......@@ -13,7 +13,7 @@ use Tz\WordPress\Tools\Notifications;
use Exception, StdClass;
use WP_User;
$records_per_page = 3;
$records_per_page = 20;
$filter_role = isset($_GET['role']) ? $_GET['role'] : null;
$pagenum = isset($_GET['pagenum']) ? $_GET['pagenum'] : 1;
......
......@@ -176,7 +176,7 @@ unset($rc, $roles['administrator']);
<?php if($role!="administrator"):?>
<h3 style="margin-bottom:5px; padding-bottom:0px;">Account Type:</h3>
<select name="user_role">
<select name="user_role" id="user_role">
<?php foreach($roles as $roled=>$name):?>
<option value="<?php echo $roled;?>" <?php echo ($roled==$role) ? "selected" : "";?>><?php echo $name;?></option>
<?php endforeach;?>
......@@ -201,7 +201,8 @@ unset($rc, $roles['administrator']);
<div style="clear:both;"></div>
<?php if ($role=="member"): ?>
<div id="show_special_status" style="display:<?php echo ($role=="member") ? "block" : "none";?>">
<h3 style="margin-bottom:5px; padding-bottom:0px;">Special Status:</h3>
<input type="hidden" name="special_status_active" value="true" />
<table cellpadding="0" cellspacing="0" border="0">
......@@ -225,7 +226,7 @@ unset($rc, $roles['administrator']);
</tbody>
</table>
<div style="clear:both;"></div>
<?php endif; ?>
</div>
......@@ -242,5 +243,16 @@ unset($rc, $roles['administrator']);
</div>
<script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>
<script type="text/javascript">
jQuery(function() {
jQuery('#user_role').change(function() {
if (jQuery(this).val() == "member") {
jQuery('#show_special_status').show();
} else {
jQuery('#show_special_status').hide();
}
});
});
</script>
......
......@@ -48,6 +48,10 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
<td><input type="text" name="first_name" value="<?php echo get_user_meta($_GET['uid'], 'first_name', true);?>" /></td>
</tr>
<tr>
<th width="150">Initial:</th>
<td><input type="text" name="initial" value="<?php echo get_user_meta($_GET['uid'], 'initial', true);?>" /></td>
</tr>
<tr>
<th>Last Name:</th>
<td><input type="text" name="last_name" value="<?php echo get_user_meta($_GET['uid'], 'last_name', true);?>" /></td>
</tr>
......@@ -71,7 +75,15 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
<tbody>
<tr>
<th width="150">&nbsp;</th>
<td><select name="profile_preference"><option value="Home" <?php echo ($profile_preference=="Home") ? "selected" : ""; ?>>Home&nbsp;</option><option value="Work" <?php echo ($profile_preference=="Work") ? "selected" : ""; ?>>Work&nbsp;</option></select></td>
<td><select name="profile_preference" id="profile_preference"><option value="Home" <?php echo ($profile_preference=="Home") ? "selected" : ""; ?>>Home&nbsp;</option><option value="Work" <?php echo ($profile_preference=="Work") ? "selected" : ""; ?>>Work&nbsp;</option></select></td>
</tr>
<tr class="work-only">
<th>Company:</th>
<td><input type="text" name="company" value="<?php echo get_user_meta($_GET['uid'], 'company', true);?>" /></td>
</tr>
<tr class="work-only">
<th>Title:</th>
<td><input type="text" name="title" value="<?php echo get_user_meta($_GET['uid'], 'title', true);?>" /></td>
</tr>
<tr>
<th>Address:</th>
......@@ -128,6 +140,10 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
<th>Mobile:</th>
<td><input type="text" name="mobile" value="<?php echo get_user_meta($_GET['uid'], 'mobile', true);?>" /></td>
</tr>
<tr class="work-only">
<th>Website:</th>
<td><input type="text" name="website" value="<?php echo get_user_meta($_GET['uid'], 'website', true);?>" /></td>
</tr>
</tbody>
</table>
......@@ -162,4 +178,13 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
</form>
</div>
<script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>
\ No newline at end of file
<script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>
<script>
jQuery(function() {
update_listing_preference();
jQuery('#profile_preference').change(function() {
update_listing_preference();
});
});
</script>
\ No newline at end of file
......