--- profile_csv.module.cvs	2007-03-24 04:17:12.000000000 +0000
+++ profile_csv.module	2007-04-10 17:37:10.000000000 +0100
@@ -15,9 +15,9 @@
   }
   return $output;
 }
-	
-function profile_csv_settings() {  
- 
+
+function profile_csv_settings() {
+
   $set = 'roles';
   $form[$set] = array(
   '#type' => 'fieldset',
@@ -26,7 +26,7 @@
   '#collapsible' => true,
   '#collapsed' => true,
   );
-  
+
   $u_role = user_roles($membersonly = TRUE);
   foreach ( $u_role as $rid => $name) {
     $role = PROFILE_CSV_ROLE . $rid;
@@ -51,7 +51,7 @@
     '#options' => array( 1 => t('active'), 0 => t('blocked'), 2 => t('both')),
     '#description' => t(''),
   );
-  
+
   $set = 'fields';
     $form[$set] = array(
     '#type' => 'fieldset',
@@ -78,7 +78,19 @@
     '#return_value' => 1,
     '#default_value' => variable_get(PROFILE_CSV_PARAM . 'mail', 0),
   );
-  
+  $form[$set][PROFILE_CSV_PARAM . 'created'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Account Created'),
+    '#return_value' => 1,
+    '#default_value' => variable_get(PROFILE_CSV_PARAM . 'created', 0),
+  );
+  $form[$set][PROFILE_CSV_PARAM . 'access'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Site Last Accessed'),
+    '#return_value' => 1,
+    '#default_value' => variable_get(PROFILE_CSV_PARAM . 'access', 0),
+  );
+
   $set = 'profile';
   $form[$set] = array(
     '#type' => 'fieldset',
@@ -87,11 +99,11 @@
     '#collapsible' => true,
     '#collapsed' => true,
   );
-  
-  $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 FROM {profile_fields} pf ORDER BY pf.category, pf.weight, pf.title");
   while ($row = db_fetch_object($result)) {
     $fld = PROFILE_CSV_PARAM . 'profile_' . $row->fid;
-    
+
     if (!isset($form[$set][$row->category])) {
       $form[$set][$row->category] = array(
         '#type' => 'fieldset',
@@ -99,14 +111,14 @@
         '#collapsible' => true,
       );
     }
-    
+
      $form[$set][$row->category][$fld] = array(
         '#type' => 'checkbox',
         '#title' => $row->title,
         '#return_value' => 1,
         '#default_value' => variable_get($fld, 0),
       );
-  } 
+  }
   return $form;
 }
 
@@ -118,30 +130,27 @@
   $items = array();
   if ($may_cache) {
     $items[] = array(
-      'path'     => 'profile_csv', 
+      'path'     => 'profile_csv',
       'title'    => t('Profile Export CSV'),
       'callback' => 'profile_csv_page',
       'access'   => user_access(PROFILE_CSV_PERM_DOWNLOAD),
       'type'     => MENU_NORMAL_ITEM,
     );
-  }  
+  }
   return $items;
 }
 
 function profile_csv_page() {
-  
   $data = _profile_csv_header();
   $user_status = variable_get(PROFILE_CSV_STATUS,2);
   if (variable_get(PROFILE_CSV_ROLE . '2', 0)) {
     $result = db_query("SELECT u.uid, u.status FROM {users} u  WHERE u.uid > 1");
     while ($row = db_fetch_object($result)) {
       if ($user_status == 2){
-	$data .= _profile_csv_format_user($row->uid );
+				$data .= _profile_csv_format_user($row->uid );
       }
-      else{      
-	if ($user_status == $row->status) {
-	  $data .= _profile_csv_format_user($row->uid );
-	}
+      elseif ($user_status == $row->status) {
+				$data .= _profile_csv_format_user($row->uid );
       }
     }
   }
@@ -149,32 +158,29 @@
     $result = db_query("SELECT u.uid, u.status, ur.rid  FROM {users} u
 	    INNER JOIN {users_roles} ur ON u.uid = ur.uid
 	    WHERE u.uid > 1");
-    $prev_uid = 0;	    
+    $prev_uid = 0;
     while ($row = db_fetch_object($result)) {
       if ((variable_get(PROFILE_CSV_ROLE . $row->rid, 0)) && ($row->uid != $prev_uid)) {
-	if ($user_status == 2){
-	  $data .= _profile_csv_format_user($row->uid );
-	}
-	else{      
-	  if ($user_status == $row->status) {
-	    $data .= _profile_csv_format_user($row->uid );
-	  }
-	}  
+				if ($user_status == 2) {
+					$data .= _profile_csv_format_user($row->uid );
+				} elseif($user_status == $row->status) {
+					$data .= _profile_csv_format_user($row->uid );
+				}
        $prev_uid = $row->uid;
-      } 
-    }    
+      }
+    }
   }
   header("Content-type: text/plain; charset=UTF-8");
   header("Content-Disposition: attachment; filename=userlist.csv");
   header("Pragma: no-cache");
   header("Expires: 0");
   print $data;
