Index: userpoints.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints.module,v retrieving revision 1.44.2.14.2.48 diff -u -p -r1.44.2.14.2.48 userpoints.module --- userpoints.module 6 Jan 2008 14:26:04 -0000 1.44.2.14.2.48 +++ userpoints.module 18 Jan 2008 05:03:32 -0000 @@ -15,6 +15,7 @@ define('USERPOINTS_TRANS_LCPOINT', define('USERPOINTS_TRANS_UNCAT', 'userpoints_trans_uncat'); define('USERPOINTS_STATUS', 'userpoints_status'); +define('USERPOINTS_ALLOW_NEGATIVE', 'userpoints_allow_negative'); define('USERPOINTS_POINTS_MODERATION', 'userpoints_points_moderation'); @@ -203,6 +204,22 @@ function userpoints_admin_settings() { '#description' => t('Select whether all !points should be approved automatically, or moderated, and require admin approval', userpoints_translation()), ); + $group = 'negative'; + $form[$group] = array( + '#type' => 'fieldset', + '#title' => t('Negative Points'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#weight' => -1, + ); + + $form[$group][USERPOINTS_ALLOW_NEGATIVE] = array( + '#type' => 'checkbox', + '#title' => t('Allow negative points'), + '#default_value' => variable_get(USERPOINTS_ALLOW_NEGATIVE, TRUE), + '#description' => t('Determines whether users will be allowed to use or spend more !points than they have.', userpoints_translation()), + ); + $group = 'renaming'; $form[$group] = array( '#type' => 'fieldset', @@ -506,6 +523,20 @@ function userpoints_userpointsapi($param // Load the user object that will be awarded the points $account = user_load(array('uid' => $params['uid'])); + + if (!variable_get(USERPOINTS_ALLOW_NEGATIVE, TRUE) && $params['points'] < 0) { + $current_points = userpoints_get_current_points($uid); + if (($current_points + $params['points']) < 0){ + return array( + 'status' => FALSE, + 'reason' => 'attempted to take away more points than the user has which + is not allowed on this site. + ', + ); + + } + } + // Call the _userpoints hook, and stop if one of them returns FALSE $rc = module_invoke_all('userpoints', 'points before', $params['points'], $account->uid, $params['event']);