| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: profile_csv.module,v 1.10 2008/07/21 00:47:04 kbahey Exp $ |
| 3 |
|
|
| 4 |
|
|
| 5 |
define('PROFILE_CSV_STATUS', 'profile_csv_status'); |
define('PROFILE_CSV_STATUS', 'profile_csv_status'); |
| 16 |
return $output; |
return $output; |
| 17 |
} |
} |
| 18 |
|
|
| 19 |
|
function profile_csv_perm() { |
| 20 |
|
return array(PROFILE_CSV_PERM_DOWNLOAD); |
| 21 |
|
} |
| 22 |
|
|
| 23 |
|
function profile_csv_menu() { |
| 24 |
|
$items = array(); |
| 25 |
|
|
| 26 |
|
$items['admin/settings/profile_csv'] = array( |
| 27 |
|
'title' => 'Profile CSV', |
| 28 |
|
'type' => MENU_NORMAL_ITEM, |
| 29 |
|
'description' => 'Profile CSV user data selection', |
| 30 |
|
'page callback' => 'drupal_get_form', |
| 31 |
|
'page arguments' => array('profile_csv_admin_settings'), |
| 32 |
|
'access arguments' => array('administer site configuration'), |
| 33 |
|
); |
| 34 |
|
$items['profile_csv'] = array( |
| 35 |
|
'title' => 'Profile CSV Export', |
| 36 |
|
'type' => MENU_SUGGESTED_ITEM, // Optional |
| 37 |
|
'page callback' => 'profile_csv_page', |
| 38 |
|
'access arguments' => array(PROFILE_CSV_PERM_DOWNLOAD), |
| 39 |
|
); |
| 40 |
|
|
| 41 |
|
return $items; |
| 42 |
|
} |
| 43 |
|
|
| 44 |
function profile_csv_admin_settings() { |
function profile_csv_admin_settings() { |
| 45 |
|
$form['extra'] = array( |
| 46 |
|
'#type' => 'markup', |
| 47 |
|
'#value' => t('Remember to enable the profile_csv menu item so users who have the permission to download profile data have this item on their menus'), |
| 48 |
|
); |
| 49 |
$set = 'roles'; |
$set = 'roles'; |
| 50 |
$form[$set] = array( |
$form[$set] = array( |
| 51 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 52 |
'#title' => t('Roles'), |
'#title' => t('Roles'), |
| 53 |
'#description' => t('Select one or more roles.'), |
'#description' => t('Select one or more roles.'), |
| 54 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 55 |
'#collapsed' => true, |
'#collapsed' => TRUE, |
| 56 |
); |
); |
| 57 |
|
|
| 58 |
$u_role = user_roles($membersonly = TRUE); |
foreach (user_roles($membersonly = TRUE) as $rid => $name) { |
|
foreach ( $u_role as $rid => $name) { |
|
| 59 |
$role = PROFILE_CSV_ROLE . $rid; |
$role = PROFILE_CSV_ROLE . $rid; |
| 60 |
$form[$set][PROFILE_CSV_ROLE . $rid] = array( |
$form[$set][$role] = array( |
| 61 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 62 |
'#title' => $name, |
'#title' => $name, |
| 63 |
'#return_value' => 1, |
'#return_value' => 1, |
| 64 |
'#default_value' => variable_get($role, 0), |
'#default_value' => variable_get($role, 0), |
| 65 |
); |
); |
| 66 |
} |
} |
| 67 |
$set = 'status'; |
$set = 'status'; |
| 68 |
$form[$set] = array( |
$form[$set] = array( |
| 69 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 70 |
'#title' => t('User status'), |
'#title' => t('User status'), |
| 71 |
'#description' => t('Select one status.'), |
'#description' => t('Select one status.'), |
| 72 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 73 |
'#collapsed' => true, |
'#collapsed' => TRUE, |
| 74 |
|
); |
| 75 |
|
$options = array( |
| 76 |
|
1 => t('Active'), |
| 77 |
|
0 => t('Blocked'), |
| 78 |
|
2 => t('Both'), |
| 79 |
); |
); |
| 80 |
$form[$set][PROFILE_CSV_STATUS] = array( |
$form[$set][PROFILE_CSV_STATUS] = array( |
| 81 |
'#type' => 'select', |
'#type' => 'select', |
| 82 |
'#default_value' => variable_get(PROFILE_CSV_STATUS, 2), |
'#default_value' => variable_get(PROFILE_CSV_STATUS, 2), |
| 83 |
'#options' => array( 1 => t('active'), 0 => t('blocked'), 2 => t('both')), |
'#options' => $options, |
| 84 |
'#description' => t(''), |
'#description' => t(''), |
| 85 |
); |
); |
| 86 |
|
|
| 87 |
$set = 'fields'; |
$set = 'fields'; |
| 88 |
$form[$set] = array( |
$form[$set] = array( |
| 89 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 90 |
'#title' => t('General'), |
'#title' => t('General'), |
| 91 |
'#description' => t('Select one or more profile fields.'), |
'#description' => t('Select one or more profile fields.'), |
| 92 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 93 |
'#collapsed' => true, |
'#collapsed' => TRUE, |
| 94 |
); |
); |
| 95 |
$form[$set][PROFILE_CSV_PARAM .'uid'] = array( |
$form[$set][PROFILE_CSV_PARAM . 'uid'] = array( |
| 96 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 97 |
'#title' => t('User ID'), |
'#title' => t('User ID'), |
| 98 |
'#return_value' => 1, |
'#return_value' => 1, |
| 99 |
'#default_value' => variable_get(PROFILE_CSV_PARAM .'uid', 0), |
'#default_value' => variable_get(PROFILE_CSV_PARAM .'uid', 0), |
| 100 |
); |
); |
| 101 |
$form[$set][PROFILE_CSV_PARAM .'name'] = array( |
$form[$set][PROFILE_CSV_PARAM . 'name'] = array( |
| 102 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 103 |
'#title' => t('User Name'), |
'#title' => t('User Name'), |
| 104 |
'#return_value' => 1, |
'#return_value' => 1, |
| 105 |
'#default_value' => variable_get(PROFILE_CSV_PARAM .'name', 0), |
'#default_value' => variable_get(PROFILE_CSV_PARAM .'name', 0), |
| 106 |
); |
); |
| 107 |
$form[$set][PROFILE_CSV_PARAM .'mail'] = array( |
$form[$set][PROFILE_CSV_PARAM . 'mail'] = array( |
| 108 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 109 |
'#title' => t('User Email'), |
'#title' => t('User Email'), |
| 110 |
'#return_value' => 1, |
'#return_value' => 1, |
| 111 |
'#default_value' => variable_get(PROFILE_CSV_PARAM .'mail', 0), |
'#default_value' => variable_get(PROFILE_CSV_PARAM .'mail', 0), |
| 112 |
); |
); |
| 113 |
|
|
| 114 |
$set = 'profile'; |
$set = 'profile'; |
| 115 |
$form[$set] = array( |
$form[$set] = array( |
| 116 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 117 |
'#title' => t('Categories'), |
'#title' => t('Categories'), |
| 118 |
'#description' => t('Select one or more profile fields from categories below.'), |
'#description' => t('Select one or more profile fields from categories below.'), |
| 119 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 120 |
'#collapsed' => true, |
'#collapsed' => TRUE, |
| 121 |
); |
); |
| 122 |
|
|
| 123 |
$result = db_query("SELECT pf.fid, pf.name, pf.title, pf.category FROM {profile_fields} pf ORDER BY pf.category, pf.weight, pf.title"); |
$result = db_query("SELECT pf.fid, pf.name, pf.title, pf.category |
| 124 |
|
FROM {profile_fields} pf |
| 125 |
|
ORDER BY pf.category, pf.weight, pf.title"); |
| 126 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 127 |
$fld = PROFILE_CSV_PARAM .'profile_'. $row->fid; |
$fld = PROFILE_CSV_PARAM .'profile_'. $row->fid; |
|
|
|
| 128 |
if (!isset($form[$set][$row->category])) { |
if (!isset($form[$set][$row->category])) { |
| 129 |
$form[$set][$row->category] = array( |
$form[$set][$row->category] = array( |
| 130 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 131 |
'#title' => $row->category, |
'#title' => $row->category, |
| 132 |
'#collapsible' => true, |
'#collapsible' => TRUE, |
| 133 |
); |
); |
| 134 |
} |
} |
| 135 |
|
|
| 136 |
$form[$set][$row->category][$fld] = array( |
$form[$set][$row->category][$fld] = array( |
| 137 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 138 |
'#title' => $row->title, |
'#title' => $row->title, |
| 139 |
'#return_value' => 1, |
'#return_value' => 1, |
| 140 |
'#default_value' => variable_get($fld, 0), |
'#default_value' => variable_get($fld, 0), |
| 141 |
); |
); |
| 142 |
} |
} |
| 143 |
return system_settings_form($form); |
return system_settings_form($form); |
|
} |
|
|
|
|
|
function profile_csv_perm() { |
|
|
return array(PROFILE_CSV_PERM_DOWNLOAD); |
|
|
} |
|
|
|
|
|
function profile_csv_menu() { |
|
|
$items = array(); |
|
|
|
|
|
$items['admin/settings/profile_csv'] = array( |
|
|
'title' => 'profile csv', |
|
|
'description' => 'profile csv settings', |
|
|
'page callback' => 'drupal_get_form', |
|
|
'page arguments' => array('profile_csv_admin_settings'), |
|
|
'access callback' => 'user_access', |
|
|
'access arguments' => array('administer site configuration'), |
|
|
'type' => MENU_NORMAL_ITEM, // optional |
|
|
); |
|
|
$items['profile_csv'] = array( |
|
|
'title' => 'Profile Export CSV', |
|
|
'page callback' => 'profile_csv_page', |
|
|
'access callback' => 'user_access', |
|
|
'access arguments' => array(PROFILE_CSV_PERM_DOWNLOAD), |
|
|
'type' => MENU_NORMAL_ITEM, |
|
|
); |
|
|
return $items; |
|
| 144 |
} |
} |
| 145 |
|
|
| 146 |
function profile_csv_page() { |
function profile_csv_page() { |
|
|
|
| 147 |
$data = _profile_csv_header(); |
$data = _profile_csv_header(); |
| 148 |
$user_status = variable_get(PROFILE_CSV_STATUS, 2); |
$user_status = variable_get(PROFILE_CSV_STATUS, 2); |
| 149 |
if (variable_get(PROFILE_CSV_ROLE .'2', 0)) { |
if (variable_get(PROFILE_CSV_ROLE .'2', 0)) { |
| 160 |
} |
} |
| 161 |
} |
} |
| 162 |
else { |
else { |
| 163 |
$result = db_query("SELECT u.uid, u.status, ur.rid FROM {users} u |
$result = db_query("SELECT u.uid, u.status, ur.rid |
| 164 |
INNER JOIN {users_roles} ur ON u.uid = ur.uid |
FROM {users} u |
| 165 |
WHERE u.uid > 1"); |
INNER JOIN {users_roles} ur ON u.uid = ur.uid |
| 166 |
|
WHERE u.uid > 1"); |
| 167 |
$prev_uid = 0; |
$prev_uid = 0; |
| 168 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 169 |
if ((variable_get(PROFILE_CSV_ROLE . $row->rid, 0)) && ($row->uid != $prev_uid)) { |
if ((variable_get(PROFILE_CSV_ROLE . $row->rid, 0)) && ($row->uid != $prev_uid)) { |
| 192 |
|
|
| 193 |
if (!isset($fields)) { |
if (!isset($fields)) { |
| 194 |
$fields = array(); |
$fields = array(); |
| 195 |
$result = db_query('SELECT pf.fid, pf.name, pf.title, pf.type, pf.visibility FROM {profile_fields} pf ORDER BY pf.category, pf.weight, pf.title'); |
$result = db_query('SELECT pf.fid, pf.name, pf.title, pf.type, pf.visibility |
| 196 |
|
FROM {profile_fields} pf |
| 197 |
|
ORDER BY pf.category, pf.weight, pf.title'); |
| 198 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 199 |
if (variable_get(PROFILE_CSV_PARAM .'profile_'. $row->fid, 0)) { |
if (variable_get(PROFILE_CSV_PARAM .'profile_'. $row->fid, 0)) { |
| 200 |
$fields[] = array('name' => $row->name, 'title' => $row->title, 'type' => $row->type, 'visibility' => $row->visibility); |
$fields[] = array('name' => $row->name, 'title' => $row->title, 'type' => $row->type, 'visibility' => $row->visibility); |
| 226 |
$users = array(); |
$users = array(); |
| 227 |
$result = db_query('SELECT u.uid, u.name, u.mail, u.data FROM {users} u WHERE u.uid = %d', $uid); |
$result = db_query('SELECT u.uid, u.name, u.mail, u.data FROM {users} u WHERE u.uid = %d', $uid); |
| 228 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 229 |
if (variable_get(PROFILE_CSV_PARAM .'uid', 0)) |
if (variable_get(PROFILE_CSV_PARAM .'uid', 0)) { |
| 230 |
$users[] = $row->uid; |
$users[] = $row->uid; |
| 231 |
|
} |
| 232 |
if (variable_get(PROFILE_CSV_PARAM .'name', 0)) |
if (variable_get(PROFILE_CSV_PARAM .'name', 0)) { |
| 233 |
$users[] = $row->name; |
$users[] = $row->name; |
| 234 |
|
} |
| 235 |
if (variable_get(PROFILE_CSV_PARAM .'mail', 0)) |
if (variable_get(PROFILE_CSV_PARAM .'mail', 0)) { |
| 236 |
$users[] = $row->mail; |
$users[] = $row->mail; |
| 237 |
$users['data'] = unserialize($row->data); |
} |
| 238 |
|
$users['data'] = unserialize($row->data); |
| 239 |
} |
} |
| 240 |
return $users; |
return $users; |
| 241 |
} |
} |
| 245 |
$profile_result = array(); |
$profile_result = array(); |
| 246 |
foreach ($profile_fields as $profile_field) { |
foreach ($profile_fields as $profile_field) { |
| 247 |
if ($profile_field ['visibility'] == 4) { |
if ($profile_field ['visibility'] == 4) { |
| 248 |
//$value = try to get it from the $user_data |
// Try to get it from the $user_data |
| 249 |
$value = $user_data[$profile_field['name']]; |
$value = $user_data[$profile_field['name']]; |
| 250 |
} |
} |
| 251 |
else { |
else { |
| 252 |
$value = db_result(db_query("SELECT pv.value FROM {profile_fields} pf, {profile_values} pv |
$value = db_result(db_query("SELECT pv.value |
| 253 |
|
FROM {profile_fields} pf, {profile_values} pv |
| 254 |
WHERE pv.fid = pf.fid |
WHERE pv.fid = pf.fid |
| 255 |
AND pf.name = '%s' |
AND pf.name = '%s' |
| 256 |
AND pv.uid = %d", $profile_field['name'], $uid)); |
AND pv.uid = %d", $profile_field['name'], $uid)); |
| 270 |
function _profile_csv_header() { |
function _profile_csv_header() { |
| 271 |
$row = array(); |
$row = array(); |
| 272 |
|
|
| 273 |
if (variable_get(PROFILE_CSV_PARAM .'uid', 0)) |
if (variable_get(PROFILE_CSV_PARAM .'uid', 0)) { |
| 274 |
$row[] = '"uid"'; |
$row[] = '"uid"'; |
| 275 |
|
} |
| 276 |
if (variable_get(PROFILE_CSV_PARAM .'name', 0)) |
if (variable_get(PROFILE_CSV_PARAM .'name', 0)) { |
| 277 |
$row[] = '"name"'; |
$row[] = '"name"'; |
| 278 |
|
} |
| 279 |
if (variable_get(PROFILE_CSV_PARAM .'mail', 0)) |
if (variable_get(PROFILE_CSV_PARAM .'mail', 0)) { |
| 280 |
$row[] = '"mail"'; |
$row[] = '"mail"'; |
| 281 |
|
} |
| 282 |
foreach (_profile_csv_get_profile_fields() as $field) { |
foreach (_profile_csv_get_profile_fields() as $field) { |
| 283 |
$row[] = '"'. $field['title'] .'"'; |
$row[] = '"'. $field['title'] .'"'; |
| 284 |
} |
} |