Index: js/uc_multiprice.js
===================================================================
--- js/uc_multiprice.js	(revision 29)
+++ js/uc_multiprice.js	(working copy)
@@ -1,4 +1,4 @@
-$(document).ready( function() {
-	// unbind any functions and submit form onchange													
-	$('#edit-panes-delivery-delivery-country').unbind('change').trigger('change').change( function(){$('#uc-cart-checkout-form').submit();});
+$(document).ready( function() {
+	// unbind any functions and submit form onchange													
+	$('#edit-panes-delivery-delivery-country').unbind('change').trigger('change').change( function(){$('#uc-cart-checkout-form').submit();});
 });
\ No newline at end of file
Index: uc_multiprice.admin.inc
===================================================================
--- uc_multiprice.admin.inc	(revision 29)
+++ uc_multiprice.admin.inc	(working copy)
@@ -2,15 +2,22 @@
 // $Id: uc_multiprice.admin.inc,v 1.2.2.2 2010/10/22 09:39:38 docc Exp $
 
 /**
- * @file Provides Admin Settings 
-*/
+ * @file
+ * Provides Multiprice Admin options
+ *
+ * Module developed by Docc | Optixdesigns.nl
+ * @author Docc 
+ * Module extended by Bartezz | Intrige.nl
+ * @author Bartezz <bartezz@gmail.com>
+ *
+ */
 
 function uc_multiprice_admin_default($form) {
   $form = array();
 
-  $countries = variable_get('uc_multiprice_default', array());
+  $multiprices = variable_get('uc_multiprice_default', array());
 
-  $form += uc_multiprice_form($countries, TRUE);
+  $form += uc_multiprice_form($multiprices, TRUE);
   $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
   $form['#pre_render'][] = 'uc_multiprice_add_js';
   
@@ -18,16 +25,83 @@
 }
 
 function uc_multiprice_admin_default_submit($form, &$form_state) {
-  foreach($form_state['values']['multiprice']['countries'] as $key => $country) {
-    if(!$country['delete']) {
-      $countries[$key] = new stdClass();
-      $countries[$key]->country_name  = $country['country'];
-      $countries[$key]->country_id     = $country['country_id'];
-      $countries[$key]->list_price     = $country['list_price'];
-      $countries[$key]->cost           = $country['cost'];
-      $countries[$key]->sell_price     = $country['sell_price'];
-      $countries[$key]->data = $country['dynamic'];
+  foreach ((array)$form_state['values']['multiprice']['multiprices']['country'] as $country_id => $country) {
+    if (!$country['delete']) {
+      $multiprice['country'][$country_id] = new stdClass();
+      $multiprice['country'][$country_id]->country_name  = $country['title'];
+      $multiprice['country'][$country_id]->country_id     = $country['country_id'];
+      $multiprice['country'][$country_id]->list_price     = $country['list_price'];
+      $multiprice['country'][$country_id]->cost           = $country['cost'];
+      $multiprice['country'][$country_id]->sell_price     = $country['sell_price'];
+      $multiprice['country'][$country_id]->data = $country['dynamic'];
     }
   }
-  variable_set('uc_multiprice_default', $countries);
+  foreach ((array)$form_state['values']['multiprice']['multiprices']['role'] as $role_id => $role) {
+    if (!$role['delete']) {
+      $multiprice['role'][$role_id] = new stdClass();
+      $multiprice['role'][$role_id]->role_name  = $role['title'];
+      $multiprice['role'][$role_id]->role_id     = $role['role_id'];
+      $multiprice['role'][$role_id]->list_price     = $role['list_price'];
+      $multiprice['role'][$role_id]->cost           = $role['cost'];
+      $multiprice['role'][$role_id]->sell_price     = $role['sell_price'];
+      $multiprice['role'][$role_id]->data = $role['dynamic'];
+    }
+  }
+  variable_set('uc_multiprice_default', $multiprice);
 }
+
+/**
+ *  Function to generate the form
+ */
+function uc_multiprice_admin_roles() {
+  if (!user_access('administer multiprice roles', $account)) {
+    return FALSE;
+  }
+  
+  $form = array();
+  
+  $form['uc_multiprice_admin_roles'] = array(
+    '#type'       => 'fieldset',
+    '#title'       => t('Multiprice enabled roles'),
+    '#collapsible'    => TRUE, 
+    '#collapsed'    => FALSE,
+    '#description'     => t('Please select the roles for which you want to set multiprices. The roles are shown ordered by weight.')
+  );
+  if (module_exists('role_weights')) {
+    $user_roles = user_roles();
+    if (variable_get('role_weights_reorder_forms', FALSE)) {
+      uksort($user_roles, '_role_weights_rid_compare');
+    }
+      $form['uc_multiprice_admin_roles']['uc_multiprice_roles'] = array(
+        '#type'  => 'checkboxes',
+        '#title'       => t('Roles'),
+        '#default_value' => variable_get('uc_multiprice_roles', array()),
+        '#options' => $user_roles,
+      );
+  }
+  else {
+    $form['uc_multiprice_admin_roles']['#description'] = t('Please install, enable and configure the <a href="@roleweight" target="_blank">Role Weight module</a>.', array('@roleweight' => url('http://drupal.org/project/role_weights')));
+  }
+    
+  return system_settings_form($form);
+}
+
+/**
+ * Implementation of hook_help().
+ */
+function uc_multiprice_help($path, $arg) {
+  global $user;
+
+  switch ($path) {
+    case 'admin/store/settings/multiprice':
+      return t('<p>Use this form to set default prices per country or role for new nodes.</p><p>Multiprice defaults will not change prices to the defaults set for a country or role in this form for existing nodes or nodes that are being edited.</p>');
+    case 'admin/store/settings/multiprice/roles':
+      return t('<p>Multiprice roles allows you to set different prices on a per role basis. Because a user can be assigned multiple roles and since roles are sorted alphabetically in core you will have to set a role weight via <a href="@roleweight" target="_blank">Role Weights module</a>. The lower the numeric weight the more priority the role will have.</p>
+               <ul>
+                 <lh><strong>Please note:</strong></lh>
+                <li>Role pricing overrides per country pricing</li>
+                <li>When a user has multiple roles the prices set for the role with the lowest weight will be used</li>
+                <li>Make sure you have set different weights for different roles in <a href="@rolewadmin">role weight settings</a></li>
+               </ul>', array('@roleweight' => url('http://drupal.org/project/role_weights'), '@rolewadmin' => url('admin/settings/role_weights')));
+  }
+}
\ No newline at end of file
Index: uc_multiprice.info
===================================================================
--- uc_multiprice.info	(revision 29)
+++ uc_multiprice.info	(working copy)
@@ -1,12 +1,12 @@
-; $Id: uc_multiprice.info,v 1.5 2009/06/09 07:54:15 docc Exp $
-name = Multiprice
-description = Allows price overide on a country level
-package = "Ubercart - extra"
-dependencies[] = uc_product
-core = 6.x
-; Information added by drupal.org packaging script on 2010-10-22
-version = "6.x-2.x-dev"
-core = "6.x"
-project = "uc_multiprice"
-datestamp = "1287750237"
-
+; $Id: uc_multiprice.info,v 1.5 2009/06/09 07:54:15 docc Exp $
+name = Multiprice
+description = Allows price overide on a country level
+package = "Ubercart - extra"
+dependencies[] = uc_product
+core = 6.x
+; Information added by drupal.org packaging script on 2010-10-17
+version = "6.x-2.x-dev"
+core = "6.x"
+project = "uc_multiprice"
+datestamp = "1287275090"
+
Index: uc_multiprice.install
===================================================================
--- uc_multiprice.install	(revision 29)
+++ uc_multiprice.install	(working copy)
@@ -191,4 +191,15 @@
         'size' => 'big',
       ));
   return $ret;
+}
+
+function uc_multiprice_update_6003() {
+  $ret = array();
+  db_add_field($ret, 'uc_multiprice', 'role_id', array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ));
+  return $ret;
 }
\ No newline at end of file
Index: uc_multiprice.module
===================================================================
--- uc_multiprice.module	(revision 29)
+++ uc_multiprice.module	(working copy)
@@ -2,12 +2,18 @@
 // $Id: uc_multiprice.module,v 1.19.2.6 2010/10/22 09:39:38 docc Exp $
 
 /**
- * @file Provides Multiprice options
+ * Provides Multiprice options
+ *
+ * Module developed by Docc | Optixdesigns.nl
+ * @author Docc 
+ * Module extended by Bartezz | Intrige.nl
+ * @author Bartezz <bartezz@gmail.com>
+ *
  */
 
-/*******************************************************************************
+/**
  * Hook Functions (Drupal)
- ******************************************************************************/
+ */
 
 /**
  * Implementation of hook_init().
@@ -30,14 +36,30 @@
     'access arguments' => array('administer multiprice'),
     'type' => MENU_CALLBACK,
   );
-  $items['admin/store/settings/multiprice'] = array(
-    'title' => 'Multiprice Defaults',
+	$items['admin/store/settings/multiprice'] = array(
+    'title' => 'Multiprice',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('uc_multiprice_admin_default'),
     'access arguments' => array('administer multiprice'),
     'type' => MENU_NORMAL_ITEM,
     'file' => 'uc_multiprice.admin.inc',
   );
+  $items['admin/store/settings/multiprice/defaults'] = array(
+    'title' => 'Multiprice Defaults',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('uc_multiprice_admin_default'),
+    'access arguments' => array('administer multiprice'),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'file' => 'uc_multiprice.admin.inc',
+  );
+  $items['admin/store/settings/multiprice/roles'] = array(
+    'title' => 'Multiprice Roles',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('uc_multiprice_admin_roles'),
+    'access arguments' => array('administer multiprice roles'),
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'uc_multiprice.admin.inc',
+  );
 
   return $items;
 }
@@ -46,7 +68,7 @@
  * Implementation of hook_perm().
  */
 function uc_multiprice_perm() {
-  return array('administer multiprice', 'create & edit multiprices');
+  return array('administer multiprice', 'create & edit multiprices', 'administer multiprice roles');
 }
 
 /**
@@ -67,8 +89,8 @@
   if (uc_product_is_product_form($form) && $form['type']['#value'] != "product_kit") {
     if (user_access('create & edit multiprices')) {
       // add multiprice form
-      $countries = $form['#node']->multiprice;
-      $form += uc_multiprice_form($countries);
+      $multiprices = $form['#node']->multiprice;
+      $form += uc_multiprice_form($multiprices, $form['#node']->nid);
       $form['#pre_render'][] = 'uc_multiprice_add_js';
       
       // take over the pricing
@@ -77,9 +99,9 @@
       $default->list_price  = $form['base']['prices']['list_price']['#default_value'];
       $default->country_id  = 0;
       $default->country_name  = 'Default';
-      $form['multiprice']['countries'][$default->country_id] = uc_multiprice_field_element($default);
-      $form['multiprice']['countries'][$default->country_id]['#weight'] = -1;
-      unset($form['base']['prices']);
+      $form['multiprice']['multiprices'][$default->country_id] = uc_multiprice_field_element($default);
+      $form['multiprice']['multiprices'][$default->country_id]['#weight'] = -1;
+      unset($form['base']['prices']); 
     }
   }
   
@@ -99,7 +121,7 @@
  */
 function uc_multiprice_checkout_validate($form, &$form_state) {
   $delivery_country = check_plain($form_state['values']['panes']['delivery']['delivery_country']);
-  if($delivery_country != uc_multiprice_country_id()) {
+  if ($delivery_country != uc_multiprice_country_id()) {
     uc_multiprice_country_id($delivery_country);
     $_SESSION['messages'] = array();
     drupal_goto('cart/checkout');
@@ -207,68 +229,107 @@
     switch ($op) {
       case 'prepare';
         // New product? add defaults
-        if(!$node->nid && !$node->multiprice && !$node->translation_source ) {
+        if (!$node->nid && !$node->multiprice && !$node->translation_source ) {
           $node->multiprice = variable_get('uc_multiprice_default', array());
-        }elseif(!$node->nid && !$node->multiprice && $node->translation_source ) {
+        }
+        elseif (!$node->nid && !$node->multiprice && $node->translation_source ) {
           $node->multiprice = $node->translation_source->multiprice;
         }
       break;  
       case 'load':  
+        // load enabled roles
+        $enabled_roles = array_filter(variable_get('uc_multiprice_roles', array()));
+        $all_roles = user_roles();
+        foreach ($enabled_roles as $k => $v) {
+          $roles[$k] = $all_roles[$k];
+        }
+        
         // load uc_countries
         $result = db_query("SELECT country_id, country_name FROM {uc_countries} WHERE version > 0 ORDER BY country_name ASC");
         while ($country = db_fetch_object($result)) {
           $countries[$country->country_id] = $country->country_name;
         }
-        
-        // Add to node object
+
+        // Add to node object{
         $result = db_query("SELECT * FROM {uc_multiprice} WHERE nid = %d", $node->nid);  
         while ($row = db_fetch_object($result)) {
-          $row->data = unserialize($row->data);
-          $row->country_name = $countries[$row->country_id];	  
-		  $row->sell_price = uc_store_format_price_field_value($row->sell_price);
-		  $row->list_price = uc_store_format_price_field_value($row->list_price);
-		  $row->cost = uc_store_format_price_field_value($row->cost);
-          $node->multiprice[$row->country_id] = $row;
+          $row->data = unserialize($row->data);  
+          $row->sell_price = uc_store_format_price_field_value($row->sell_price);
+          $row->list_price = uc_store_format_price_field_value($row->list_price);
+          $row->cost = uc_store_format_price_field_value($row->cost);
+          if ($row->country_id) {
+            $row->country_name = $countries[$row->country_id] ? $countries[$row->country_id] : (module_exists('countries_api') ? countries_api_get_country($row->country_id) : $row->country_id) . ' - ' . t('disabled');
+            $node->multiprice['country'][$row->country_id] = $row;
+          }
+          else {
+            $row->role_name = $roles[$row->role_id] ? $roles[$row->role_id] : $all_roles[$row->role_id] . ' - ' . t('disabled');
+            $node->multiprice['role'][$row->role_id] = $row;
+          }
         }
-        
+
         // Replace product price with multiprice if it's not node form.
         // @todo: how about revisions?
         if ((arg(2) != 'edit') && (arg(2) != 'add') && (arg(2) != 'clone') && (arg(2) != 'convert')) {
+          
+          // set the price according to country id, if the country id is still enabled
           $cid = uc_multiprice_country_id();
-          if ($node->multiprice[$cid]) {
-              $node->sell_price = check_plain($node->multiprice[$cid]->sell_price);
-              $node->list_price = check_plain($node->multiprice[$cid]->list_price);
-              $node->cost       = check_plain($node->multiprice[$cid]->cost);
+          if ($node->multiprice['country'][$cid] && in_array($cid, array_keys($countries))) {
+              $node->sell_price = check_plain($node->multiprice['country'][$cid]->sell_price);
+              $node->list_price = check_plain($node->multiprice['country'][$cid]->list_price);
+              $node->cost       = check_plain($node->multiprice['country'][$cid]->cost);
           }
+          
+          // get the current user's role
+          global $user;
+          $user_roles = $user->roles;
+          // sort the user's roles by weight
+          if (variable_get('role_weights_reorder_forms', FALSE)) {
+            uksort($user_roles, '_role_weights_rid_compare');
+          }
+          foreach (array_keys($user_roles) as $k => $v) {
+            // loop thru each role id
+            if ($node->multiprice['role'][$v] && in_array($v, $enabled_roles)) {
+              // if there is a price set for this role then output it, if the role still is enabled
+              $node->sell_price = check_plain($node->multiprice['role'][$v]->sell_price);
+              $node->list_price = check_plain($node->multiprice['role'][$v]->list_price);
+              $node->cost       = check_plain($node->multiprice['role'][$v]->cost);
+              // and break if we output a price, since it's by role weight
+              break;
+            }
+          }
         }
       break;
       case 'presave';
         // reset the default pricing 
         // only if we have values to reset it with
-        if($node->multiprice['countries'][0]) {
-          $node->sell_price = check_plain($node->multiprice['countries'][0]['sell_price']);
-          $node->list_price = check_plain($node->multiprice['countries'][0]['list_price']);
-          $node->cost       = check_plain($node->multiprice['countries'][0]['cost']);
-          unset($node->multiprice['countries'][0]);
+        if ($node->multiprice['multiprices'][0]) {
+          $node->sell_price = check_plain($node->multiprice['multiprices'][0]['sell_price']);
+          $node->list_price = check_plain($node->multiprice['multiprices'][0]['list_price']);
+          $node->cost       = check_plain($node->multiprice['multiprices'][0]['cost']);
+          unset($node->multiprice['multiprices'][0]);
         }
       break;
       case 'insert':
       case 'update':
-        if (count($node->multiprice['countries']) == 0)
+        if (count($node->multiprice['multiprices']) == 0)
           break;
-       
         db_query("DELETE FROM {uc_multiprice} WHERE nid = %d", $node->nid);
-        unset($node->multiprice['countries'][0]);
- 
-        foreach ($node->multiprice['countries'] as $country_id => $country) {
+        unset($node->multiprice['multiprices'][0]);
+        foreach ((array)$node->multiprice['multiprices']['country'] as $country_id => $country) {
           if (empty($country->delete)) {
-            db_query("INSERT INTO {uc_multiprice} (nid, country_id, list_price, cost, sell_price, data) VALUES (%d, %d, %f, %f, %f, '%s')",
-              $node->nid, $country_id, $country['list_price'], $country['cost'], $country['sell_price'], serialize($country['dynamic']));
+            db_query("INSERT INTO {uc_multiprice} (nid, country_id, list_price, cost, sell_price, data, role_id) VALUES (%d, %d, %f, %f, %f, '%s', %d)",
+              $node->nid, $country['country_id'], $country['list_price'], $country['cost'], $country['sell_price'], serialize($country['dynamic']), $country['role_id']);
           }
         }
+        foreach ((array)$node->multiprice['multiprices']['role'] as $role_id => $role) {
+          if (empty($role->delete)) {
+            db_query("INSERT INTO {uc_multiprice} (nid, country_id, list_price, cost, sell_price, data, role_id) VALUES (%d, %d, %f, %f, %f, '%s', %d)",
+              $node->nid, $role['country_id'], $role['list_price'], $role['cost'], $role['sell_price'], serialize($role['dynamic']), $role['role_id']);
+          }
+        }
       break;
       case 'delete':
-	    db_query("DELETE FROM {uc_multiprice} WHERE nid = %d", $node->nid);
+      db_query("DELETE FROM {uc_multiprice} WHERE nid = %d", $node->nid);
       break;
     }
   }
@@ -302,13 +363,13 @@
   }
 }
 
-/*******************************************************************************
+/**
  * Hook Functions (Ubercart)
- ******************************************************************************/
+ */
 
 /**
-* Implementation of hook_cart_pane().
-*/
+ * Implementation of hook_cart_pane().
+ */
 function uc_multiprice_cart_pane($items) {
   $panes[] = array(
     'id' => 'multiprice_country_cart_form',
@@ -321,8 +382,8 @@
 }
   
 /**
-* Implementation of hook_order().
-*/
+ * Implementation of hook_order().
+ */
 function uc_multiprice_order($op, &$arg1, $arg2) {
   switch ($op) {
     case 'save':
@@ -349,29 +410,29 @@
     $options = $currency + $options;
     unset($options['deci']);
   }
-
-  if($context['type'] == 'product') {
+  if ($context['type'] == 'product') {
     $price['price'] = 0;
     $node = $context['subject']['node'];
     $node = node_load($node->nid);
 
-    if($node->type == "product_kit") { // Product kit
-      foreach($node->products as $product) {
+    if ($node->type == "product_kit") { // Product kit
+      foreach ($node->products as $product) {
         $field = ($context['field']) ? $product->$context['field'] : $product->sell_price; // check if its there
         $price['price'] += $field + $product->discount;
       }
-    }else{
+    }
+    else{
       $field = ($context['field']) ? $node->$context['field'] : $node->sell_price; // check if its there
       $price['price'] = $field;
     }
   }
 }
 
-/*******************************************************************************
+/**
  * Helpers and Callbacks
- ******************************************************************************/
+ */
 
-function uc_multiprice_form($countries, $default = NULL) {
+function uc_multiprice_form($multiprices, $default = NULL) {
   $form['multiprice'] = array(
     '#type' => 'fieldset',
     '#title' => t('Pricing'),
@@ -380,7 +441,7 @@
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
   );
-  $form['multiprice']['countries'] = array(
+  $form['multiprice']['multiprices'] = array(
     '#type' => 'fieldset',
     '#tree' => TRUE,
     '#weight' => 0,
@@ -390,34 +451,54 @@
     '#suffix' => '</div>',
     '#theme' => (module_exists('uc_multiprice_dynamic')) ? 'uc_multiprice_dynamic_form' : 'uc_multiprice_form',
   );
-  
   $exist = array();
-  if(count($countries)!=0) {
-    foreach($countries as $country) {
+  if (count($multiprices)!=0) {
+    foreach ((array)$multiprices['country'] as $country) {
       if (module_exists('uc_multiprice_dynamic')) {
-        $form['multiprice']['countries'][$country->country_id] = uc_multiprice_dynamic_field_element($country);
-        $form['multiprice']['countries'][$country->country_id]['dynamic']['list_price'] = uc_multiprice_dynamic_element($country, 'list_price');
-        $form['multiprice']['countries'][$country->country_id]['dynamic']['cost']       = uc_multiprice_dynamic_element($country, 'cost');
-        $form['multiprice']['countries'][$country->country_id]['dynamic']['sell_price'] = uc_multiprice_dynamic_element($country, 'sell_price');
-      }else{
-        $form['multiprice']['countries'][$country->country_id] = uc_multiprice_field_element($country);
+        $form['multiprice']['multiprices']['country'][$country->country_id] = uc_multiprice_dynamic_field_element($country);
+        $form['multiprice']['multiprices']['country'][$country->country_id]['dynamic']['list_price'] = uc_multiprice_dynamic_element($country, 'list_price');
+        $form['multiprice']['multiprices']['country'][$country->country_id]['dynamic']['cost']       = uc_multiprice_dynamic_element($country, 'cost');
+        $form['multiprice']['multiprices']['country'][$country->country_id]['dynamic']['sell_price'] = uc_multiprice_dynamic_element($country, 'sell_price');
       }
+      else{
+        $form['multiprice']['multiprices']['country'][$country->country_id] = uc_multiprice_field_element($country);
+      }
       $exist[] = $country->country_id;
     }
+    foreach ((array)$multiprices['role'] as $role) {
+      if (module_exists('uc_multiprice_dynamic')) {
+        $form['multiprice']['multiprices']['role'][$role->role_id] = uc_multiprice_dynamic_field_element($role);
+        $form['multiprice']['multiprices']['role'][$role->role_id]['dynamic']['list_price'] = uc_multiprice_dynamic_element($role, 'list_price');
+        $form['multiprice']['multiprices']['role'][$role->role_id]['dynamic']['cost']       = uc_multiprice_dynamic_element($role, 'cost');
+        $form['multiprice']['multiprices']['role'][$role->role_id]['dynamic']['sell_price'] = uc_multiprice_dynamic_element($role, 'sell_price');
+      }
+      else{
+        $form['multiprice']['multiprices']['role'][$role->role_id] = uc_multiprice_field_element($role);
+      }
+      $exist[] = $role->role_id;
+    }
   }
+  // build country dropdown
+  $multiprices = array();
+  $multiprices[0] = 'Select country or role';
+  // load enabled profiles
+  $enabled_roles = array_filter(variable_get('uc_multiprice_roles', array()));
+  $roles = user_roles();
+  foreach ($enabled_roles as $k => $v) {
+    if (!in_array($k, $exist)) {
+      $multiprices['role|' . $k] = $roles[$k];
+    }
+  }
+  // load countries
+  $result = db_query("SELECT country_id, country_name FROM {uc_countries} WHERE country_id <> %d AND version > 0 ORDER BY country_name ASC", uc_store_default_country());
   
-   // build country dropdown
-  $result = db_query("SELECT country_id, country_name FROM {uc_countries} WHERE country_id != %d AND version > 0 ORDER BY country_name ASC", uc_store_default_country());
-  $countries = array();
-  $countries[0] = 'Select country';
   while ($country = db_fetch_object($result)) {
   if (!in_array($country->country_id, $exist))
-    $countries[$country->country_id] = $country->country_name; 
+    $multiprices['country|' . $country->country_id] = $country->country_name; 
   }
-  
   $form['multiprice']['more'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Add a price override for a country'),
+    '#title' => t('Add a price override for a country or role'),
     '#tree' => TRUE,
     '#weight' => 1,
     '#collapsible' => TRUE,
@@ -426,8 +507,8 @@
   
   $form['multiprice']['more']['list'] = array(
   '#type' => 'select',
-  '#description' => t("Select the country/region to add a price overide."),
-  '#options' => $countries,
+  '#description' => t("Select the country/region/role to add a price overide."),
+  '#options' => $multiprices,
   '#ahah' => array(
     'path' => ($default) ? 'uc_multiprice/js/default' : 'uc_multiprice/js',
     'wrapper' => 'multiprice-countries',
@@ -435,7 +516,6 @@
     'effect' => 'slide',
     ),
   );
-  
   return $form;
 }
 
@@ -451,21 +531,19 @@
       uc_multiprice_save_country_to_order($order_id);
     }
   }
-  
   // Get Country by IP if not set
   if (empty($_SESSION['country_id'])) {
-   // IP by ip2country
-   if (module_exists('ip2country') && module_exists('countries_api')) {
-     $country_code = ip2country_get_country(ip_address());
-     $country = countries_api_get_country($country_code);
-     $_SESSION['country_id'] = $country['numcode'];
-   }
-   // IP by ip2cc
-   elseif (module_exists('ip2cc')) { 
-     $country = ip2cc_get_country(ip_address());
-     $_SESSION['country_id'] = $country->country_number;
-   }
-    
+    // IP by ip2country
+    if (module_exists('ip2country') && module_exists('countries_api')) {
+      $country_code = ip2country_get_country(ip_address());
+      $country = countries_api_get_country($country_code);
+      $_SESSION['country_id'] = $country['numcode'];
+    }
+    // IP by ip2cc
+    elseif (module_exists('ip2cc')) { 
+      $country = ip2cc_get_country(ip_address());
+      $_SESSION['country_id'] = $country->country_number;
+    }    
     // Still nothing? use default country
     if (empty($country)) {
       $_SESSION['country_id'] = uc_store_default_country();
@@ -476,34 +554,52 @@
 
 function theme_uc_multiprice_form($form) {
   $output = '';
-  $header = array(t('Country'), t('List price'), t('Cost'), t('Sell price'), t('Delete'));
+  $header = array(t('Country/role'), t('List price'), t('Cost'), t('Sell price'), t('Delete'));
   $row = array();
-  foreach (element_children($form) as $country_id) {
+
+  foreach (element_children($form) as $multiprice_id) {
     $row = array();
-    $row[] = check_plain($form[$country_id]['country']['#value']);
-    $row[] = drupal_render($form[$country_id]['list_price']);
-    $row[] = drupal_render($form[$country_id]['cost']);
-    $row[] = drupal_render($form[$country_id]['sell_price']);
-    $row[] = drupal_render($form[$country_id]['delete']);
-    $rows[] = $row;
+    if ($multiprice_id == '0') {
+      $row[] = check_plain($form[$multiprice_id]['title']['#value']);
+      $row[] = drupal_render($form[$multiprice_id]['list_price']);
+      $row[] = drupal_render($form[$multiprice_id]['cost']);
+      $row[] = drupal_render($form[$multiprice_id]['sell_price']);
+      $row[] = drupal_render($form[$multiprice_id]['delete']);
+      $rows[] = $row;
+    }
+    else {
+      foreach (element_children($form[$multiprice_id]) as $mpid) {
+        $row = array();
+        $row[] = check_plain($form[$multiprice_id][$mpid]['title']['#value']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['list_price']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['cost']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['sell_price']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['delete']);
+        $rows[] = $row;
+      }
+    }
   }
   $output .= theme('table', $header, $rows, array('id' => 'uc_multiprice_table'));
   return $output;
 }
 
-function uc_multiprice_field_element($country) {
+function uc_multiprice_field_element($multiprice) {
   $field['country_id'] = array(
     '#type' => 'hidden',
-    '#value' => $country->country_id,
+    '#value' => $multiprice->country_id,
   );
-  $field['country'] = array(
+  $field['role_id'] = array(
     '#type' => 'hidden',
-    '#default_value' => $country->country_name,
+    '#value' => $multiprice->role_id,
   );
+  $field['title'] = array(
+    '#type' => 'hidden',
+    '#default_value' => $multiprice->country_name ? $multiprice->country_name : $multiprice->role_name,
+  );
   $field['list_price'] = array(
     '#type' => 'textfield',
     '#required' => FALSE,
-    '#default_value' => isset($country->list_price) ? check_plain($country->list_price) : 0.00,
+    '#default_value' => isset($multiprice->list_price) ? check_plain($multiprice->list_price) : 0.00,
     '#weight' => 0,
     '#size' => 20,
     '#maxlength' => 35,
@@ -511,7 +607,7 @@
   $field['cost'] = array(
     '#type' => 'textfield',
     '#required' => FALSE,
-    '#default_value' => isset($country->cost) ? check_plain($country->cost) : 0.00,
+    '#default_value' => isset($multiprice->cost) ? check_plain($multiprice->cost) : 0.00,
     '#weight' => 1,
     '#size' => 20,
     '#maxlength' => 35,
@@ -520,7 +616,7 @@
     '#type' => 'textfield',
     '#required' => FALSE,
     '#weight' => 2,
-    '#default_value' => isset($country->sell_price) ? check_plain($country->sell_price) : 0.00,
+    '#default_value' => isset($multiprice->sell_price) ? check_plain($multiprice->sell_price) : 0.00,
     '#size' => 20,
     '#maxlength' => 35,
   );
@@ -539,29 +635,52 @@
   $form_state = array('submitted' => FALSE);
   $form_build_id = $_POST['form_build_id'];
   $form = form_get_cache($form_build_id, $form_state);
-  $country_id = check_plain($_POST['multiprice']['more']['list']);
   
-  // new field
-  $country = db_fetch_object(db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $country_id));
-  if (module_exists('uc_multiprice_dynamic')) {
-    $form['multiprice']['countries'][$country->country_id] = uc_multiprice_dynamic_field_element($country);
-    $form['multiprice']['countries'][$country->country_id]['dynamic']['list_price'] = uc_multiprice_dynamic_element($country, 'list_price');
-    $form['multiprice']['countries'][$country->country_id]['dynamic']['cost']       = uc_multiprice_dynamic_element($country, 'cost');
-    $form['multiprice']['countries'][$country->country_id]['dynamic']['sell_price'] = uc_multiprice_dynamic_element($country, 'sell_price');
-  }else{
-    $form['multiprice']['countries'][$country->country_id] = uc_multiprice_field_element($country);
+  list($type, $id) = explode('|', check_plain($_POST['multiprice']['more']['list']));
+
+  if ($type == 'country') {
+    // if one selected a cid
+    $country = db_fetch_object(db_query("SELECT * FROM {uc_countries} WHERE country_id = %d", $id));
+    if (module_exists('uc_multiprice_dynamic')) {
+      $form['multiprice']['multiprices']['country'][$country->country_id] = uc_multiprice_dynamic_field_element($country);
+      $form['multiprice']['multiprices']['country'][$country->country_id]['dynamic']['list_price'] = uc_multiprice_dynamic_element($country, 'list_price');
+      $form['multiprice']['multiprices']['country'][$country->country_id]['dynamic']['cost']       = uc_multiprice_dynamic_element($country, 'cost');
+      $form['multiprice']['multiprices']['country'][$country->country_id]['dynamic']['sell_price'] = uc_multiprice_dynamic_element($country, 'sell_price');
+    }
+    else{
+      $form['multiprice']['multiprices']['country'][$country->country_id] = uc_multiprice_field_element($country);
+    }
+  } 
+  elseif ($type == 'role') {
+    // if one selected a rid
+    $enabled_roles = array_filter(variable_get('uc_multiprice_roles', array()));
+    $roles = user_roles();
+    foreach ($enabled_roles as $k => $v) {
+      if ($k == $id) {
+        $role->role_id = $k;
+        $role->role_name = $roles[$k];
+      }
+    }    
+    if (module_exists('uc_multiprice_dynamic')) {
+      $form['multiprice']['multiprices']['role'][$role->role_id] = uc_multiprice_dynamic_field_element($role);
+      $form['multiprice']['multiprices']['role'][$role->role_id]['dynamic']['list_price'] = uc_multiprice_dynamic_element($role, 'list_price');
+      $form['multiprice']['multiprices']['role'][$role->role_id]['dynamic']['cost']       = uc_multiprice_dynamic_element($role, 'cost');
+      $form['multiprice']['multiprices']['role'][$role->role_id]['dynamic']['sell_price'] = uc_multiprice_dynamic_element($role, 'sell_price');
+    }
+    else {
+      $form['multiprice']['multiprices']['role'][$role->role_id] = uc_multiprice_field_element($role);
+    }
   }
 
   form_set_cache($form_build_id, $form, $form_state);
 
   // Rebuild the form. 
   $form = form_builder($_POST['form_id'], $form, $form_state);
-  
   // return correct part
-  unset($form['multiprice']['countries']['prefix']);
-  unset($form['multiprice']['countries']['suffix']);
-  $output = drupal_render($form['multiprice']['countries']);
-  $output .= '<script type="text/javascript">Drupal.settings.uc_multiprice.countries.push('. $country_id .');</script>'; // bad programming?
+  unset($form['multiprice']['multiprices']['prefix']);
+  unset($form['multiprice']['multiprices']['suffix']);
+  $output = drupal_render($form['multiprice']['multiprices']);
+  $output .= '<script type="text/javascript">Drupal.settings.uc_multiprice.'. $type .'.push('. $id .');$("#edit-multiprice-more-list option:selected").remove()</script>'; // bad programming?
   
   print drupal_to_js(array('status' => TRUE, 'data' => $output));
   exit;
@@ -586,14 +705,16 @@
   return $form;  
 }
 
-// save selection to session
+/**
+ * Save selection to session.
+ */
 function uc_multiprice_region_form_submit($form, &$form_state) {
   uc_multiprice_country_id($form_state['values']['country_id']);
 }
   
 /**
-* Save selected country id to the order.
-*/
+ * Save selected country id to the order.
+ */
 function uc_multiprice_save_country_to_order($order_id) {
   // Load up the existing data array.
   $data = db_result(db_query("SELECT data FROM {uc_orders} WHERE order_id = %d", $order_id));
@@ -607,14 +728,21 @@
 }
 
 /**
-* Get countries from the multiprice form and add to drupal settings
-*/
+ * Get countries from the multiprice form and add to drupal settings
+ */
 function uc_multiprice_add_js($form) {
-  foreach($form['multiprice']['countries'] as $key => $country) {
-    if(is_array($country) && isset($country['country_id'])) {
+  $countries = array();
+  foreach ((array)$form['multiprice']['multiprices']['country'] as $key => $country) {
+    if (is_array($country) && isset($country['country_id'])) {
       $countries[] = $key;
     }
   }
-  drupal_add_js(array('uc_multiprice' => array('countries' => $countries)), 'setting');
+  $roles = array();
+  foreach ((array)$form['multiprice']['multiprices']['role'] as $key => $role) {
+    if (is_array($role) && isset($role['role_id'])) {
+      $roles[] = $key;
+    }
+  }
+  drupal_add_js(array('uc_multiprice' => array('country' => $countries, 'role' => $roles)), 'setting');
   return $form;
 }
\ No newline at end of file
Index: uc_multiprice_dynamic/css/uc_multiprice_dynamic_style.css
===================================================================
--- uc_multiprice_dynamic/css/uc_multiprice_dynamic_style.css	(revision 29)
+++ uc_multiprice_dynamic/css/uc_multiprice_dynamic_style.css	(working copy)
@@ -1,77 +1,77 @@
-#uc_multiprice_table th { white-space: nowrap; }
-
-#uc_multiprice_table th:last-child,
-#uc_multiprice_table td:last-child { text-align:center; }
-#uc_multiprice_table .popup td:last-child { text-align:left; }
-
-#uc_multiprice_table input:disabled,
-#uc_multiprice_table input.disabled {
-	color:#999999;
-	background: #EDF5FA;
-	}
-
-#uc_multiprice_table .popup input:disabled,
-#uc_multiprice_table .popup input.disabled {
-	background: #D3E7F4;
-	}
-.dynamic {
-	border:0;
-	height:20px;
-	width:20px;
-	cursor:pointer;
-	margin:0;
-	background: transparent url(../images/calculator_off.png) center no-repeat;
-}
-.dynamic_on {
-	background: transparent url(../images/calculator_on.png) center no-repeat;
-}
-td.dynamic_tab {
-	background: #AFD1E9 url(../images/bg_calc.gif) left bottom repeat-x;
-	}
-
-.popup {
-	display:none;
-	width:100%;	
-	}
-
-.popup td {
-	padding: 10px 0;
-	background:#AFD1E9 url(../images/bg_popup.gif) 0 0 repeat-x;
-	}
-
-.popup fieldset {
-	width:23%;
-	margin:0;
-	padding:0;
-	border:0;
-	background:none;
-	float:left;
-	position:relative;
-	}
-.popup div {
-	width:23%;
-	padding:2px 14px;
-	display:block;
-	float:left;
-	}
-.popup fieldset div {
-	width:auto;
-	float:none;
-	}
-.popup div.description {
-	color:#4C80B2;
-	width:auto;
-	padding:0;
-	float:none;
-	}
-.popup label { 
-	color:#23476E;
-	font-weight:bold;
-	}
-.popup textarea,
-.popup select {
-	width: 100%;
-	padding:0;
-	margin:0;
-	}
-
+#uc_multiprice_table th { white-space: nowrap; }
+
+#uc_multiprice_table th:last-child,
+#uc_multiprice_table td:last-child { text-align:center; }
+#uc_multiprice_table .popup td:last-child { text-align:left; }
+
+#uc_multiprice_table input:disabled,
+#uc_multiprice_table input.disabled {
+	color:#999999;
+	background: #EDF5FA;
+	}
+
+#uc_multiprice_table .popup input:disabled,
+#uc_multiprice_table .popup input.disabled {
+	background: #D3E7F4;
+	}
+.dynamic {
+	border:0;
+	height:20px;
+	width:20px;
+	cursor:pointer;
+	margin:0;
+	background: transparent url(../images/calculator_off.png) center no-repeat;
+}
+.dynamic_on {
+	background: transparent url(../images/calculator_on.png) center no-repeat;
+}
+td.dynamic_tab {
+	background: #AFD1E9 url(../images/bg_calc.gif) left bottom repeat-x;
+	}
+
+.popup {
+	display:none;
+	width:100%;	
+	}
+
+.popup td {
+	padding: 10px 0;
+	background:#AFD1E9 url(../images/bg_popup.gif) 0 0 repeat-x;
+	}
+
+.popup fieldset {
+	width:23%;
+	margin:0;
+	padding:0;
+	border:0;
+	background:none;
+	float:left;
+	position:relative;
+	}
+.popup div {
+	width:23%;
+	padding:2px 14px;
+	display:block;
+	float:left;
+	}
+.popup fieldset div {
+	width:auto;
+	float:none;
+	}
+.popup div.description {
+	color:#4C80B2;
+	width:auto;
+	padding:0;
+	float:none;
+	}
+.popup label { 
+	color:#23476E;
+	font-weight:bold;
+	}
+.popup textarea,
+.popup select {
+	width: 100%;
+	padding:0;
+	margin:0;
+	}
+
Index: uc_multiprice_dynamic/js/uc_multiprice_dynamic.js
===================================================================
--- uc_multiprice_dynamic/js/uc_multiprice_dynamic.js	(revision 29)
+++ uc_multiprice_dynamic/js/uc_multiprice_dynamic.js	(working copy)
@@ -1,12 +1,14 @@
-function uc_multiprice_dynamic(country_id, field) {
+
+function uc_multiprice_dynamic(field_id, field, countryrole) {
+
 	var field = field.replace('_', '-');
-	var _return = $("#edit-multiprice-countries-"+country_id+"-"+field+"");
-	var _default = $("#edit-multiprice-countries-0-"+field);
-	var dynamic_button = $("#edit-multiprice-countries-"+country_id+"-edit-"+field);
-	var enabled = $("#edit-multiprice-countries-"+country_id+"-dynamic-"+field+"-enabled");
+	var _return = $("#edit-multiprice-multiprices-"+countryrole+"-"+field_id+"-"+field+"");
+	var _default = $("#edit-multiprice-multiprices-0-"+field);
+	var dynamic_button = $("#edit-multiprice-multiprices-"+countryrole+"-"+field_id+"-edit-"+field);
+	var enabled = $("#edit-multiprice-multiprices-"+countryrole+"-"+field_id+"-dynamic-"+field+"-enabled");
 	
 	//check if enabled otherwise quit
-	if(enabled.attr("checked")) {
+	if (enabled.attr("checked")) {
 		$(dynamic_button).addClass('dynamic_on');
 		_return.attr("disabled", "disabled");
 		$(_return).addClass('disabled');
@@ -18,14 +20,14 @@
 	}
 
 	// get operators and values
-	var operator 		= $("#edit-multiprice-countries-"+country_id+"-dynamic-"+field+"-operator-value");
-	var operator_1 	= $("#edit-multiprice-countries-"+country_id+"-dynamic-"+field+"-1-operator");
-	var value_1			= $("#edit-multiprice-countries-"+country_id+"-dynamic-"+field+"-1-value");
-	var operator_2	= $("#edit-multiprice-countries-"+country_id+"-dynamic-"+field+"-2-operator");
-	var value_2 		= $("#edit-multiprice-countries-"+country_id+"-dynamic-"+field+"-2-value");
+	var operator 		= $("#edit-multiprice-multiprices-"+countryrole+"-"+field_id+"-dynamic-"+field+"-operator-value");
+	var operator_1 	= $("#edit-multiprice-multiprices-"+countryrole+"-"+field_id+"-dynamic-"+field+"-1-operator");
+	var value_1			= $("#edit-multiprice-multiprices-"+countryrole+"-"+field_id+"-dynamic-"+field+"-1-value");
+	var operator_2	= $("#edit-multiprice-multiprices-"+countryrole+"-"+field_id+"-dynamic-"+field+"-2-operator");
+	var value_2 		= $("#edit-multiprice-multiprices-"+countryrole+"-"+field_id+"-dynamic-"+field+"-2-value");
 
 	// do some changing
-	if(operator_1.val() == 'default') {
+	if (operator_1.val() == 'default') {
 		value_1.val(_default.val());
 		value_1.attr("disabled", "disabled");
 		$(value_1).addClass('disabled');
@@ -34,7 +36,7 @@
 		$(value_1).removeClass('disabled');
 	}
 	
-	if(operator_2.val() == 'default') {
+	if (operator_2.val() == 'default') {
 		value_2.val(_default.val());
 		value_2.attr("disabled", "disabled");
 		$(value_2).addClass('disabled');
@@ -43,24 +45,24 @@
 		$(value_2).removeClass('disabled');
 	}
 	
-	if(operator_1.val() == 'custom') {
+	if (operator_1.val() == 'custom') {
 		value_1.attr("disabled", '');
 	}
-	if(operator_2.val() == 'custom') {
+	if (operator_2.val() == 'custom') {
 		value_2.attr("disabled", '');
 	}
 	
 	// dynamiculations
-	if(operator.val() == 'x') {
+	if (operator.val() == 'x') {
 		result = parseFloat(value_1.val()) * parseFloat(value_2.val());
 	}
-	if(operator.val() == '-') {
+	if (operator.val() == '-') {
 		result = parseFloat(value_1.val()) - parseFloat(value_2.val());
 	}
-	if(operator.val() == '+') {
+	if (operator.val() == '+') {
 		result = parseFloat(value_1.val()) + parseFloat(value_2.val());
 	}
-	if(operator.val() == '/') {
+	if (operator.val() == '/') {
 		result = parseFloat(value_1.val()) / parseFloat(value_2.val());
 	}
 	
@@ -69,9 +71,12 @@
 }
 
 function uc_multiprice_dynamic_recalculate(field) {
-	jQuery.each(Drupal.settings.uc_multiprice.countries, function() {
-			uc_multiprice_dynamic(this, field);																																
-	})
+	jQuery.each(Drupal.settings.uc_multiprice.country, function() {
+			uc_multiprice_dynamic(this, field, 'country');																																
+	});
+	jQuery.each(Drupal.settings.uc_multiprice.role, function() {
+			uc_multiprice_dynamic(this, field, 'role');																																
+	});
 }
 
 Drupal.behaviors.uc_multiprice_dynamic = function (context) {
@@ -94,13 +99,13 @@
 	});
 
 	// add listeners to default
-	$("#edit-multiprice-countries-0-list-price").change(function(){
+	$("#edit-multiprice-multiprice-0-list-price").change(function(){
 			uc_multiprice_dynamic_recalculate('list-price');
 	});
-	$("#edit-multiprice-countries-0-sell-price").change(function(){
+	$("#edit-multiprice-multiprice-0-sell-price").change(function(){
 			uc_multiprice_dynamic_recalculate('sell-price');
 	});
-	$("#edit-multiprice-countries-0-cost").change(function(){
+	$("#edit-multiprice-multiprice-0-cost").change(function(){
 			uc_multiprice_dynamic_recalculate('cost');
 	});
 	
Index: uc_multiprice_dynamic/uc_multiprice_dynamic.info
===================================================================
--- uc_multiprice_dynamic/uc_multiprice_dynamic.info	(revision 29)
+++ uc_multiprice_dynamic/uc_multiprice_dynamic.info	(working copy)
@@ -1,13 +1,13 @@
-; $Id: uc_multiprice_dynamic.info,v 1.2 2009/10/01 11:45:10 docc Exp $
-name = Multiprice Dynamic price
-description = Allows dynamic calculation of the price
-package = "Ubercart - extra"
-dependencies[] = uc_multiprice
-core = 6.x
-
-; Information added by drupal.org packaging script on 2010-10-22
-version = "6.x-2.x-dev"
-core = "6.x"
-project = "uc_multiprice"
-datestamp = "1287750237"
-
+; $Id: uc_multiprice_dynamic.info,v 1.2 2009/10/01 11:45:10 docc Exp $
+name = Multiprice Dynamic price
+description = Allows dynamic calculation of the price
+package = "Ubercart - extra"
+dependencies[] = uc_multiprice
+core = 6.x
+
+; Information added by drupal.org packaging script on 2010-10-17
+version = "6.x-2.x-dev"
+core = "6.x"
+project = "uc_multiprice"
+datestamp = "1287275090"
+
Index: uc_multiprice_dynamic/uc_multiprice_dynamic.module
===================================================================
--- uc_multiprice_dynamic/uc_multiprice_dynamic.module	(revision 29)
+++ uc_multiprice_dynamic/uc_multiprice_dynamic.module	(working copy)
@@ -2,12 +2,18 @@
 // $Id: uc_multiprice_dynamic.module,v 1.7 2009/10/14 08:28:03 docc Exp $
 
 /**
- * @file Provides Multiprice dynamic options
+ * Provides Multiprice options
+ *
+ * Module developed by Docc | Optixdesigns.nl
+ * @author Docc 
+ * Module extended by Bartezz | Intrige.nl
+ * @author Bartezz <bartezz@gmail.com>
+ *
  */
 
-/*******************************************************************************
+/**
  * Hook Functions (Drupal)
- ******************************************************************************/
+ */
 
 /**
  * Implementation of hook_menu().
@@ -43,9 +49,9 @@
   );
 }
 
-/*******************************************************************************
+/**
  * Theme functions
- ******************************************************************************/
+ */
 
 /**
  * theme_uc_multiprice_dynamic_element_form
@@ -64,43 +70,60 @@
   drupal_add_js($path .'/js/uc_multiprice_dynamic.js', 'module', 'header');  
   drupal_add_css($path .'/css/uc_multiprice_dynamic_style.css', 'module', 'all', FALSE);
   
-  $header = array(array('data' => t('Country'), 'width' => '125px'), '', t('List price'), '', t('Cost'), '', t('Sell price'), t('Delete'));
+  $header = array(array('data' => t('Country/role'), 'width' => '125px'), '', t('List price'), '', t('Cost'), '', t('Sell price'), t('Delete'));
   
   $row = array();
-  foreach (element_children($form) as $country_id) {
+  foreach (element_children($form) as $multiprice_id) {
     $row = array();
-    if ($country_id != '0' || $country_id != 'dynamic') {
-      $row[] = check_plain($form[$country_id]['country']['#value']);
-      $row[] = drupal_render($form[$country_id]['edit']['list_price']);
-      $row[] = drupal_render($form[$country_id]['list_price']);
-      $row[] = drupal_render($form[$country_id]['edit']['cost']);
-      $row[] = drupal_render($form[$country_id]['cost']);
-      $row[] = drupal_render($form[$country_id]['edit']['sell_price']);
-      $row[] = drupal_render($form[$country_id]['sell_price']);
-      $row[] = drupal_render($form[$country_id]['delete']);
-    }elseif($country_id == '0') {
-      $row[] = check_plain($form[$country_id]['country']['#value']);
+    if ($multiprice_id != '0' || $multiprice_id != 'dynamic') {
+      foreach (element_children($form[$multiprice_id]) as $mpid) {
+        $row = array();
+        $row[] = check_plain($form[$multiprice_id][$mpid]['title']['#value']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['edit']['list_price']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['list_price']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['edit']['cost']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['cost']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['edit']['sell_price']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['sell_price']);
+        $row[] = drupal_render($form[$multiprice_id][$mpid]['delete']);
+        $rows[] = $row;
+        
+        $row = array();
+        $row[] = array('data' => drupal_render($form[$multiprice_id][$mpid]['dynamic']['list_price']), 'colspan' => '8');
+        $rows[] = array('data' => $row, 'id' => 'edit-multiprice-multiprices-'. $multiprice_id .'-'. $mpid .'-edit-list-price-dynamic', 'class' => 'popup');
+        
+        $row = array();
+        $row[] = array('data' => drupal_render($form[$multiprice_id][$mpid]['dynamic']['cost']), 'colspan' => '8');
+        $rows[] = array('data' => $row, 'id' => 'edit-multiprice-multiprices-'. $multiprice_id .'-'. $mpid .'-edit-cost-dynamic', 'class' => 'popup');
+        
+        $row = array();
+        $row[] = array('data' => drupal_render($form[$multiprice_id][$mpid]['dynamic']['sell_price']), 'colspan' => '8');
+        $rows[] = array('data' => $row, 'id' => 'edit-multiprice-multiprices-'. $multiprice_id .'-'. $mpid .'-edit-sell-price-dynamic', 'class' => 'popup');
+      }
+    }
+    elseif ($multiprice_id == '0') {
+      $row[] = check_plain($form[$multiprice_id]['title']['#value']);
       $row[] = '';
-      $row[] = drupal_render($form[$country_id]['list_price']);
+      $row[] = drupal_render($form[$multiprice_id]['list_price']);
       $row[] = '';
-      $row[] = drupal_render($form[$country_id]['cost']);
+      $row[] = drupal_render($form[$multiprice_id]['cost']);
       $row[] = '';
-      $row[] = drupal_render($form[$country_id]['sell_price']);
+      $row[] = drupal_render($form[$multiprice_id]['sell_price']);
       $row[] = '';
-    }  
-    $rows[] = $row;
-    
-    $row = array();
-    $row[] = array('data' => drupal_render($form[$country_id]['dynamic']['list_price']), 'colspan' => '8');
-    $rows[] = array('data' => $row, 'id' => 'edit-multiprice-countries-'. $country_id .'-edit-list-price-dynamic', 'class' => 'popup');
-    
-    $row = array();
-    $row[] = array('data' => drupal_render($form[$country_id]['dynamic']['cost']), 'colspan' => '8');
-    $rows[] = array('data' => $row, 'id' => 'edit-multiprice-countries-'. $country_id .'-edit-cost-dynamic', 'class' => 'popup');
-    
-    $row = array();
-    $row[] = array('data' => drupal_render($form[$country_id]['dynamic']['sell_price']), 'colspan' => '8');
-    $rows[] = array('data' => $row, 'id' => 'edit-multiprice-countries-'. $country_id .'-edit-sell-price-dynamic', 'class' => 'popup');
+      $rows[] = $row;
+      
+      $row = array();
+      $row[] = array('data' => drupal_render($form[$multiprice_id]['dynamic']['list_price']), 'colspan' => '8');
+      $rows[] = array('data' => $row, 'id' => 'edit-multiprice-multiprices-'. $multiprice_id .'-edit-list-price-dynamic', 'class' => 'popup');
+      
+      $row = array();
+      $row[] = array('data' => drupal_render($form[$multiprice_id]['dynamic']['cost']), 'colspan' => '8');
+      $rows[] = array('data' => $row, 'id' => 'edit-multiprice-multiprices-'. $multiprice_id .'-edit-cost-dynamic', 'class' => 'popup');
+      
+      $row = array();
+      $row[] = array('data' => drupal_render($form[$multiprice_id]['dynamic']['sell_price']), 'colspan' => '8');
+      $rows[] = array('data' => $row, 'id' => 'edit-multiprice-multiprices-'. $multiprice_id .'-edit-sell-price-dynamic', 'class' => 'popup');
+    }    
   }
   
   $output .= theme('table', $header, $rows, array('id' => 'uc_multiprice_table'));
@@ -108,18 +131,17 @@
   return $output;
 }
 
-/*******************************************************************************
+/**
  * Callbacks, forms etc
- ******************************************************************************/
-
-function uc_multiprice_dynamic_element($country, $type) {
+ */
+function uc_multiprice_dynamic_element($multiprice, $type) {
   $field['#theme'] = 'uc_multiprice_dynamic_element_form';
   $field['enabled'] = array(
       '#type' => 'checkbox',
       '#title' => t('Enabled'),
-      '#description' => t("Calculate @type for @country", array('@type' => str_replace('_', ' ', $type), '@country' => $country->country_name)),
-      '#default_value' => isset($country->data[$type]['enabled']) ? $country->data[$type]['enabled'] : 0,
-      '#attributes' => array('onclick' => 'uc_multiprice_dynamic("'. $country->country_id .'", "'. $type .'");'),
+      '#description' => t("Calculate @type for @country", array('@type' => str_replace('_', ' ', $type), '@country' => ($multiprice->country_name ? $multiprice->country_name : $multiprice->role_name))),
+      '#default_value' => isset($multiprice->data[$type]['enabled']) ? $multiprice->data[$type]['enabled'] : 0,
+      '#attributes' => array('onclick' => 'uc_multiprice_dynamic("'. ($multiprice->country_id ? $multiprice->country_id : $multiprice->role_id) .'", "'. $type .'", "'. ($multiprice->country_name ? 'country' : 'role') .'");'),
   );
   $field['type'] = array(
     '#type' => 'hidden',
@@ -135,17 +157,17 @@
     '#type' => 'select',
     '#required' => FALSE,
     '#options' => array('default' => 'Default', 'custom' => 'Custom'),
-    '#default_value' => isset($country->data[$type]['1']) ? check_plain($country->data[$type]['1']['operator']) : 'custom',
-    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. $country->country_id .'", "'. $type .'");'),
+    '#default_value' => isset($multiprice->data[$type]['1']) ? check_plain($multiprice->data[$type]['1']['operator']) : 'custom',
+    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. ($multiprice->country_id ? $multiprice->country_id : $multiprice->role_id) .'", "'. $type .'", "'. ($multiprice->country_name ? 'country' : 'role') .'");'),
   );
   $field['1']['value'] = array(
     '#type' => 'textfield',
-    '#default_value' => isset($country->data[$type]['1']['value']) ? check_plain($country->data[$type]['1']['value']) : 0.00,
+    '#default_value' => isset($multiprice->data[$type]['1']['value']) ? check_plain($multiprice->data[$type]['1']['value']) : 0.00,
     '#size' => 5,
-    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. $country->country_id .'", "'. $type .'");'),
-    //'#disabled' => ($country->data[$type]['1']['operator']=='default')? TRUE : FALSE,
+    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. ($multiprice->country_id ? $multiprice->country_id : $multiprice->role_id) .'", "'. $type .'", "'. ($multiprice->country_name ? 'country' : 'role') .'");'),
+    //'#disabled' => ($multiprice->data[$type]['1']['operator']=='default')? TRUE : FALSE,
   );
-	$field['operator'] = array(
+  $field['operator'] = array(
       '#type' => 'fieldset',
       '#tree' => TRUE,
       '#collapsible' => FALSE,
@@ -155,8 +177,8 @@
     '#type' => 'select',
     '#required' => FALSE,
     '#options' => array('x' => 'x', '-' => '-', '+' => '+', '/' => '/'),
-    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. $country->country_id .'", "'. $type .'");'),
-    '#default_value' => isset($country->data[$type]) ? check_plain($country->data[$type]['value']) : 'x',
+    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. ($multiprice->country_id ? $multiprice->country_id : $multiprice->role_id) .'", "'. $type .'", "'. ($multiprice->country_name ? 'country' : 'role') .'");'),
+    '#default_value' => isset($multiprice->data[$type]) ? check_plain($multiprice->data[$type]['value']) : 'x',
   );
   $field['2'] = array(
       '#type' => 'fieldset',
@@ -167,43 +189,42 @@
   $field['2']['operator'] = array(
     '#type' => 'select',
     '#options' => array('default' => 'Default', 'custom' => 'Custom'),
-    '#default_value' => isset($country->data[$type]['2']) ? check_plain($country->data[$type]['2']['operator']) : 'default',
-    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. $country->country_id .'", "'. $type .'");'),
+    '#default_value' => isset($multiprice->data[$type]['2']) ? check_plain($multiprice->data[$type]['2']['operator']) : 'default',
+    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. ($multiprice->country_id ? $multiprice->country_id : $multiprice->role_id) .'", "'. $type .'", "'. ($multiprice->country_name ? 'country' : 'role') .'");'),
   );
   $field['2']['value'] = array(
     '#type' => 'textfield',
-    '#default_value' => isset($country->data[$type]['2']) ? check_plain($country->data[$type]['2']['value']) : 0.00,
+    '#default_value' => isset($multiprice->data[$type]['2']) ? check_plain($multiprice->data[$type]['2']['value']) : 0.00,
     '#size' => 5,
-    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. $country->country_id .'", "'. $type .'");'),
-    //'#disabled' => ($country->data[$type]['2']['operator']=='default')? TRUE : FALSE,
+    '#attributes' => array('onchange' => 'uc_multiprice_dynamic("'. ($multiprice->country_id ? $multiprice->country_id : $multiprice->role_id) .'", "'. $type .'", "'. ($multiprice->country_name ? 'country' : 'role') .'");'),
+    //'#disabled' => ($multiprice->data[$type]['2']['operator']=='default')? TRUE : FALSE,
   );
 
   return $field;
 }
 
-function uc_multiprice_dynamic_field_element($country) {
+function uc_multiprice_dynamic_field_element($multiprice) {
   $field['country_id'] = array(
     '#type' => 'hidden',
-    '#value' => $country->country_id,
-  );/*
-  $field['country'] = array(
-    '#type' => 'textfield',
-    '#default_value' => $country->country_name,
+    '#value' => $multiprice->country_id,
   );
-  */
-  $field['country'] = array(
+  $field['role_id'] = array(
     '#type' => 'hidden',
-    '#default_value' => $country->country_name,
+    '#value' => $multiprice->role_id,
   );
+  $field['title'] = array(
+    '#type' => 'hidden',
+    '#default_value' => $multiprice->country_name ? $multiprice->country_name : $multiprice->role_name,
+  );
   $field['edit']['list_price'] = array(
     '#type' => 'button',
     '#weight' => 1,
-    '#attributes' => array('class' => ($country->data['list_price']['enabled']==1) ? 'dynamic dynamic_on' : 'dynamic'),
+    '#attributes' => array('class' => ($multiprice->data['list_price']['enabled']==1) ? 'dynamic dynamic_on' : 'dynamic'),
   );
   $field['list_price'] = array(
     '#type' => 'textfield',
     '#required' => FALSE,
-    '#default_value' => isset($country->list_price) ? check_plain($country->list_price) : 0.00,
+    '#default_value' => isset($multiprice->list_price) ? check_plain($multiprice->list_price) : 0.00,
     '#weight' => 0,
     '#size' => 10,
     '#maxlength' => 35,
@@ -211,12 +232,12 @@
   $field['edit']['cost'] = array(
     '#type' => 'button',
     '#weight' => 1,
-    '#attributes' => array('class' => ($country->data['cost']['enabled']==1) ? 'dynamic dynamic_on' : 'dynamic'),
+    '#attributes' => array('class' => ($multiprice->data['cost']['enabled']==1) ? 'dynamic dynamic_on' : 'dynamic'),
   );
   $field['cost'] = array(
     '#type' => 'textfield',
     '#required' => FALSE,
-    '#default_value' => isset($country->cost) ? check_plain($country->cost) : 0.00,
+    '#default_value' => isset($multiprice->cost) ? check_plain($multiprice->cost) : 0.00,
     '#weight' => 1,
     '#size' => 20,
     '#maxlength' => 35,
@@ -224,13 +245,13 @@
   $field['edit']['sell_price'] = array(
     '#type' => 'button',
     '#weight' => 1,
-    '#attributes' => array('class' => ($country->data['sell_price']['enabled']==1) ? 'dynamic dynamic_on' : 'dynamic'),
+    '#attributes' => array('class' => ($multiprice->data['sell_price']['enabled']==1) ? 'dynamic dynamic_on' : 'dynamic'),
   );
   $field['sell_price'] = array(
     '#type' => 'textfield',
     '#required' => FALSE,
     '#weight' => 2,
-    '#default_value' => isset($country->sell_price) ? check_plain($country->sell_price) : 0.00,
+    '#default_value' => isset($multiprice->sell_price) ? check_plain($multiprice->sell_price) : 0.00,
     '#size' => 20,
     '#maxlength' => 35,
   );
Index: uc_product_handler_field_multiprice.inc
===================================================================
--- uc_product_handler_field_multiprice.inc	(revision 29)
+++ uc_product_handler_field_multiprice.inc	(working copy)
@@ -11,17 +11,14 @@
  */
 class uc_product_handler_field_multiprice extends views_handler_field {
   function render($values) {
-    $multiprice = db_fetch_object(db_query("SELECT * FROM {uc_multiprice} WHERE nid = %d AND country_id = %d", 
-                       $values->nid, uc_multiprice_country_id()));
+    $multiprice = db_fetch_object(db_query("SELECT * FROM {uc_multiprice} WHERE nid = %d AND country_id = %d", $values->nid, uc_multiprice_country_id()));
     if ($multiprice) {
       if ($values->uc_products_sell_price)
-       $values->uc_products_sell_price = check_plain($multiprice->sell_price);
-       
+        $values->uc_products_sell_price = check_plain($multiprice->sell_price);
       if ($values->uc_products_cost)
-       $values->uc_products_cost = check_plain($multiprice->cost);
-      
+        $values->uc_products_cost = check_plain($multiprice->cost);
       if ($values->uc_products_list_price)
-       $values->uc_products_list_price = check_plain($multiprice->list_price);
+        $values->uc_products_list_price = check_plain($multiprice->list_price);
     }
 
     $context = array(
@@ -32,10 +29,10 @@
       'field' => $this->real_field,
       ),
     );
-    $table_alias_len = strlen($this->table_alias);
+    $table_alias_len = drupal_strlen($this->table_alias);
     foreach ($values as $key => $value) {
-      if (substr($key, 0, $table_alias_len) == $this->table_alias) {
-        $values->{substr($key, $table_alias_len + 1)} = $value;
+      if (drupal_substr($key, 0, $table_alias_len) == $this->table_alias) {
+        $values->{drupal_substr($key, $table_alias_len + 1)} = $value;
       }
     }
     
