Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/user_badges/README.txt,v
retrieving revision 1.5
diff -u -F^f -r1.5 README.txt
--- README.txt	17 Jan 2007 06:51:01 -0000	1.5
+++ README.txt	3 Apr 2008 16:17:38 -0000
@@ -17,6 +17,12 @@
 identify moderators, administrators, or anyone with a given role.
 
 
+Limitation
+==========
+
+User Badges is not compatible with the "private" file download method.
+
+
 Dependencies
 ============
 In order to upload images via the user interface, user badges depends on:
Index: user_badges.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/user_badges/user_badges.info,v
retrieving revision 1.2
diff -u -F^f -r1.2 user_badges.info
--- user_badges.info	18 Jun 2007 23:50:59 -0000	1.2
+++ user_badges.info	3 Apr 2008 16:17:38 -0000
@@ -1,5 +1,10 @@
-; $Id: user_badges.info,v 1.2 2007/06/18 23:50:59 dww Exp $
+; $Id: user_badges.info,v 1.1.2.1 2007/06/18 23:07:11 dww Exp $
 name = User badges
 description = Enables assignment of graphical badges to users and roles.
-dependencies = upload
+dependencies[] = upload
 
+; Information added by drupal.org packaging script on 2007-06-19
+version = "6.x-1.x-dev"
+project = "user_badges"
+datestamp = "1182212765"
+core = 6.x
Index: user_badges.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/user_badges/user_badges.install,v
retrieving revision 1.1
diff -u -F^f -r1.1 user_badges.install
--- user_badges.install	25 Jul 2006 14:28:20 -0000	1.1
+++ user_badges.install	3 Apr 2008 16:17:38 -0000
@@ -1,26 +1,132 @@
 <?php
