function urllogin_userlist_page in urllogin 6
Same name and namespace in other branches
- 7 urllogin.inc \urllogin_userlist_page()
Link to download of user access URL's as a csv. A theme template file is needed of the page-urllogin-userlist.csv.tpl containing the single line: < ?php print $content; ? >
@todo test whether profile module is installed and if fields are correct @todo look at integrating with content profile module
Return value
Page containing user access URL's as a file of tab separated variables
1 string reference to 'urllogin_userlist_page'
- urllogin_menu in ./
urllogin.module - Implements hook_menu().
File
- ./
urllogin.inc, line 319
Code
function urllogin_userlist_page() {
$codekey = variable_get('urllogin_codekey', 0);
$passphrase = urllogin_passphrase();
$thissite = url('l/', array(
'absolute' => TRUE,
));
$destination = '/' . variable_get('urllogin_destination', '');
// Tell browser this is not a web page but a file to download.
drupal_set_header('Content-Type: text/csv; charset=utf-8');
drupal_set_header('Content-Disposition: inline; filename="userlist.csv"');
// Find out if all authenticated users have the permission and
// use a different SQL query depending on result.
$sql = "SELECT pid FROM {permission} AS p WHERE rid = 2 AND (p.perm LIKE '%login via url%')";
if (db_result(db_query($sql)) == "") {
$join_user_role = "JOIN {users_roles} AS r ON r.uid = u.uid\n JOIN {permission} AS p ON p.rid = r.rid ";
$role_has_permission = "AND p.perm LIKE '%login via url%' ";
}
else {
$join_user_role = "";
$role_has_permission = "";
}
// use a different SQL query depending on whether we are to get firstname and lastname from the profile
if (variable_get('urllogin_useprofile', 0) == 0) {
$sql = "SELECT u.uid, u.mail, u.name\n FROM {users} AS u " . $join_user_role . "WHERE u.uid > 1 " . $role_has_permission . "ORDER BY name";
$result = db_query($sql);
print t('UID') . "\t" . t('Name') . "\t" . t('Email') . "\t" . t('URL') . "\r\n";
while ($data = db_fetch_object($result)) {
$urlstr = $thissite . urllogin_encode($data->uid, $codekey, $passphrase) . $destination;
print $data->uid . "\t" . $data->name . "\t" . $data->mail . "\t" . $urlstr . "\r\n";
}
}
else {
$sql = "SELECT u.uid, u.mail, u.name, vf.value AS first, vl.value AS last\n FROM {users} AS u " . $join_user_role . "JOIN {profile_values} AS vf ON vf.uid = u.uid\n JOIN {profile_fields} AS f ON f.fid = vf.fid\n JOIN {profile_values} AS vl ON vl.uid = u.uid\n JOIN {profile_fields} AS l ON l.fid = vl.fid\n WHERE u.uid > 1\n AND f.name = 'profile_firstname'\n AND l.name = 'profile_lastname' " . $role_has_permission . "ORDER BY last, first";
$result = db_query($sql);
print t('UID') . "\t" . t('Name') . "\t" . t('First') . "\t" . t('Last') . "\t" . t('Email') . "\t" . t('URL') . "\r\n";
while ($data = db_fetch_object($result)) {
$urlstr = $thissite . urllogin_encode($data->uid, $codekey, $passphrase) . $destination;
print $data->uid . "\t" . $data->name . "\t" . $data->first . "\t" . $data->last . "\t" . $data->mail . "\t" . $urlstr . "\r\n";
}
}
}