Index: cck_field_privacy/cck_field_privacy.install
===================================================================
--- cck_field_privacy/cck_field_privacy.install	(revision 633)
+++ cck_field_privacy/cck_field_privacy.install	(working copy)
@@ -27,8 +27,9 @@
         'not null' => TRUE,
       ),
       'permission' => array(
-        'description' => t('TODO'),
-        'type' => 'char',
+        'description' => t('Serialized permission values'),
+        'type' => 'text',
+        'serialize' => TRUE,
         'not null' => TRUE,
       ),
     ),
@@ -116,6 +117,16 @@
 }
 
 /**
+ * Patch to update permission field to allow for more than 1
+ * permission (+ integration with UR)
+ */
+function cck_field_privacy_update_6102(){
+  $ret = array();
+  db_change_field($ret, 'cckfp', 'permission', 'permission', array('type' => 'text', 'not null' => TRUE, 'serialize' => TRUE));
+  return $ret;
+}
+
+/**
  * Update the module's weight in the system table
  */
 function _cck_field_privacy_update_weight() {
Index: cck_field_privacy/cck_field_privacy.module
===================================================================
--- cck_field_privacy/cck_field_privacy.module	(revision 633)
+++ cck_field_privacy/cck_field_privacy.module	(working copy)
@@ -115,13 +115,23 @@
       if ($result) {
         //Put all of the permissions entries into an array so we can process them all at once.
         while ($row = db_fetch_object($result)) {
+          $row->permission = unserialize($row->permission);
           $permissions[$row->field_name] = $row;
         }
-        
+		        
         foreach ($permissions as $field_name => $fieldpriv) {
-          //A permission setting exists, so let's handle the permissions            
-          $access_clear = _cck_field_privacy_access_check($fieldpriv, $node, $user, $node_user);
+          //A permission setting exists, so let's handle the permissions
+          foreach($fieldpriv->permission as $priv){
+            $clear = _cck_field_privacy_access_check($priv, $node, $user, $node_user);
+            if($clear){
+              $access_clear = TRUE;
+              break;
+            }else{
+              $access_clear = FALSE;
+            }
+          }
           if ($access_clear == FALSE) {
+            drupal_set_message('yeah');
             $node->$field_name['#access'] = FALSE;
             $node->content[$field_name]['#access'] = FALSE;
           }
@@ -130,9 +140,19 @@
             if (is_array($node->content[$field_name]['group'])) {
               $node_groups = fieldgroup_groups($node->type);
               $group_fields = $node_groups[$field_name]['fields'];
+              
               foreach ($group_fields as $child) {
                 if (array_key_exists($child['field_name'], $permissions)) {
-                  $child_access = _cck_field_privacy_access_check($permissions[$child['field_name']], $node, $user, $node_user);
+                  //print_r($permissions[$child['field_name']]);
+                  foreach($permissions[$child['field_name']]->permission as $child_priv){
+                    $child_clear = _cck_field_privacy_access_check($child_priv, $node, $user, $node_user);	
+                  	if($child_clear){
+              		  $child_access = TRUE;
+              		  break;
+            		}else{
+              		  $child_access = FALSE;
+            		}
+                  }
                   if ($child_access == FALSE) {
                     //$node->$field_name[$child['field_name']]['#access'] = FALSE;
                     $node->content[$field_name]['group'][$child['field_name']]['field']['#access'] = FALSE;
@@ -162,19 +182,20 @@
  */
 function _cck_field_privacy_access_check($permission, $node, $user, $node_user) {
   $access_clear = TRUE;
-  if ($permission->permission == 'b') {
-    foreach (module_invoke_all('cck_field_privacy_access', $node_user, $user) as $access_result ) {
-      if (!$access_result) {   
+  
+  if ($permission == 'everyone') {
+  }
+  else if ($permission == 'nobody') {
+    $access_clear = FALSE;
+  }else{
+  	foreach (module_invoke_all('cck_field_privacy_access', $node_user, $user, $permission) as $access_result ) {
+      if (!$access_result) {     
         $access_clear=FALSE;
       }
       continue; 
     }
   }
-  if ($permission->permission == 'e') {
-  }
-  if ($permission->permission == 'n') {
-    $access_clear = FALSE;
-  }
+  
   return $access_clear;
 }
 
@@ -213,12 +234,20 @@
 
             // Get the current state of the field and set perms that will be used with jQ impromptu
             $field_pref_sql = db_query("SELECT permission FROM {cckfp} WHERE uid = %d AND type_name = '%s' AND field_name = '%s'", $u, $node_type, $field);
-            $field_pref = (string) db_result($field_pref_sql);
+            $field_pref = unserialize((string)db_result($field_pref_sql));
+            
             if ($field_pref == "") {
-              $field_pref = variable_get('cckfp_'. $node_type .'_default', 'e'); // Set to the default state of the field
+              $pref = variable_get('cckfp_'. $node_type .'_default', 'everyone'); // Set to the default state of the field
+              $prefs[$pref] = $pref;
+            }else{
+              
+              foreach($field_pref as $pref){
+              	$prefs[$pref] = $pref;
+              }
             }
-            $privacyfields[$field] = $field_pref;
             
+            $privacyfields[$field] = $prefs;
+            
             switch ($fieldtypes[$field]['widget']['type']) {
 
               // treats special cases separately :
@@ -254,6 +283,9 @@
             _cck_field_privacy_add_padlock($form, $needpadlock);
           }
 
+          //retrieve the types of relationships available
+	      $rels = variable_get('cckfp_rel_type_options', 'everyone');
+          
           // include javascript and css only if needed
           jquery_impromptu_add();
           drupal_add_js(drupal_get_path('module', 'cck_field_privacy') .'/cck_field_privacy.js');
@@ -262,6 +294,7 @@
               'action' => url('cck_field_privacy/ajax'),
               'uid' => $u,
               'content_type' => $node_type,
+              'relationships' => $rels,
               'default_value' => $privacyfields,
               ),
             ), 'setting');
@@ -357,15 +390,28 @@
   global $user;
 
   if (user_access('modify cck field privacy') || (user_access('modify own cck field privacy') && $user->uid == $_POST['user'])) {
-    if (isset($_POST['user'], $_POST['field'], $_POST['type'], $_POST['setting'])) {
-      $userinfo = array();
-      $userinfo['uid'] = $_POST['user'];
+    if (isset($_POST['user'], $_POST['field'], $_POST['type'], $_POST['settings'])) {
+      $uid = $_POST['user'];
       $field = $_POST['field'];
       $type = $_POST['type'];
-      $setting = $_POST['setting'];
-      if ($userinfo != 'NULL' && $field != 'NULL' && $type != 'NULL' && $setting != 'NULL') {
-        $sql = "INSERT INTO {cckfp} (uid, field_name, type_name, permission) VALUES(%d, '%s', '%s', '%s') ON DUPLICATE KEY UPDATE uid=%d, field_name='%s', type_name='%s', permission='%s'";
-        $result = db_query($sql, $userinfo['uid'], $field, $type, $setting, $userinfo['uid'], $field, $type, $setting);
+      $settings = $_POST['settings'];
+             
+      if ($uid != 'NULL' && $field != 'NULL' && $type != 'NULL' && $settings != 'NULL') {
+        $cckfp = array(
+		  'uid' => $uid,
+		  'field_name' => $field,
+		  'type_name' => $type,
+		  'permission' => $settings,         
+        );
+        
+        $select = "SELECT * FROM {cckfp} WHERE uid = %d AND field_name = '%s'";
+        $result = db_fetch_object(db_query($select, $uid, $field));
+    	if($result){
+          drupal_write_record('cckfp', $cckfp, array('uid', 'field_name', 'type_name'));
+    	}else{
+    	  drupal_write_record('cckfp', $cckfp);	
+    	}	
+      
         if (!db_error()) {
         } 
         else {
@@ -442,12 +488,33 @@
             );
           }
           
+          $options = array(
+            'everyone' => t('everyone'),
+            'buddies' => t('buddies'),
+			'nobody' => t('nobody')
+          );
+          //if user relationship module exists grab the 
+          //relationship types
+          if(module_exists('user_relationships_api')){
+            module_load_include('inc', 'user_relationships_api', 'user_relationships_api.api');
+            $ur_types = user_relationships_types_load();
+            
+            //build options array for form.
+            foreach($ur_types as $rel){
+              $options[$rel->plural_name] = $rel->plural_name;
+            }
+            unset($options['buddies']);    
+          }
+          
+          //set what options are so we can retrieve them later in the modal dialog
+          variable_set('cckfp_rel_type_options', $options);
+          
           $form['field_fields'][$enabled_type]['cckfp_' . $enabled_type . '_default'] = array(
             '#type' => 'radios',
             '#title' => t('Default Value'),
             '#description' => t('You may choose a default privacy value for the fields in this content type.'),
-            '#default_value' => variable_get('cckfp_' . $enabled_type . '_default', 'e'),
-            '#options' => array('e' => t('Everyone'), 'b' => t('Buddies'), 'n' => t('Nobody')),
+            '#default_value' => variable_get('cckfp_' . $enabled_type . '_default', 'everyone'),
+            '#options' => $options,
             '#weight' => 1,
           );
         }
@@ -566,20 +633,22 @@
     $result = db_query("SELECT field_name, permission FROM {cckfp} WHERE uid = %d AND type_name = '%s' ORDER BY field_name DESC", $node->uid, $node->type);
     
     if ($result) {
-      while ($permissions = db_fetch_object($result)) {
-        if ($permissions->permission == 'e') {
-          continue;
-        } 
-        else if ($permissions->permission == 'n') {
-          $inaccessible_fields[$permissions->field_name] = $permissions->field_name;
-        } 
-        else if (!empty($permissions->permission)) {
-          $node_user = user_load(array('uid' => $node->uid));
-          $plugin_access_result = module_invoke($permissions->permission, 'cck_field_privacy_access', $node_user, $user);
-          //Uncomment the next line to enable debug output to the watchdog when testing views access
-          //watchdog('cckfp', 'result of module '.$permissions->permission.' check: '.print_r($plugin_access_result, TRUE));
-          if ($plugin_access_result === FALSE) {
+      while ($permissions = db_fetch_object($result)) {        
+        foreach($permissions->permission as $perm){
+          if ($perm == 'everyone') {
+            continue;
+          } 
+          else if ($perm == 'nobody') {
             $inaccessible_fields[$permissions->field_name] = $permissions->field_name;
+          } 
+          else if (!empty($perm)) {
+            $node_user = user_load(array('uid' => $node->uid));
+            $plugin_access_result = module_invoke($perm, 'cck_field_privacy_access', $node_user, $user);
+            //Uncomment the next line to enable debug output to the watchdog when testing views access
+            //watchdog('cckfp', 'result of module '.$permissions->permission.' check: '.print_r($plugin_access_result, TRUE));
+            if ($plugin_access_result === FALSE) {
+              $inaccessible_fields[$permissions->field_name] = $permissions->field_name;
+            }
           }
         }
       }
Index: cck_field_privacy/cck_field_privacy.js
===================================================================
--- cck_field_privacy/cck_field_privacy.js	(revision 633)
+++ cck_field_privacy/cck_field_privacy.js	(working copy)
@@ -1,5 +1,6 @@
 var cck_field_privacy = {
   init: function() {
+    console.log('init called');
     if (typeof(Drupal) == 'undefined' || typeof(Drupal.settings) == 'undefined') return; // abort
 
     for (field_name in Drupal.settings.cck_field_privacy.default_value) {
@@ -9,49 +10,74 @@
 
   click: function() {
     var field_name = $(this).attr('id').substr(0, $(this).attr('id').length-4),
-        field_state = Drupal.settings.cck_field_privacy.default_value[field_name];
+        field_states = Drupal.settings.cck_field_privacy.default_value[field_name];
 
+	var rels = Drupal.settings.cck_field_privacy.relationships;
+	var checkboxes = '';
+	for(var rel in rels){
+    	checkboxes += "<div><label><input type='checkbox' value='"+rels[rel]+"' name='"+rels[rel]+"' />"+rels[rel]+"</label></div>";
+    }
+	
     // display prompt
     var prompt = $.prompt(
       // @TODO: Output the list of privacy options in Drupal.settings.
       // @TODO: Make Buddies conditional based on module_exists('buddylist').
       //        then remove as a dependency.
-      // @TODO: Provide all available relationships when module_exists('user_relationships').
       '<p><strong>Privacy Settings</strong></p>'+
-      '<form>'+
-      '  <div><label><input type="radio" value="e" name="privacy" /> Everyone</label></div>'+
-      '  <div><label><input type="radio" value="b" name="privacy" /> Buddies</label></div>'+
-      '  <div><label><input type="radio" value="n" name="privacy" /> Nobody</label></div>'+
+      '<form>'+checkboxes+
       '</form>', {
 
       overlayspeed: 'fast',
       promptspeed: 'fast',
+      buttons: { Ok: true, Cancel: false },
+      submit: function(v, m, f){
+      	if(v == true){
+      		var settings = new Array();
+        	$.each(f, function(){
+        		settings.push(this);
+        	});
+      		// remember setting
+      		Drupal.settings.cck_field_privacy.default_value[field_name] = f; 
+          	$.post( // save changes
+            	Drupal.settings.cck_field_privacy.action, {
+            	user: Drupal.settings.cck_field_privacy.uid,
+            	field: field_name,
+            	type: Drupal.settings.cck_field_privacy.content_type,
+            	'settings[]': settings
+          	});
+           	
+      	   	return true;
+      	}
+      	return true;
+      },
       show: 'slideDown',
-      loaded: (function(field_name) { return function() {
-        $("input[@type='radio']", this).each(function() {
-          // set default radio checked on load
-          var e = $(this);
-          e.attr('checked', field_state == e.val()? 'checked' : '');
-        }).change((function(field_name) { return function() {
-          // save changes
-          var radio = $(this),
-              form = radio.parents('form'),
-              prompt = form.parents('div.jqicontainer');
-
-          Drupal.settings.cck_field_privacy.default_value[field_name] = radio.val(); // remember setting
-          $('#jqibuttonOk', prompt).trigger('click'); // automatically close prompt
-          $.post( // save changes
-            Drupal.settings.cck_field_privacy.action, {
-            user: Drupal.settings.cck_field_privacy.uid,
-            field: field_name,
-            type: Drupal.settings.cck_field_privacy.content_type,
-            setting: radio.val()
-          });
-        };})(field_name))
-      };})(field_name)
-    });
-  return false;
+      loaded: (function(field_name) { 
+      	return function() {
+        	$("input[@type='checkbox']", this).each(function() {
+          		// set default checked on load
+          		var e = $(this);          
+          		e.attr('checked', field_states[e.val()] == e.val()? 'checked' : '');
+        	}).change(function(field_name) { 
+        		var name = $(this).attr('name');
+        		if(name == 'everyone' || name == 'nobody'){        		
+        		  if ($(this).is(':checked')) {
+  					// Uncheck all other checkboxes.
+  					$("input[@name!='"+$(this).attr('name')+"']").each(function(){
+  						$(this).attr('checked',false);
+  					});
+				  }
+				}//uncheck 'everyone' , 'nobody'
+				else{
+				  $("input[@name='everyone'], input[@name='nobody']").attr('checked',false);
+				}
+        	});
+		};
+	  }(field_name))
+	});
+	return false;
   }
 };
 
-$(cck_field_privacy.init); // onload
\ No newline at end of file
+Drupal.behaviors.cck_field_privacy = function(context){
+	cck_field_privacy.init();
+}
