'userpoints', 'callback' => 'userpoints_list_users', 'title' => t('users by points'), 'access' => user_access(USERPOINTS_PERM_VIEW), 'type' => MENU_NORMAL_ITEM); $items[] = array( 'path' => 'userpoints_reset', 'callback' => 'userpoints_reset', 'title' => t('reset points'), 'access' => user_access(USERPOINTS_PERM_ADMIN), 'type' => MENU_NORMAL_ITEM); return $items; } function userpoints_perm() { return array (USERPOINTS_PERM_VIEW, USERPOINTS_PERM_USE, USERPOINTS_PERM_ADMIN); } function userpoints_reset() { $form['confirm'] = array( '#type' => 'textfield', '#title' => t('Reset all user points. This is useful in certain situations such as monthly contests. Enter YES without quotes to reset'), '#size' => 3, '#maxlength' => 3, '#default_value' => t('NO')); $form['reset'] = array( '#type' => 'submit', '#value' => t('Reset')); return drupal_get_form('userpoints_reset', $form); } function userpoints_reset_submit($form_id, $edit) { if ($edit['confirm'] == t('YES')) { db_query('DELETE FROM {userpoints}'); drupal_set_message(t('All user points have been reset!')); } drupal_goto(); } function userpoints_settings() { $group = 'points'; $form[$group] = array( '#type' => 'fieldset', '#collapsible' => true, '#title' => t('Points for each event'), ); foreach(node_get_types() as $type => $name) { $form[$group][USERPOINTS_POST. $type] = array( '#type' => 'textfield', '#title' => t('Points for posting a %node-name', array('%node-name' => $name)), '#default_value' => variable_get(USERPOINTS_POST. $type, '0'), '#size' => 5, '#maxlength' => 5, ); } $form[$group][USERPOINTS_POST_COMMENT] = array( '#type' => 'textfield', '#title' => t('Points for posting a comment'), '#default_value' => variable_get(USERPOINTS_POST_COMMENT, 0), '#size' => 5, '#maxlength' => 5, ); $form[$group][USERPOINTS_MODERATE_COMMENT] = array( '#type' => 'textfield', '#title' => t('Points for moderating a comment'), '#default_value' => variable_get(USERPOINTS_MODERATE_COMMENT, 0), '#size' => 5, '#maxlength' => 5, ); if (module_exist('nodevote')) { $form[$group][USERPOINTS_NODEVOTE] = array( '#type' => 'textfield', '#title' => t('Points for voting on a node (requires nodevote module)'), '#default_value' => variable_get(USERPOINTS_NODEVOTE, 0), '#size' => 5, '#maxlength' => 5, ); } if (module_exist('user_referral')) { $form[$group][USERPOINTS_REFERRAL] = array( '#type' => 'textfield', '#title' => t('Points for referring a user (requires the user_referral module)'), '#default_value' => variable_get(USERPOINTS_REFERRAL, 0), '#size' => 5, '#maxlength' => 5, ); } if (module_exist('invite')) { $form[$group][USERPOINTS_INVITE_INVITE] = array( '#type' => 'textfield', '#title' => t('Points for inviting a user (requires the invite module)'), '#default_value' => variable_get(USERPOINTS_INVITE_INVITE, 0), '#size' => 5, '#maxlength' => 5, ); } if (module_exist('invite')) { $form[$group][USERPOINTS_INVITE_REGISTER] = array( '#type' => 'textfield', '#title' => t('Points when invited user registers (requires the invite module)'), '#default_value' => variable_get(USERPOINTS_INVITE_REGISTER, 0), '#size' => 5, '#maxlength' => 5, ); } if (module_exist('cart') && module_exist('payment')) { $group = 'ecommerce'; $form[$group] = array( '#type' => 'fieldset', '#collapsible' => true, '#collapsed' => true, '#title' => t('Ecommerce Options'), ); $form[$group][USERPOINTS_EC_EARN] = array( '#type' => 'textfield', '#title' => t('Points awarded for buying (multiplied by price)'), '#default_value' => variable_get(USERPOINTS_EC_EARN, 0), '#size' => 5, '#maxlength' => 5, ); $form[$group][USERPOINTS_MIN_PURCHASE] = array( '#type' => 'textfield', '#title' => t('Smallest purchase for which points are awarded'), '#default_value' => variable_get(USERPOINTS_MIN_PURCHASE, '0.00'), '#size' => 5, '#maxlength' => 5, ); $form[$group][USERPOINTS_EC_PAYMENT] = array( '#type' => 'radios', '#title' => t('Accept user points as payment?'), '#default_value' => variable_get(USERPOINTS_EC_PAYMENT, 0), '#options' => array(t('Disable'), t('Enable')), ); $form[$group][USERPOINTS_EC_SPEND] = array( '#type' => 'textfield', '#title' => t('Points used in payment (for every dollar)'), '#default_value' => variable_get(USERPOINTS_EC_SPEND, 1), '#size' => 5, '#maxlength' => 5, ); $form[$group][USERPOINTS_MIN_SPEND] = array( '#type' => 'textfield', '#title' => t('Number of points that must be spent per purchase'), '#default_value' => variable_get(USERPOINTS_MIN_SPEND, '0'), '#size' => 5, '#maxlength' => 5, ); } $group = 'advanced'; $form[$group] = array( '#type' => 'fieldset', '#collapsible' => true, '#collapsed' => true, '#title' => t('Advanced Options'), ); $form[$group]['reset'] = array( '#title' => t('Reset points'), '#value' => l(t('Reset the points for all users.'), 'userpoints_reset'), ); return $form; } function userpoints_user($op, &$edit, &$user, $category = '') { switch($op) { case 'delete': db_query('DELETE FROM {userpoints} WHERE uid = %d', $user->uid); break; case 'view': $points = (int) db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d', $user->uid)); $disp_points[] = array( 'title' => t('User points'), 'value' => $points, ); return array(t('Points') => $disp_points); break; } } function userpoints_list_users() { $sql = "SELECT p.uid, u.name, p.points FROM {userpoints} p INNER JOIN {users} u WHERE u.uid = p.uid GROUP BY p.uid"; $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {userpoints}"; $header = array( array('data' => t('User'), 'field' => 'u.name'), array('data' => t('Points'), 'field' => 'p.points', 'sort' => 'desc'), ); $sql .= tablesort_sql($header); $result = pager_query($sql, 30, 0, $sql_cnt); while ($data = db_fetch_object($result)) { $rows[] = array( array('data' => theme('username', $data)), array('data' => $data->points, 'align' => 'right'), ); } $output = theme('table', $header, $rows); $output .= theme('pager', NULL, 30, 0); return $output; } function userpoints_block($op = 'list', $delta = 0, $edit = array()) { global $user; $num = 5; $block_title = array(); $block_title[] = t('%user\'s points', array('%user' => $user->name)); $block_title[] = t('Highest users'); switch ($op) { case 'list': $blocks[0]['info'] = $block_title[0]; $blocks[1]['info'] = $block_title[1]; return $blocks; case 'view': if (user_access(USERPOINTS_PERM_VIEW)) { switch ($delta) { case 0: $title = $block_title[$delta]; if ($user->uid) { $points = (int) db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d', $user->uid)); $content = t('You have %p %c', array('%p' => $points, '%c' => format_plural($points, 'point', 'points'))); } else { $content = t('Points are visible to logged in users only'); } break; case 1: $title = $block_title[$delta]; $result = db_query_range('SELECT p.uid, u.name, p.points FROM {userpoints} p, {users} u WHERE u.uid = p.uid GROUP BY p.uid ORDER BY p.points DESC', 0, $num); while ($data = db_fetch_object($result)) { $rows[] = array( array('data' => theme('username', $data)), array('data' => $data->points, 'align' => 'right')); } $header = array(t('User'), t('Points')); $content = theme('table', $header, $rows); $content .= '