function urllogin_userlist_page in urllogin 7
Same name and namespace in other branches
- 6 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 322
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_add_http_header('Content-Type', 'text/csv; charset=utf-8');
drupal_add_http_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 permission FROM {role_permission} AS p WHERE rid = 2 AND (p.permission LIKE '%login via url%')";
if (db_query($sql)
->fetchField() == "") {
$join_user_role = "JOIN {users_roles} AS r ON r.uid = u.uid\n JOIN {role_permission} AS p ON p.rid = r.rid ";
$role_has_permission = "AND p.permission 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";
foreach ($result as $data) {
$urlstr = $thissite . urllogin_encode($data->uid, $codekey, $passphrase) . $destination;
print $data->uid . "\t" . $data->name . "\t" . $data->mail . "\t" . $urlstr . "\r\n";
}
}
else {
/* Profiles need to be reworked significantly
$sql = "SELECT u.uid, u.mail, u.name, vf.value AS first, vl.value AS last
FROM {users} AS u "
. $join_user_role .
"JOIN {profile_values} AS vf ON vf.uid = u.uid
JOIN {profile_fields} AS f ON f.fid = vf.fid
JOIN {profile_values} AS vl ON vl.uid = u.uid
JOIN {profile_fields} AS l ON l.fid = vl.fid
WHERE u.uid > 1
AND f.name = 'profile_firstname'
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";
}
*/
}
}