--- profile.module.old	2007-02-11 00:42:00.000000000 -0600
+++ profile.module	2007-03-03 01:00:12.000000000 -0600
@@ -39,6 +39,7 @@
 <li>multi-line textfield</li>
 <li>checkbox</li>
 <li>list selection</li>
+<li>multiselect list</li>
 <li>freeform list</li>
 <li>URL</li>
 <li>date</li>
@@ -103,7 +104,6 @@
 
   if ($op == 'list') {
      $blocks[0]['info'] = t('Author information');
-
      return $blocks;
   }
   else if ($op == 'configure' && $delta == 0) {
@@ -251,7 +251,7 @@
     '#default_value' => $edit['explanation'],
     '#description' => t('An optional explanation to go with the new field. The explanation will be shown to the user.'),
   );
-  if ($type == 'selection') {
+  if ($type == 'selection' || $type == 'multiselect') {
     $form['fields']['options'] = array('#type' => 'textarea',
       '#title' => t('Selection options'),
       '#default_value' => $edit['options'],
@@ -269,7 +269,7 @@
     '#default_value' => isset($edit['visibility']) ? $edit['visibility'] : PROFILE_PUBLIC,
     '#options' => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')),
   );
-  if ($type == 'selection' || $type == 'list' || $type == 'textfield') {
+  if ($type == 'selection' || $type == 'multiselect' || $type == 'list' || $type == 'textfield') {
     $form['fields']['page'] = array('#type' => 'textfield',
       '#title' => t('Page title'),
       '#default_value' => $edit['page'],
@@ -283,6 +283,7 @@
       '#description' => t('To enable browsing this field by value, enter a title for the resulting page. An example page title is "People who are employed". This is only applicable for a public field.'),
     );
   }
+
   $form['fields']['autocomplete'] = array('#type' => 'checkbox',
     '#title' => t('Form will auto-complete while user is typing.'),
     '#default_value' => $edit['autocomplete'],
@@ -456,6 +457,10 @@
         $query = "v.value = '%s'";
         $arguments[] = $value;
         break;
+      case 'multiselect':
+        $query = "v.value LIKE '%%%s%%'";
+        $arguments[] = $value;
+        break;
       case 'list':
         $query = "v.value LIKE '%%%s%%'";
         $arguments[] = $value;
@@ -476,7 +481,7 @@
     }
     $output .= theme('pager', NULL, 20);
 
-    if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
+    if ($field->type == 'selection' || $field->type == 'multiselect' || $field->type == 'list' || $field->type == 'textfield') {
       $title = strtr(check_plain($field->page), array('%value' => theme('placeholder', $value)));
     }
     else {
@@ -530,10 +535,14 @@
     if (_profile_field_serialize($field->type)) {
        $edit[$field->name] = serialize($edit[$field->name]);
     }
+    
+    $value = ($field->type == 'multiselect') ? implode("\n\r",$edit[$field->name]) : $edit[$field->name];
+    
     db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $field->fid, $user->uid);
-    db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]);
+    db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $value);
     // Mark field as handled (prevents saving to user->data).
     $edit[$field->name] = NULL;
+    $value = NULL;
   }
 }
 
@@ -552,6 +561,14 @@
       case 'textfield':
       case 'selection':
         return $browse ? l($value, 'profile/'. $field->name .'/'. $value) : check_plain($value);
+      case 'multiselect':
+        $values = split("[,\n\r]", $value);
+        foreach ($values as $value) {
+          if ($value = trim($value)) {
+            $fields[] = $browse ? l($value, 'profile/'. $field->name .'/'. $value) : check_plain($value);
+          }
+        }
+        return implode(', ', $fields);
       case 'checkbox':
         return $browse ? l($field->title, 'profile/'. $field->name) : check_plain($field->title);
       case 'url':
@@ -613,6 +630,9 @@
   if ($field->type == 'list') {
     $output .= ' '. t('Put each item on a separate line or separate them by commas. No HTML allowed.');
   }
+  else if ($field->type == 'multiselect') {
+    $output .= ' '. t('You can select more then one option.');
+  }
 
   if ($field->visibility == PROFILE_PRIVATE) {
     $output .= ' '. t('The content of this field is kept private and will not be shown publicly.');
@@ -675,6 +695,7 @@
             $options[$line] = $line;
           }
         }
+        
         $fields[$category][$field->name] = array('#type' => 'select',
           '#title' => check_plain($field->title),
           '#default_value' => $edit[$field->name],
@@ -683,6 +704,25 @@
           '#required' => $field->required,
         );
         break;
+      case 'multiselect':
+        $options = array();
+        $lines = split("[,\n\r]", $field->options);
+        foreach ($lines as $line) {
+          if ($line = trim($line)) {
+            $options[$line] = $line;
+          }
+        }
+        $value = split("[,\n\r]", $edit[$field->name]);
+        $fields[$category][$field->name] = array('#type' => 'select',
+          '#title' => check_plain($field->title),
+          '#default_value' => $value,
+          '#options' => $options,
+          '#description' => _profile_form_explanation($field),
+          '#multiple' => TRUE,
+          '#size' => 'size="'. min(12, count($options)) .'"',
+          '#required' => $field->required,
+        );
+        break;
       case 'date':
         $fields[$category][$field->name] = array('#type' => 'date',
           '#title' => check_plain($field->title),
@@ -788,6 +828,7 @@
                  'textarea' => t('multi-line textfield'),
                  'checkbox' => t('checkbox'),
                  'selection' => t('list selection'),
+                 'multiselect' => t('multi-list selection'),
                  'list' => t('freeform list'),
                  'url' => t('URL'),
                  'date' => t('date'));
