Index: profile.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile.module,v
retrieving revision 1.156
diff -u -r1.156 profile.module
--- profile.module	12 May 2006 08:50:22 -0000	1.156
+++ profile.module	15 May 2006 06:47:18 -0000
@@ -243,13 +243,20 @@
     '#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'],
       '#description' => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'),
     );
   }
+  if ($type == 'multiselect') {
+    $form['fields']['multiselect'] = array('#type' => 'checkbox',
+      '#title' => t('enable multiple selections.'),
+      '#default_value' => '1',
+    );
+  }
+
   $form['fields']['weight'] = array('#type' => 'weight',
     '#title' => t('Weight'),
     '#default_value' => $edit['weight'],
@@ -261,7 +268,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 == 'list' || $type == 'textfield' || $type == 'multiselect') {
     $form['fields']['page'] = array('#type' => 'textfield',
       '#title' => t('Page title'),
       '#default_value' => $edit['page'],
@@ -441,11 +448,13 @@
       case 'checkbox':
         $query = 'v.value = 1';
         break;
-      case 'textfield':
       case 'selection':
         $query = "v.value = '%s'";
         $arguments[] = $value;
         break;
+      case 'multiselect':
+        $query = "v.value LIKE '%%". db_escape_string($value) ."%%'";
+        break;
       case 'list':
         $query = "v.value LIKE '%%%s%%'";
         $arguments[] = $value;
@@ -466,7 +475,7 @@
     }
     $output .= theme('pager', NULL, 20);
 
-    if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield') {
+    if ($field->type == 'selection' || $field->type == 'list' || $field->type == 'textfield' || $field->type == 'multiselect') {
       $title = strtr($field->page, array('%value' => theme('placeholder', $value)));
     }
     else {
@@ -550,6 +559,15 @@
         return $browse ? l($value, 'profile/'. $field->name .'/'. $value) : check_plain($value);
       case 'checkbox':
         return $browse ? l($field->title, 'profile/'. $field->name) : check_plain($field->title);
+      case 'multiselect':
+        $values = split("[,\n\r]", $value);
+        $fields = array();
+        foreach ($values as $value) {
+          if ($value = trim($value)) {
+            $fields[] = $browse ? l($value, "profile/". urlencode($field->name) ."/". urlencode($value)) : check_plain($value);
+          }
+        }
+        return implode(', ', $fields);
       case 'url':
         return '<a href="'. check_url($value) .'">'. check_plain($value) .'</a>';
       case 'date':
@@ -668,6 +686,27 @@
           '#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;
+          }
+        }
+
+        $fields[$category][$field->name] = array(
+          '#type' => 'select',
+          '#title' => check_plain($field->title),
+          '#default_value' => $edit[$field->name],
+          '#options' => $options,
+          '#description' => _profile_form_explanation($field),
+          '#extra' => 0,
+          '#multiple' => 1,
+          '#required' => $field->required,
+      );
+      break;
+
       case 'checkbox':
         $fields[$category][$field->name] = array('#type' => 'checkbox',
           '#title' => check_plain($field->title),
@@ -810,6 +849,7 @@
                  'textarea' => t('multi-line textfield'),
                  'checkbox' => t('checkbox'),
                  'selection' => t('list selection'),
+                 'multiselect' => t('multiple selection'),
                  'list' => t('freeform list'),
                  'url' => t('URL'),
                  'date' => t('date'));
@@ -817,7 +857,13 @@
 }
 
 function _profile_field_serialize($type = NULL) {
-  return $type == 'date';
+  switch ($type) {
+    case 'date':
+    case 'multiselect':
+      return TRUE;
+    default:
+      return FALSE;
+  }
 }
 
 /**