-  exit();  
-}  
+  exit();
+}
 
 function _profile_csv_get_profile_fields() {
   static $fields;
-  
+
   if (!isset($fields)) {
     $fields = array();
     $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');
@@ -184,53 +190,65 @@
       }
     }
   }
-  return $fields;  
-}  
+  return $fields;
+}
 
 
-function _profile_csv_format_user($uid = 0) { 
+function _profile_csv_format_user($uid = 0) {
   $user_data = _profile_csv_get_user($uid);
   $profile_data = _profile_csv_get_profile($uid,$user_data['data']);
   unset($user_data['data']);
   $info = array_merge($user_data, $profile_data);
-  //all of the valid fields in ['data'] should have been picked out in _profile_csv_get_profile, so unset it  
-    
+  //all of the valid fields in ['data'] should have been picked out in _profile_csv_get_profile, so unset it
+
   foreach($info as $value) {
     $new_info[] = '"' . str_replace('"', '""', $value) . '"';
   }
-  if (isset($new_info)) { 
+  if (isset($new_info)) {
     $line = implode(",", $new_info);
-  } 
+  }
   $data .= trim($line) . "\n";
-  
+
  return $data;
 }
 
 function _profile_csv_get_user($uid = 0) {
    $users = array();
-   $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, u.created, u.access FROM {users} u WHERE u.uid = %d', $uid);
    while ($row = db_fetch_object($result)) {
-    if (variable_get(PROFILE_CSV_PARAM . 'uid', 0)) 
+    if (variable_get(PROFILE_CSV_PARAM . 'uid', 0)) {
       $users[] = $row->uid;
- 
-    if (variable_get(PROFILE_CSV_PARAM . 'name', 0)) 
+	 }
+
+    if (variable_get(PROFILE_CSV_PARAM . 'name', 0)) {
       $users[] = $row->name;
-    
-    if (variable_get(PROFILE_CSV_PARAM . 'mail', 0)) 
+		}
+
+    if (variable_get(PROFILE_CSV_PARAM . 'mail', 0)) {
       $users[] = $row->mail;
-      $users['data'] = unserialize($row->data);
-  } 
-  return $users;  
-}  
-    
+		}
+
+		if(variable_get(PROFILE_CSV_PARAM . 'created', 0)) {
+			$users[] = format_date($row->created, 'small');
+		}
+
+		if(variable_get(PROFILE_CSV_PARAM . 'access', 0)) {
+			$users[] = format_date($row->access, 'small');
+		}
+
+    $users['data'] = unserialize($row->data);
+  }
+  return $users;
+}
+
 function _profile_csv_get_profile($uid=0,$user_data=NULL) {
-  $profile_fields = _profile_csv_get_profile_fields();  
+  $profile_fields = _profile_csv_get_profile_fields();
   $profile_result = array();
   foreach($profile_fields  as $profile_field) {
     if ($profile_field ['visibility'] == 4) {
       //$value = try to get it from the $user_data
       $value = $user_data[$profile_field['name']];
-    } 
+    }
     else {
       $value = db_result(db_query("SELECT pv.value FROM {profile_fields} pf, {profile_values} pv
 	WHERE pv.fid = pf.fid
@@ -243,7 +261,7 @@
 	$value = unserialize($value);
 	$value = $value['year'] .'-'. $value['month'] .'-'. $value['day'];
       }
-    }  
+    }
     $profile_result[] = $value;
   }
   return $profile_result;
@@ -252,15 +270,21 @@
 function _profile_csv_header() {
   $row = array();
 
-  if (variable_get(PROFILE_CSV_PARAM . 'uid', 0)) 
+  if (variable_get(PROFILE_CSV_PARAM . 'uid', 0))
     $row[] = '"uid"';
 
-  if (variable_get(PROFILE_CSV_PARAM . 'name', 0)) 
+  if (variable_get(PROFILE_CSV_PARAM . 'name', 0))
     $row[] = '"name"';
 
-  if (variable_get(PROFILE_CSV_PARAM . 'mail', 0)) 
+  if (variable_get(PROFILE_CSV_PARAM . 'mail', 0))
     $row[] = '"mail"';
 
+  if (variable_get(PROFILE_CSV_PARAM . 'created', 0))
+    $row[] = '"created"';
+
+  if (variable_get(PROFILE_CSV_PARAM . 'access', 0))
+    $row[] = '"access"';
+
   foreach(_profile_csv_get_profile_fields() as $field) {
     $row[] = '"'. $field['title'] .'"';
   }
