5222ae4d by Kevin Burton

User manager updates

1 parent ed49c518
1 function update_listing_preference() {
2 var pref = jQuery('#profile_preference').val();
3 if (pref == "Work") {
4 jQuery('.work-only').show();
5 } else {
6 jQuery('.work-only').hide();
7 }
8 }
9
1 jQuery(function() { 10 jQuery(function() {
2 11
3 Date.firstDayOfWeek = 0; 12 Date.firstDayOfWeek = 0;
......
...@@ -35,6 +35,19 @@ CBV\load('User'); ...@@ -35,6 +35,19 @@ CBV\load('User');
35 }); 35 });
36 36
37 function display_users() { 37 function display_users() {
38 global $wpdb;
39 // temporary - remove when done...
40 $query = $wpdb->get_results("SELECT ID FROM {$wpdb->users}");
41 foreach($query as $user) {
42 $status = get_user_meta($user->ID, 'status', true);
43 if (empty($status)) {
44 update_user_meta($user->ID, 'status', 'active');
45 }
46 }
47
48
49 // end temporary.
50
38 51
39 if ( isset($_GET['action']) && ($_GET['action']=="edit") && isset($_GET['uid']) && ($_GET['uid'] > 0) ) { 52 if ( isset($_GET['action']) && ($_GET['action']=="edit") && isset($_GET['uid']) && ($_GET['uid'] > 0) ) {
40 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'edit_user.php'); 53 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_ ...@@ -95,15 +108,15 @@ function get_users($role = null, $pagenum=1, $records_per_page=0, $return_count_
95 $search_text 108 $search_text
96 ORDER BY last_name ASC, first_name ASC 109 ORDER BY last_name ASC, first_name ASC
97 "; 110 ";
111 /*
112 $query = "
113 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
114 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')
115 GROUP BY u.ID
116 ORDER BY ln;
117 ");
118 */
98 119
99 /* cB Query:
100 SELECT u.ID, u.user_login,
101 CONCAT('{', GROUP_CONCAT(CONCAT('"', m.meta_key, '"', ':', '"', m.meta_value, '"')), '}') AS meta_data
102 , (SELECT meta_value FROM wp_usermeta as mt where meta_key = 'last_name' and mt.user_id = u.ID) AS ln
103 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;
104
105 $array = jseon_decode($meta_data);
106 */
107 120
108 if ($records_per_page > 0) { 121 if ($records_per_page > 0) {
109 $limit = " LIMIT ".( ($pagenum - 1) * $records_per_page ).", $records_per_page"; 122 $limit = " LIMIT ".( ($pagenum - 1) * $records_per_page ).", $records_per_page";
...@@ -139,7 +152,11 @@ class ProfileValidation extends Common\Validation { ...@@ -139,7 +152,11 @@ class ProfileValidation extends Common\Validation {
139 } 152 }
140 153
141 public function first_name($val) { 154 public function first_name($val) {
142 update_user_meta($_POST['uid'], __FUNCTION__, User\clean_string($val)); 155 if(empty($val)) {
156 throw new Exception('First name cannot be blank');
157 } else {
158 update_user_meta($_POST['uid'], __FUNCTION__, User\clean_string($val));
159 }
143 } 160 }
144 161
145 public function initial($val) { 162 public function initial($val) {
...@@ -147,7 +164,11 @@ class ProfileValidation extends Common\Validation { ...@@ -147,7 +164,11 @@ class ProfileValidation extends Common\Validation {
147 } 164 }
148 165
149 public function last_name($val) { 166 public function last_name($val) {
150 update_user_meta($_POST['uid'], __FUNCTION__, User\clean_string($val)); 167 if(empty($val)) {
168 throw new Exception('Last name cannot be blank');
169 } else {
170 update_user_meta($_POST['uid'], __FUNCTION__, User\clean_string($val));
171 }
151 } 172 }
152 173
153 public function degrees($val) { 174 public function degrees($val) {
......
...@@ -13,7 +13,7 @@ use Tz\WordPress\Tools\Notifications; ...@@ -13,7 +13,7 @@ use Tz\WordPress\Tools\Notifications;
13 use Exception, StdClass; 13 use Exception, StdClass;
14 use WP_User; 14 use WP_User;
15 15
16 $records_per_page = 3; 16 $records_per_page = 20;
17 17
18 $filter_role = isset($_GET['role']) ? $_GET['role'] : null; 18 $filter_role = isset($_GET['role']) ? $_GET['role'] : null;
19 $pagenum = isset($_GET['pagenum']) ? $_GET['pagenum'] : 1; 19 $pagenum = isset($_GET['pagenum']) ? $_GET['pagenum'] : 1;
......
...@@ -176,7 +176,7 @@ unset($rc, $roles['administrator']); ...@@ -176,7 +176,7 @@ unset($rc, $roles['administrator']);
176 176
177 <?php if($role!="administrator"):?> 177 <?php if($role!="administrator"):?>
178 <h3 style="margin-bottom:5px; padding-bottom:0px;">Account Type:</h3> 178 <h3 style="margin-bottom:5px; padding-bottom:0px;">Account Type:</h3>
179 <select name="user_role"> 179 <select name="user_role" id="user_role">
180 <?php foreach($roles as $roled=>$name):?> 180 <?php foreach($roles as $roled=>$name):?>
181 <option value="<?php echo $roled;?>" <?php echo ($roled==$role) ? "selected" : "";?>><?php echo $name;?></option> 181 <option value="<?php echo $roled;?>" <?php echo ($roled==$role) ? "selected" : "";?>><?php echo $name;?></option>
182 <?php endforeach;?> 182 <?php endforeach;?>
...@@ -201,7 +201,8 @@ unset($rc, $roles['administrator']); ...@@ -201,7 +201,8 @@ unset($rc, $roles['administrator']);
201 201
202 <div style="clear:both;"></div> 202 <div style="clear:both;"></div>
203 203
204 <?php if ($role=="member"): ?> 204
205 <div id="show_special_status" style="display:<?php echo ($role=="member") ? "block" : "none";?>">
205 <h3 style="margin-bottom:5px; padding-bottom:0px;">Special Status:</h3> 206 <h3 style="margin-bottom:5px; padding-bottom:0px;">Special Status:</h3>
206 <input type="hidden" name="special_status_active" value="true" /> 207 <input type="hidden" name="special_status_active" value="true" />
207 <table cellpadding="0" cellspacing="0" border="0"> 208 <table cellpadding="0" cellspacing="0" border="0">
...@@ -225,7 +226,7 @@ unset($rc, $roles['administrator']); ...@@ -225,7 +226,7 @@ unset($rc, $roles['administrator']);
225 </tbody> 226 </tbody>
226 </table> 227 </table>
227 <div style="clear:both;"></div> 228 <div style="clear:both;"></div>
228 <?php endif; ?> 229 </div>
229 230
230 231
231 232
...@@ -242,5 +243,16 @@ unset($rc, $roles['administrator']); ...@@ -242,5 +243,16 @@ unset($rc, $roles['administrator']);
242 </div> 243 </div>
243 244
244 <script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script> 245 <script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>
246 <script type="text/javascript">
247 jQuery(function() {
248 jQuery('#user_role').change(function() {
249 if (jQuery(this).val() == "member") {
250 jQuery('#show_special_status').show();
251 } else {
252 jQuery('#show_special_status').hide();
253 }
254 });
255 });
256 </script>
245 257
246 258
......
...@@ -48,6 +48,10 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true); ...@@ -48,6 +48,10 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
48 <td><input type="text" name="first_name" value="<?php echo get_user_meta($_GET['uid'], 'first_name', true);?>" /></td> 48 <td><input type="text" name="first_name" value="<?php echo get_user_meta($_GET['uid'], 'first_name', true);?>" /></td>
49 </tr> 49 </tr>
50 <tr> 50 <tr>
51 <th width="150">Initial:</th>
52 <td><input type="text" name="initial" value="<?php echo get_user_meta($_GET['uid'], 'initial', true);?>" /></td>
53 </tr>
54 <tr>
51 <th>Last Name:</th> 55 <th>Last Name:</th>
52 <td><input type="text" name="last_name" value="<?php echo get_user_meta($_GET['uid'], 'last_name', true);?>" /></td> 56 <td><input type="text" name="last_name" value="<?php echo get_user_meta($_GET['uid'], 'last_name', true);?>" /></td>
53 </tr> 57 </tr>
...@@ -71,7 +75,15 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true); ...@@ -71,7 +75,15 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
71 <tbody> 75 <tbody>
72 <tr> 76 <tr>
73 <th width="150">&nbsp;</th> 77 <th width="150">&nbsp;</th>
74 <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> 78 <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>
79 </tr>
80 <tr class="work-only">
81 <th>Company:</th>
82 <td><input type="text" name="company" value="<?php echo get_user_meta($_GET['uid'], 'company', true);?>" /></td>
83 </tr>
84 <tr class="work-only">
85 <th>Title:</th>
86 <td><input type="text" name="title" value="<?php echo get_user_meta($_GET['uid'], 'title', true);?>" /></td>
75 </tr> 87 </tr>
76 <tr> 88 <tr>
77 <th>Address:</th> 89 <th>Address:</th>
...@@ -128,6 +140,10 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true); ...@@ -128,6 +140,10 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
128 <th>Mobile:</th> 140 <th>Mobile:</th>
129 <td><input type="text" name="mobile" value="<?php echo get_user_meta($_GET['uid'], 'mobile', true);?>" /></td> 141 <td><input type="text" name="mobile" value="<?php echo get_user_meta($_GET['uid'], 'mobile', true);?>" /></td>
130 </tr> 142 </tr>
143 <tr class="work-only">
144 <th>Website:</th>
145 <td><input type="text" name="website" value="<?php echo get_user_meta($_GET['uid'], 'website', true);?>" /></td>
146 </tr>
131 </tbody> 147 </tbody>
132 </table> 148 </table>
133 149
...@@ -162,4 +178,13 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true); ...@@ -162,4 +178,13 @@ $preference = get_user_meta($user->ID, 'email_address_preference', true);
162 178
163 </form> 179 </form>
164 </div> 180 </div>
165 <script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>
...\ No newline at end of file ...\ No newline at end of file
181 <script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>
182 <script>
183 jQuery(function() {
184 update_listing_preference();
185
186 jQuery('#profile_preference').change(function() {
187 update_listing_preference();
188 });
189 });
190 </script>
...\ No newline at end of file ...\ No newline at end of file
......