-// $Id: user_badges.install,v 1.1 2006/07/25 14:28:20 heine Exp $
+// $Id: user_badges.install,v 1.1.4.3 2007/03/14 20:15:41 heine Exp $
+
+function user_badges_schema() {
+  $schema = array();
+  $schema['user_badges_badges'] = array(
+    'description' => 'Holds the user badge images',
+    'fields' => array(
+      'bid' => array(
+        'description' => t('Original badge ID'),
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'name' => array(
+        'description' => t('Badge name'),
+        'type' => 'varchar',
+        'length' => 50,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'image' => array(
+        'description' => t('Associated image'),
+        'type' => 'varchar',
+        'length' => 80,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'weight' => array(
+        'description' => t('Order in list'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0
+      ),
+    ),
+    'primary key' => array('bid'),
+    'indexes' => array(
+      'bid_weight_name' => array('bid', 'weight', 'name'),
+      'weight_name' => array('weight', 'name'),
+    )
+  );
+  $schema['user_badges_product'] = array(
+    'description' => 'Holds the user badge images',
+    'fields' => array(
+      'bid' => array(
+        'description' => t('Original badge ID'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0
+      ),
+      'nid' => array(
+        'description' => t('Node ID'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'unique keys' => array('bid_nid' => array('bid', 'nid')),
+  );
+  $schema['user_badges_roles'] = array(
+    'description' => 'Holds the user badge images',
+    'fields' => array(
+      'rid' => array(
+        'description' => t('Original role ID'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'bid' => array(
+        'description' => t('Original badge ID'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+    ),
+    'unique keys' => array('rid_bid' => array('rid', 'bid')),
+  );
+  $schema['user_badges_user'] = array(
+    'description' => 'Holds the user badge images',
+    'fields' => array(
+      'uid' => array(
+        'description' => t('Original user ID'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'bid' => array(
+        'description' => t('Original badge ID'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'type' => array(
+        'description' => t('Badge Type'),
+        'type' => 'varchar',
+        'length' => 20,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+    ),
+    'unique keys' => array('uid_bid' => array('uid', 'bid')),
+    'indexes' => array(
+      'type' => array('type'),
+    )
+  );
+  
+  return $schema;
+}
 
 function user_badges_install() {
-  $ret = array();
-  $ret[] = db_query("CREATE TABLE {user_badges_badges} (
-  bid int(10) NOT NULL default '0',
-  name varchar(50) NOT NULL default '',
-  image varchar(80) NOT NULL default '',
-  weight int(2) NOT NULL default '0'
-  )");
-  $ret[] = db_query("CREATE TABLE {user_badges_product} (
-  bid int(10) NOT NULL default '0',
-  nid int(10) NOT NULL default '0'
-)");
-  $ret[] = db_query("CREATE TABLE {user_badges_roles} (
-  rid int(10) NOT NULL default '0',
-  bid int(10) NOT NULL default '0'
-)");
-  $ret[] = db_query("CREATE TABLE {user_badges_user} (
-  uid int(10) NOT NULL default '0',
-  bid int(10) NOT NULL default '0',
-  type varchar(20) NOT NULL default ''
-)");
-  return $ret;
+  drupal_install_schema('user_badges');
 }
+
+function user_badges_uninstall() {
+  // Delete files.
+  $dir = file_create_path('badges');
+  if ($dir) {
+    $files = file_scan_directory($dir, '.*\.(gif|jpg|jpeg|png)', array('.', '..', 'CVS'), 0, FALSE);
+    foreach ($files as $file) {
+      file_delete($file->filename);
+    }
+  }
+  
+  // Delete the badges directory.  
+  if (file_exists($dir)) {
+    rmdir($dir);
+  }
+  drupal_uninstall_schema('user_badges');
+}
\ No newline at end of file
Index: user_badges.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/user_badges/user_badges.module,v
retrieving revision 1.14
diff -u -F^f -r1.14 user_badges.module
--- user_badges.module	17 Jan 2007 06:51:01 -0000	1.14
+++ user_badges.module	3 Apr 2008 16:17:39 -0000
@@ -1,7 +1,7 @@
 <?php
-/* $Id: user_badges.module,v 1.14 2007/01/17 06:51:01 heine Exp $ */
+/* $Id: user_badges.module,v 1.14.2.5 2007/03/16 13:00:28 heine Exp $ */
 
-# Todo: convert to 5, make it work with private files.
+# Todo: convert to 6, make it work with private files.
 
 function user_badges_help($section) {
   switch ($section) {
@@ -14,8 +14,6 @@ function user_badges_help($section) {
       return t("Select the badge that you'd like to associate with each role.");
     case 'admin/settings/user_badges/images':
       return t("Upload images to display as a user badge. These images can be anything you like, but it is recommended that you maintain a uniform icon size for all of your badges. Keep in mind that a user may have many badges displayed so you'll probably want to keep them as small as possible (like 16x16 pixels or smaller).");
-    case 'admin/settings/user_badges/products':
-      return t("For each ecommerce product listed below, select the badge that will be assigned to users upon payment completion.");
   }
 }
 
@@ -24,78 +22,54 @@ function user_badges_perm() {
 }
 
 
-function user_badges_menu($may_cache) {
-  $access = user_access('manage badges');
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/user/user_badges',
-      'title' => t('Badges'),
-      'callback' => 'user_badges_settings_page',
-      'access' => $access,
-    );
-  }
-  else {
-    $items[] = array(
-      'path' => 'admin/user/user_badges/list',
-      'title' => t('Edit user badges'),
-      'access' => $access,
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-      'weight' => -10
-    );
-    $items[] = array(
-      'path' => 'admin/user/user_badges/images',
-      'title' => t('Images'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('user_badges_images_form'),
-      'access' => $access,
-      'type' => MENU_LOCAL_TASK
-    );
-    $items[] = array(
-      'path' => 'admin/user/user_badges/roles',
-      'title' => t('Roles'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('user_badges_roles_form'),
-      'access' => $access,
-      'type' => MENU_LOCAL_TASK
-    );
-    if (module_exists('product')) {
-      $items[] = array(
-        'path' => 'admin/user/user_badges/products',
-        'title' => t('Products'),
-        'callback' => 'user_badges_products_page',
-        'weight' => 8,
-        'access' => $access,
-        'type' => MENU_LOCAL_TASK
-      );
-    }
-    $items[] = array(
-      'path' => 'admin/user/user_badges/delete',
-      'title' => t('Delete badge'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('user_badges_delete_form'),
-      'access' => $access,
-      'type' => MENU_CALLBACK,
-    );
-    if (arg(0) == 'user') {
-      if ($access) {
-        $uid = arg(1);
-      }
-      if (is_numeric($uid)) {
-        $items[] = array(
-          'path' => "user/$uid/badges",
-          'title' => t('Badges'),
-          'callback' => 'user_badges_page',
-          'access' => $access,
-          'type' => MENU_LOCAL_TASK,
-          'weight' => 5,
-        );
-      }
-    }
-  }
+function user_badges_menu() {
+  $items = array();
+  $access = user_badges_perm();
+  $items['admin/user/user_badges'] = array(
+    'title' => 'Badges',
+    'page callback' => 'user_badges_settings_page',
+    'access arguments' => $access,
+  );
+  
+  $items['admin/user/user_badges/list'] = array(
+    'title' => 'Edit user badges',
+    'access arguments' => $access,
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => -10,
+  );
+  $items['admin/user/user_badges/images'] = array(
+    'title' => 'Images',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('user_badges_images_form'),
+    'access arguments' => $access,
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/user/user_badges/roles'] = array(
+    'title' => 'Roles',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('user_badges_roles_form'),
+    'access arguments' => $access,
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/user/user_badges/delete'] = array(
+    'title' => 'Delete badge',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('user_badges_delete_form'),
+    'access arguments' => $access,
+    'type' => MENU_CALLBACK,
+  );
+  $items['user/%user/badges'] = array(
+    'title' => 'Badges',
+    'page callback' => 'user_badges_page',
+    'page arguments' => array(1),
+    'access arguments' => $access,
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 5,
+  );
+  
   return $items;
 }
 
-
 /**
  * Implementation of hook_user()
  * This handles assignment of badges based on role.
@@ -190,12 +164,27 @@ function user_badges_user($op, &$edit, &
 }
 
 /**
- * Define the page on user/uid/badges.
+ * Implementation of hook_theme().
  */
-function user_badges_page() {
-  $uid = arg(1);
-  $account = user_load(array('uid' => $uid));
+function user_badges_theme() {
+  $themes = array();
+  $themes['user_badge'] = array(
+    'arguments' => array(
+      'badge' => NULL,
+    ),
+  );
+  $themes['user_badge_group'] = array(
+    'arguments' => array(
+      'badgeimages' => array(),
+    ),
+  );
+  return $themes;
+}
 
+/**
+ * Define the page on user/uid/badges.
+ */
+function user_badges_page($account) {
   drupal_set_title(t('Edit badges for %user_name', array('%user_name' => $account->name)));
 
   return drupal_get_form('user_badges_page_form', $account);
@@ -204,7 +193,7 @@ function user_badges_page() {
 /**
  * Form to assign badges to users.
  */
-function user_badges_page_form($account) {
+function user_badges_page_form(&$form_state, $account) {
   $form = array();
 
   $form['uid'] = array('#type' => 'value', '#value' => $account->uid);
@@ -228,7 +217,8 @@ function user_badges_page_form($account)
   return $form;
 }
 
-function user_badges_page_form_submit($form_id, $form_values) {
+function user_badges_page_form_submit($form, &$form_state) {
+  $form_values = $form_state['values'];
   user_badges_user_save($form_values['badges'], $form_values['uid'], FALSE);
 }
 
@@ -275,7 +265,7 @@ function user_badges_user_save($edit, $u
       drupal_set_message(t('Badges saved.'));
     }
     elseif (!$quiet) {
-      drupal_set_message(t('There was a problem saving badges to the database.'));
+      drupal_set_message(t('There was a problem saving badges to the database.'), 'error');
     }
   }
 }
@@ -293,7 +283,7 @@ function user_badges_user_save($edit, $u
  * @return unknown
  */
 function user_badges_user_add_badge($uid, $bid, $type = NULL){
-  return db_query('INSERT INTO {user_badges_user} (uid, bid, type) VALUES (%d, %d, "%s")', $uid, $bid, $type);
+  return db_query('INSERT INTO {user_badges_user} (uid, bid, type) VALUES (%d, %d, \'%s\')', $uid, $bid, $type);
 }
 
 function user_badges_user_remove_badge($uid, $bid, $type = NULL){
@@ -301,12 +291,11 @@ function user_badges_user_remove_badge($
     return db_query('DELETE FROM {user_badges_user} WHERE uid=%d AND bid=%d', $uid, $bid);
   }
   else {
-    return db_query('DELETE FROM {user_badges_user} WHERE uid=%d AND bid=%d AND type="%s"', $uid, $bid, $type);
+    return db_query('DELETE FROM {user_badges_user} WHERE uid=%d AND bid=%d AND type=\'%s\'', $uid, $bid, $type);
   }
 }
 
 function user_badges_settings_page($op = NULL, $bid = NULL) {
-
   switch ($op) {
     case 'edit':
       if (is_numeric($bid)) {
@@ -331,30 +320,31 @@ function user_badges_settings_page($op =
       $output = theme('table', $header, $tablerow, array('style'=>'width:100%'));
       $output .= "<br/><br/>";
       $form[] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Add another'),
-    );
-    //$output .= user_badges_edit_form();
-    $output .= drupal_get_form('user_badges_edit_form');
-
+        '#type' => 'fieldset',
+        '#title' => t('Add another'),
+      );
+      //$output .= user_badges_edit_form();
+	  $output .= drupal_get_form('user_badges_edit_form');
+	  break;
   }
   return $output;
 }
 
-function user_badges_edit_form_submit($form_id, $form_values) {
-  user_badges_save_badge($form_values);
+function user_badges_edit_form_submit($form, &$form_state) {
+  $form_state['redirect'] = user_badges_save_badge($form_state['values']);
 }
 
 /**
  * Define a form to upload the badge images.
  */
-function user_badges_images_form() {
+function user_badges_images_form($form_state) {
+  $form = array('#skip_duplicate_check' => TRUE);
   if (module_exists('upload')) {
     $form['new']['upload'] = array('#type' => 'file', '#title' => t('Upload image'), '#size' => 40);
     $form['new']['attach'] = array('#type' => 'submit', '#value' => t('Upload'));
   }
   else {
-  	drupal_set_message(t('Upload of images requires the upload module to be enabled.'), 'error');
+    drupal_set_message(t('Upload of images requires the upload module to be enabled.'), 'error');
   }
 
   $form['#attributes']['enctype'] = 'multipart/form-data';
@@ -387,37 +377,51 @@ function user_badges_images_form() {
  * OR
  * Upload has been chosen AND the file upload form is not empty.
  */
-function user_badges_images_form_validate($form_id, $form_values) {
-  if ($form_values['op'] == t('Upload') && file_check_upload('upload') === FALSE ) {
-    form_set_error('upload', t('Please enter the filename of an image to upload.'));
+function user_badges_images_form_validate($form, &$form_state) {
+  $form_values = $form_state['values'];
+  $op = $form_state['clicked_button']['#value'];
+  if ($op == t('Upload')) {
+    $dir = file_create_path('badges');
+    $is_writable = file_check_directory($dir, 1);
+    if ($is_writable) {
+      if ($file = file_save_upload('upload', array(), $dir)) {
+        if (!image_get_info($file->filepath)) {
+          file_delete($file->filepath);
+          form_set_error('upload', t('Uploaded image file does not appear to be a valid image file.  Please try again'));
+        } else {
+          user_badges_hold_temporary_file($file);
+        }
+      }
+      else {
+        form_set_error('upload', t('Cannot save image.  Enter the path to an image and try again.'));
+      }
+    }
+    else {
+      form_set_error('upload', t('Cannot save image - directory not writable'));
+    }
   }
-  else if ($form_values['op'] == t('Delete')) {
+  else if ($op == t('Delete')) {
     if (count(array_filter($form_values['images'])) == 0) {
       form_set_error('images', t('Please select images to delete.'));
     }
   }
 }
 
-function user_badges_images_form_submit($form_id, $form_values) {
-  $op = $form_values['op'];
+function user_badges_hold_temporary_file($file = NULL) {
+  static $static_file;
+  if (isset($file)) {
+    $static_file = $file;
+  }
+  return $file;
+}
+
+function user_badges_images_form_submit($form, &$form_state) {
+  $op = $form_state['clicked_button']['#value'];
+  $form_values = $form_state['values'];
   // Save uploaded files
   if ($op == t('Upload')) {
-    $dir = file_create_path('badges');
-    $is_writable = file_check_directory($dir, 1);
-    if ($is_writable) {
-      if( $source = file_check_upload('upload')) {
-        // Security measure to prevent exploit of file.php.png
-        $source->filename = upload_munge_filename($source->filename);
-        if ($file = file_save_upload($source, $dir)) {
-          if (image_get_info($file->filepath)) {
-            drupal_set_message(t('New image saved.'));
-          } else {
-            file_delete($file->filepath);
-            drupal_set_message('Uploaded file does not appear to be a valid image file. Please try again.');
-          }
-        }
-      }
-    }
+    $file = user_badges_hold_temporary_file();
+    file_set_status($file, FILE_STATUS_PERMANENT);
   }
   else if ($op == t('Delete')) {
     foreach ($form_values['images'] as $path => $is_removed) {
@@ -461,8 +465,9 @@ function user_badges_roles_form() {
   return $form;
 }
 
-function user_badges_roles_form_submit($form_id, $form_values) {
-	user_badges_save_roles($form_values['roles']);
+function user_badges_roles_form_submit($form, &$form_state) {
+  $form_values = $form_state['values'];
+  user_badges_save_roles($form_values['roles']);
 }
 
 /**
@@ -477,10 +482,10 @@ function user_badges_roles_form_submit($
 function user_badges_get_badges($uid) {
   $badges = array();
   if ($uid == 'all' || $uid == 'select') {
-    $sql = db_query('SELECT b.bid, b.name, b.image FROM {user_badges_badges} b ORDER BY b.weight, b.name');
+    $sql = db_query('SELECT b.bid, b.weight, b.name, b.image FROM {user_badges_badges} b ORDER BY b.weight, b.name');
   }
   else {
-    $sql = db_query('SELECT DISTINCT b.bid, b.name, b.image FROM {user_badges_badges} b INNER JOIN {user_badges_user} u ON b.bid = u.bid WHERE u.uid = %d ORDER BY b.weight, b.name', $uid);
+    $sql = db_query('SELECT DISTINCT b.bid, b.weight, b.name, b.image FROM {user_badges_badges} b INNER JOIN {user_badges_user} u ON b.bid = u.bid WHERE u.uid = %d ORDER BY b.weight, b.name', $uid);
   }
   while ($badge = db_fetch_object($sql)) {
     if ($uid == 'select') {
@@ -505,7 +510,7 @@ function user_badges_get_badge($bid) {
  * Define the edit form for userbadges.
  *
  */
-function user_badges_edit_form($bid = NULL) {
+function user_badges_edit_form($form_state, $bid = NULL) {
   if (is_numeric($bid)) {
     $edit = db_fetch_object(db_query('SELECT * FROM {user_badges_badges} WHERE bid = %d', $bid));
     if (is_numeric($edit->bid)) {
@@ -521,7 +526,7 @@ function user_badges_edit_form($bid = NU
   '#default_value' => $edit->name,
   '#size' => 40,
   '#maxlength' => 100,
-  '#description' => t('Name for the badge.<br/>Will be displayed as tooltip when rolling over badge image.<br/>'),
+  '#description' => t('Name for the badge. Will be displayed as tooltip when rolling over badge image.'),
   '#attributes' => NULL,
   '#required' => TRUE,
   );
@@ -532,7 +537,7 @@ function user_badges_edit_form($bid = NU
     '#title' => t('Image'),
     '#default_value' => $edit->image,
     '#options' => $selects,
-    '#description' => t('Select an image to associate with this badge. Add more images '.l(t('here'), "admin/user/user_badges/images")),
+    '#description' => t('Select an image to associate with this badge. You can upload additional images on the <a href="@url">Images page</a>.', array('@url' => url("admin/user/user_badges/images"))),
   );
   }
   else {
@@ -558,25 +563,24 @@ function user_badges_edit_form($bid = NU
   */
 function user_badges_save_badge($edit) {
   $edit = (object)$edit;
-  if (is_numeric($edit->bid)) {
+  if (isset($edit->bid) && preg_match("/^[0-9]+$/D", $edit->bid)) {
     db_query('DELETE FROM {user_badges_badges} WHERE bid = %d', $edit->bid);
+    $result = db_query("INSERT INTO {user_badges_badges} (bid, name, image, weight) VALUES (%d, '%s', '%s', %d)", $edit->bid, $edit->name, $edit->image, $edit->weight);
+    drupal_set_message('Edited image');
+  } else {
+    $result = db_query("INSERT INTO {user_badges_badges} (name, image, weight) VALUES ('%s', '%s', %d)", $edit->name, $edit->image, $edit->weight);
+    drupal_set_message('Inserted new image');
   }
-  else {
-    $edit->bid = db_next_id('user_badges_badges');
-  }
-  $result = db_query("INSERT INTO {user_badges_badges} (bid, name, image, weight) VALUES (%d, '%s', '%s', %d)", $edit->bid, $edit->name, $edit->image, $edit->weight);
   if ($result) {
     drupal_set_message(t('Badge %badgename saved.', array('%badgename' => $edit->name)));
   }
   else {
     drupal_set_message(t('There was a problem saving the badge information into the database.'));
   }
-  drupal_goto('admin/user/user_badges');
-  return $result;
+  return 'admin/user/user_badges';
 }
 
-
-function user_badges_delete_form($bid) {
+function user_badges_delete_form($form_state, $bid) {
   if ($badge = user_badges_get_badge($bid)) {
     $form = array();
     $form['badge'] = array('#value' => theme('user_badge_group', array(theme('user_badge', $badge))));
@@ -586,20 +590,21 @@ function user_badges_delete_form($bid) {
   form_set_error('', t('This badge does not exist.'));
 }
 
-function user_badges_delete_form_submit($form_id, $form_values) {
+function user_badges_delete_form_submit($form, &$form_state) {
+  $form_values = $form_state['values'];
   db_query("DELETE FROM {user_badges_badges} WHERE bid = %d", $form_values['bid']);
   db_query("DELETE FROM {user_badges_user} WHERE bid = %d", $form_values['bid']);
   db_query("DELETE FROM {user_badges_roles} WHERE bid = %d", $form_values['bid']);
   drupal_set_message(t('Badge deleted.'));
-  return 'admin/user/user_badges';
+  $form_state['redirect'] = 'admin/user/user_badges';
 }
 
 function user_badges_image_selects() {
   $selects = array();
-  $dir = file_create_path('badges').'/';
-  $listings = file_scan_directory($dir, '.*\.(gif|jpg|jpeg|png)', array('.', '..', 'CVS'), 0, FALSE);
-  foreach ($listings as $listing) {
-    $selects[$dir.$listing->basename] = theme('image', $dir.$listing->basename, $listing->basename, $listing->basename);
+  $dir = file_create_path('badges');
+  $files = file_scan_directory($dir, '.*\.(gif|jpg|jpeg|png)', array('.', '..', 'CVS'), 0, FALSE);
+  foreach ($files as $file) {
+    $selects[$file->filename] = theme('image', $file->filename, $file->filename, $file->filename);
   }
   return $selects;
 }
@@ -714,7 +719,7 @@ function user_badges_for_user($array) {
 
 function theme_user_badge_group($badgeimages) {
    if (!empty($badgeimages)) {
-    return "<div class='user_badges'>".implode('', $badgeimages)."</div>";
+    return '<div class="user_badges">'.implode('', $badgeimages)."</div>";
    }
 }
 
@@ -725,97 +730,3 @@ function theme_user_badge_group($badgeim
 function theme_user_badge($badge) {
   return theme('image', $badge->image, $badge->name, $badge->name);
 }
-
-
-
-function user_badges_products_page() {
-  $products = user_badges_get_product_list();
-  $badges = user_badges_get_products();
-  $selects = array(''=>'inactive') + user_badges_get_badges('select');
-  $form['products'] = array('#tree' => TRUE);
-  foreach($products as $key => $val) {
-      $form['products'][$key] = array(
-        '#type' => 'select',
-        '#title' => $val->title,
-        '#default_value' => $badges[$key],
-        '#options' => $selects,
-        '#description' => check_plain($val->sku),
-      );
-  }
-  $form[] = array(
-    '#type' => 'submit',
-    '#value' => 'Save',
-  );
-  $output = drupal_get_form('user_badges_products_page', $form);
-
-  return $output;
-}
-
-function user_badges_products_page_submit($form_id, $form_values) {
-  user_badges_save_products($form_values['products']);
-}
-
-function user_badges_save_products($edit) {
-  if (is_array($edit)) {
-    $success = TRUE;
-    db_query('DELETE FROM {user_badges_product}');
-    foreach ($edit as $nid => $bid) {
-      if ($bid) {
-        $success = $success && db_query('INSERT INTO {user_badges_product} (nid, bid) VALUES (%d, %d)', $nid, $bid);
-      }
-    }
-    if ($success) {
-      drupal_set_message(t('Products saved.'));
-    }
-    else {
-      drupal_set_message(t('There was a problem saving product information to the database'));
-    }
-  }
-}
-
-
-function user_badges_ecommerceapi($t, $op) {
-  switch ($op) {
-    case 'on payment completion':
-      $productbadges = user_badges_get_products();
-      foreach ($t['items'] as $item) {
-        if (array_key_exists($item->nid, $productbadges)) {
-          // no duplicates please...
-          db_query("DELETE FROM {user_badges_user} WHERE uid=%d AND bid=%d", $t['uid'], $productbadges[$item->nid]);
-          db_query("INSERT INTO {user_badges_user} (uid, bid, type) VALUES (%d, %d, 'product')", $t['uid'], $productbadges[$item->nid]);
-        }
-      }
-  }
-}
-
-function user_badges_get_sku($nid) {
-  return db_result(db_query('SELECT sku FROM {ec_product} WHERE nid = %d', $nid));
-}
-
-/**
-  * Get list of all ecommerce products
-  */
-
-function user_badges_get_product_list() {
-  $products = array();
-  $sql = db_query('SELECT p.*, n.title FROM {ec_product} p INNER JOIN {node} n ON p.nid = n.nid ORDER BY sku');
-  while ($row = db_fetch_object($sql)) {
-    $products[$row->nid] = $row;
-  }
-  return $products;
-}
-
-/**
-  * Get list of products that have badges
-  * keys are node ids (nid)
-  * values are badge ids (bid)
-  */
-
-function user_badges_get_products() {
-  $products = array();
-  $sql = db_query('SELECT * FROM {user_badges_product}');
-  while ($row = db_fetch_object($sql)) {
-    $products[$row->nid] = $row->bid;
-  }
-  return $products;
-}
Index: user_badges_products.info
===================================================================
RCS file: user_badges_products.info
diff -N user_badges_products.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ user_badges_products.info	3 Apr 2008 16:17:39 -0000
@@ -0,0 +1,11 @@
+; $Id: user_badges.info,v 1.1.2.1 2007/06/18 23:07:11 dww Exp $
+name = User Product Badges
+description = Enables assignment of graphical badges to users and roles.
+dependencies[] = user_badges
+dependencies[] = product
+
+; Information added by drupal.org packaging script on 2007-06-19
+version = "6.x-1.x-dev"
+project = "user_badges"
+datestamp = "1182212765"
+core = 6.x
Index: user_badges_products.install
===================================================================
RCS file: user_badges_products.install
diff -N user_badges_products.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ user_badges_products.install	3 Apr 2008 16:17:39 -0000
@@ -0,0 +1,10 @@
+<?php
+
+function user_badges_products_install() {
+  
+}
+
+function user_badges_products_uninstall() {
+  
+}
+
Index: user_badges_products.module
===================================================================
RCS file: user_badges_products.module
diff -N user_badges_products.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ user_badges_products.module	3 Apr 2008 16:17:39 -0000
@@ -0,0 +1,115 @@
+<?php
+
+function user_badges_help($section) {
+  switch ($section) {
+    case 'admin/modules#description':
+      // This description is shown in the listing at admin/modules.
+      return t('Assign badges to ecommerce products');
+    case 'admin/settings/user_badges/products':
+      return t("For each ecommerce product listed below, select the badge that will be assigned to users upon payment completion.");
+  }
+}
+
+function user_badges_products_menu() {
+  $items = array();
+  $items['admin/user/user_badges/products'] = array(
+    'title' => 'Products',
+    'page callback' => 'user_badges_products_page',
+    'access arguments' => user_badges_perm(),
+    'weight' => 8,
+    'type' => MENU_LOCAL_TASK,
+  );
+  return $items;
+}
+
+function user_badges_products_page($form_state) {
+  $products = user_badges_products_get_product_list();
+  $badges = user_badges_products_get_products();
+  $selects = array(''=>'inactive') + user_badges_get_badges('select');
+  $form['products'] = array('#tree' => TRUE);
+  foreach($products as $key => $val) {
+      $form['products'][$key] = array(
+        '#type' => 'select',
+        '#title' => $val->title,
+        '#default_value' => $badges[$key],
+        '#options' => $selects,
+        '#description' => check_plain($val->sku),
+      );
+  }
+  $form[] = array(
+    '#type' => 'submit',
+    '#value' => 'Save',
+  );
+  $output = drupal_get_form('user_badges_products_page', $form);
+
+  return $output;
+}
+
+function user_badges_products_page_submit($form, &$form_state) {
+  $form_values = $form_state['values'];
+  user_badges_products_save_products($form_values['products']);
+}
+
+function user_badges_products_save_products($edit) {
+  if (is_array($edit)) {
+    $success = TRUE;
+    db_query('DELETE FROM {user_badges_product}');
+    foreach ($edit as $nid => $bid) {
+      if ($bid) {
+        $success = $success && db_query('INSERT INTO {user_badges_product} (nid, bid) VALUES (%d, %d)', $nid, $bid);
+      }
+    }
+    if ($success) {
+      drupal_set_message(t('Products saved.'));
+    }
+    else {
+      drupal_set_message(t('There was a problem saving product information to the database'));
+    }
+  }
+}
+
+
+function user_badges_products_ecommerceapi($t, $op) {
+  switch ($op) {
+    case 'on payment completion':
+      $productbadges = user_badges_products_get_products();
+      foreach ($t['items'] as $item) {
+        if (array_key_exists($item->nid, $productbadges)) {
+          // no duplicates please...
+          db_query("DELETE FROM {user_badges_user} WHERE uid=%d AND bid=%d", $t['uid'], $productbadges[$item->nid]);
+          db_query("INSERT INTO {user_badges_user} (uid, bid, type) VALUES (%d, %d, 'product')", $t['uid'], $productbadges[$item->nid]);
+        }
+      }
+  }
+}
+
+function user_badges_products_get_sku($nid) {
+  return db_result(db_query('SELECT sku FROM {ec_product} WHERE nid = %d', $nid));
+}
+
+/**
+  * Get list of all ecommerce products
+  */
+
+function user_badges_products_get_product_list() {
+  $products = array();
+  $sql = db_query('SELECT p.*, n.title FROM {ec_product} p INNER JOIN {node} n ON p.nid = n.nid ORDER BY sku');
+  while ($row = db_fetch_object($sql)) {
+    $products[$row->nid] = $row;
+  }
+  return $products;
+}
+
+/**
+  * Get list of products that have badges
+  * keys are node ids (nid)
+  * values are badge ids (bid)
+  */
+function user_badges_products_get_products() {
+  $products = array();
+  $sql = db_query('SELECT * FROM {user_badges_product}');
+  while ($row = db_fetch_object($sql)) {
+    $products[$row->nid] = $row->bid;
+  }
+  return $products;
+}
