plugins/SpecialUserFuncs.php
changeset 103 a8891e108c95
parent 101 bb4e677a4da9
child 105 f7750e454168
equal deleted inserted replaced
102:d807dcd7aed7 103:a8891e108c95
    78       ));
    78       ));
    79     
    79     
    80     $paths->add_page(Array(
    80     $paths->add_page(Array(
    81       \'name\'=>\'Forgot password\',
    81       \'name\'=>\'Forgot password\',
    82       \'urlname\'=>\'PasswordReset\',
    82       \'urlname\'=>\'PasswordReset\',
       
    83       \'namespace\'=>\'Special\',
       
    84       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
       
    85       ));
       
    86     
       
    87     $paths->add_page(Array(
       
    88       \'name\'=>\'Member list\',
       
    89       \'urlname\'=>\'Memberlist\',
    83       \'namespace\'=>\'Special\',
    90       \'namespace\'=>\'Special\',
    84       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    91       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    85       ));
    92       ));
    86     ');
    93     ');
    87 
    94 
  1064           <p><input type="submit" name="do_reset" value="Mail new password" /></p>
  1071           <p><input type="submit" name="do_reset" value="Mail new password" /></p>
  1065         </form>';
  1072         </form>';
  1066   $template->footer();
  1073   $template->footer();
  1067 }
  1074 }
  1068 
  1075 
       
  1076 function page_Special_Memberlist()
       
  1077 {
       
  1078   global $db, $session, $paths, $template, $plugins; // Common objects
       
  1079   $template->header();
       
  1080   
       
  1081   $startletters = 'abcdefghijklmnopqrstuvwxyz';
       
  1082   $startletters = enano_str_split($startletters);
       
  1083   $startletter = ( isset($_GET['letter']) ) ? strtolower($_GET['letter']) : '';
       
  1084   if ( !in_array($startletter, $startletters) && $startletter != 'chr' )
       
  1085   {
       
  1086     $startletter = '';
       
  1087   }
       
  1088   
       
  1089   $startletter_sql = $startletter;
       
  1090   if ( $startletter == 'chr' )
       
  1091   {
       
  1092     $startletter_sql = '([^a-z])';
       
  1093   }
       
  1094   
       
  1095   // determine number of rows
       
  1096   $q = $db->sql_query('SELECT u.user_id FROM '.table_prefix.'users AS u WHERE u.username REGEXP "^' . $startletter_sql . '" AND u.username != "Anonymous";');
       
  1097   if ( !$q )
       
  1098     $db->_die();
       
  1099   
       
  1100   $num_rows = $db->numrows();
       
  1101   $db->free_result();
       
  1102   
       
  1103   // offset
       
  1104   $offset = ( isset($_GET['offset']) && strval(intval($_GET['offset'])) === $_GET['offset']) ? intval($_GET['offset']) : 0;
       
  1105   
       
  1106   // sort order
       
  1107   $sortkeys = array(
       
  1108       'uid' => 'u.user_id',
       
  1109       'username' => 'u.username',
       
  1110       'email' => 'u.email'
       
  1111     );
       
  1112   
       
  1113   $sortby = ( isset($_GET['sort']) && isset($sortkeys[$_GET['sort']]) ) ? $_GET['sort'] : 'username';
       
  1114   $sort_sqllet = $sortkeys[$sortby];
       
  1115   
       
  1116   $target_order = ( isset($_GET['orderby']) && in_array($_GET['orderby'], array('ASC', 'DESC')) )? $_GET['orderby'] : 'ASC';
       
  1117   
       
  1118   $sortorders = array();
       
  1119   foreach ( $sortkeys as $k => $_unused )
       
  1120   {
       
  1121     $sortorders[$k] = ( $sortby == $k ) ? ( $target_order == 'ASC' ? 'DESC' : 'ASC' ) : 'ASC';
       
  1122   }
       
  1123   
       
  1124   // Why 3.3714%? 100 percent / 28 cells, minus a little (0.2% / cell) to account for cell spacing
       
  1125   
       
  1126   echo '<div class="tblholder">
       
  1127           <table border="0" cellspacing="1" cellpadding="4" style="text-align: center;">
       
  1128             <tr>';
       
  1129   echo '<td class="row1" style="width: 3.3714%;"><a href="' . makeUrlNS('Special', 'Memberlist', 'letter=&sort=' . $sortby . '&orderby=' . $target_order, true) . '">All</a></td>';
       
  1130   echo '<td class="row1" style="width: 3.3714%;"><a href="' . makeUrlNS('Special', 'Memberlist', 'letter=chr&sort=' . $sortby . '&orderby=' . $target_order, true) . '">#</a></td>';
       
  1131   foreach ( $startletters as $letter )
       
  1132   {
       
  1133     echo '<td class="row1" style="width: 3.3714%;"><a href="' . makeUrlNS('Special', 'Memberlist', 'letter=' . $letter . '&sort=' . $sortby . '&orderby=' . $target_order, true) . '">' . strtoupper($letter) . '</a></td>';
       
  1134   }
       
  1135   echo '    </tr>
       
  1136           </table>
       
  1137         </div>';
       
  1138   
       
  1139   // formatter parameters
       
  1140   $formatter = new MemberlistFormatter();
       
  1141   $formatters = array(
       
  1142     'username' => array($formatter, 'username'),
       
  1143     'user_level' => array($formatter, 'user_level'),
       
  1144     'email' => array($formatter, 'email')
       
  1145     );
       
  1146   
       
  1147   // Column markers
       
  1148   $headings = '<tr>
       
  1149                  <th style="max-width: 50px;">
       
  1150                    <a href="' . makeUrlNS('Special', 'Memberlist', 'letter=' . $startletter . '&sort=uid&orderby=' . $sortorders['uid'], true) . '">#</a>
       
  1151                  </th>
       
  1152                  <th>
       
  1153                    <a href="' . makeUrlNS('Special', 'Memberlist', 'letter=' . $startletter . '&sort=username&orderby=' . $sortorders['username'], true) . '">Username</a>
       
  1154                  </th>
       
  1155                  <th>
       
  1156                    <a href="' . makeUrlNS('Special', 'Memberlist', 'letter=' . $startletter . '&sort=email&orderby=' . $sortorders['email'], true) . '">E-mail</a>
       
  1157                  </th>
       
  1158                </tr>';
       
  1159   
       
  1160   $q = $db->sql_unbuffered_query('SELECT u.user_id, u.username, u.reg_time, u.email, u.user_level, x.email_public FROM '.table_prefix.'users AS u
       
  1161                                     LEFT JOIN '.table_prefix.'users_extra AS x
       
  1162                                       ON ( u.user_id = x.user_id )
       
  1163                                     WHERE u.username REGEXP "^' . $startletter_sql . '" AND u.username != "Anonymous"
       
  1164                                     ORDER BY ' . $sort_sqllet . ' ' . $target_order . ';');
       
  1165   if ( !$q )
       
  1166     $db->_die();
       
  1167   
       
  1168   $html = paginate(
       
  1169             $q,                                                                                                       // MySQL result resource
       
  1170             '<tr>
       
  1171                <td class="{_css_class}">{user_id}</td>
       
  1172                <td class="{_css_class}" style="text-align: left;">{username}<br /><small>{user_level}</small></td>
       
  1173                <td class="{_css_class}">{email}</small></td>
       
  1174              </tr>
       
  1175              ',                                                                                                       // TPL code for rows
       
  1176              $num_rows,                                                                                               // Number of results
       
  1177              makeUrlNS('Special', 'Memberlist', 'letter=' . $startletter . '&offset=%s&sort=' . $sortby . '&orderby=' . $target_order ), // Result URL
       
  1178              $offset,                                                                                                 // Start at this number
       
  1179              25,                                                                                                      // Results per page
       
  1180              $formatters,                                                                                             // Formatting hooks
       
  1181              '<div class="tblholder">
       
  1182                 <table border="0" cellspacing="1" cellpadding="4" style="text-align: center;">
       
  1183                   ' . $headings . '
       
  1184                  ',                                                                                                   // Header (printed before rows)
       
  1185              '  ' . $headings . '
       
  1186                  </table>
       
  1187               </div>
       
  1188               '                                                                                                       // Footer (printed after rows)
       
  1189           );
       
  1190   
       
  1191   if ( $num_rows < 1 )
       
  1192   {
       
  1193     echo '<p>Sorry - no users with usernames that start with that letter could be found.</p>';
       
  1194   }
       
  1195   else
       
  1196   {
       
  1197     echo $html;
       
  1198   }
       
  1199   
       
  1200   $template->footer();
       
  1201 }
       
  1202 
       
  1203 /**
       
  1204  * Class for formatting results for the memberlist.
       
  1205  * @access private
       
  1206  */
       
  1207 
       
  1208 class MemberlistFormatter
       
  1209 {
       
  1210   function username($username, $row)
       
  1211   {
       
  1212     global $db, $session, $paths, $template, $plugins; // Common objects
       
  1213     $userpage = $paths->nslist['User'] . sanitize_page_id($username);
       
  1214     $class = ( isPage($userpage) ) ? ' title="Click to view this user\'s userpage"' : ' class="wikilink-nonexistent" title="This user hasn\'t created a userpage yet, but you can still view profile details by clicking this link."';
       
  1215     $anchor = '<a href="' . makeUrlNS('User', sanitize_page_id($username)) . '"' . $class . '>' . htmlspecialchars($username) . '</a>';
       
  1216     if ( $session->user_level >= USER_LEVEL_ADMIN )
       
  1217     {
       
  1218       $anchor .= ' <small>- <a href="' . makeUrlNS('Special', 'Administration', 'module=' . $paths->nslist['Admin'] . 'UserManager&src=get&username=' . urlencode($username), true) . '"
       
  1219                                onclick="ajaxAdminUser(\'' . addslashes(htmlspecialchars($username)) . '\'); return false;">Administer user</a></small>';
       
  1220     }
       
  1221     return $anchor;
       
  1222   }
       
  1223   function user_level($level, $row)
       
  1224   {
       
  1225     global $db, $session, $paths, $template, $plugins; // Common objects
       
  1226     switch ( $level )
       
  1227     {
       
  1228       case USER_LEVEL_GUEST:
       
  1229         $s_level = 'Guest'; break;
       
  1230       case USER_LEVEL_MEMBER:
       
  1231       case USER_LEVEL_CHPREF:
       
  1232         $s_level = 'Member'; break;
       
  1233       case USER_LEVEL_MOD:
       
  1234         $s_level = 'Moderator'; break;
       
  1235       case USER_LEVEL_ADMIN:
       
  1236         $s_level = 'Site administrator'; break;
       
  1237       default:
       
  1238         $s_level = 'Unknown (level ' . $level . ')';
       
  1239     }
       
  1240     return $s_level;
       
  1241   }
       
  1242   function email($addy, $row)
       
  1243   {
       
  1244     if ( $row['email_public'] == '1' )
       
  1245     {
       
  1246       global $email;
       
  1247       $addy = $email->encryptEmail($addy);
       
  1248       return $addy;
       
  1249     }
       
  1250     else
       
  1251     {
       
  1252       return '<small>&lt;Non-public&gt;</small>';
       
  1253     }
       
  1254   }
       
  1255 }
       
  1256 
  1069 ?>
  1257 ?>