Index: award.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/award/award.info,v retrieving revision 1.2 diff -u -p -r1.2 award.info --- award.info 11 Feb 2008 21:04:02 -0000 1.2 +++ award.info 8 Sep 2008 02:52:59 -0000 @@ -1,4 +1,10 @@ ; $Id: award.info,v 1.2 2008/02/11 21:04:02 joshbenner Exp $ name = Award -description = Allows node types to be specified as awards and given to users by those with permission \ No newline at end of file +description = Allows node types to be specified as awards and given to users by those with permission +core = "6.x" +; Information added by drupal.org packaging script on 2008-02-11 +version = "6.x-1.0" +project = "award" +datestamp = "1202765701" + Index: award.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/award/award.install,v retrieving revision 1.2 diff -u -p -r1.2 award.install --- award.install 11 Feb 2008 21:05:23 -0000 1.2 +++ award.install 8 Sep 2008 02:52:59 -0000 @@ -5,23 +5,62 @@ * @file Award Module install file */ +function award_schema() { + + $schema['award_grants'] = array( + 'fields' => array( + 'aid' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'length' => 11, + ), + 'uid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'length' => 11, + ), + 'nid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'length' => 11, + ), + 'granted_by' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'length' => 11, + ), + 'granted_time' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'length' => 11, + ), + 'grant_reason' => array( + 'type' => 'text', + ), + ), + 'unique keys' => array( + 'uid' => array('uid'), + 'nid' => array('nid'), + ), + 'primary key' => array('aid'), + ); + + return $schema; +} + /** * Implementation of hook_install() */ function award_install() { - db_query(" - CREATE TABLE {award_grants} ( - aid int(11) unsigned not null auto_increment, - uid int(11) unsigned not null, - nid int(11) unsigned not null, - granted_by int(11) unsigned not null, - granted_time int(11) unsigned not null, - grant_reason TEXT, - key (uid, nid), - primary key (aid) - ) /*!40100 DEFAULT CHARACTER SET utf8 */;" - ); - + $ret = drupal_install_schema('award'); + drupal_set_message('about to ask for success var'); + drupal_set_message($ret['success']); + drupal_set_message($ret['query']); drupal_set_message(t('Awards module installed. Database table created.')); } @@ -29,8 +68,7 @@ function award_install() { * Implementation of hook_uninstall() */ function award_uninstall() { - variable_del('award_content_types'); - db_query('DROP TABLE IF EXISTS {award_grants}'); + $ret = drupal_uninstall_schema('award'); + drupal_set_message(t('Award module uninstalled. Database table removed.')); } -?> \ No newline at end of file Index: award.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/award/award.module,v retrieving revision 1.2 diff -u -p -r1.2 award.module --- award.module 11 Feb 2008 21:05:23 -0000 1.2 +++ award.module 8 Sep 2008 02:52:59 -0000 @@ -8,26 +8,27 @@ /** * Implementation of hook_menu() */ -function award_menu($may_cache) { +function award_menu() { + $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'admin/settings/award', - 'title' => t('Award Settings'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('award_admin_settings'), - 'access' => user_access('administer awards'), - 'type' => MENU_NORMAL_ITEM, - ); - $items[] = array( - 'path' => 'award/revoke', - 'title' => t('Revoke Award'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('award_revoke_confirm'), - 'access' => user_access('revoke awards'), - 'type' => MENU_CALLBACK, - ); - } + + $items['admin/settings/award'] = array( + 'title' => 'Award Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('award_admin_settings'), + 'access callback' => 'user_access', + 'access arguments' => array('administer awards'), + 'type' => MENU_NORMAL_ITEM, + ); + $items['award/revoke'] = array( + 'title' => 'Revoke Award', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('award_revoke_confirm'), + 'access callback' => 'user_access', + 'access arguments' => array('revoke awards'), + 'type' => MENU_CALLBACK, + ); + return $items; } @@ -47,6 +48,7 @@ function award_perm() { * Implementation of hook_user() */ function award_user($op, &$edit, &$account, $category = NULL) { + switch ($op) { case 'load': $r = db_query("SELECT * FROM {award_grants} WHERE uid=%d ORDER BY granted_time", $account->uid); @@ -57,17 +59,18 @@ function award_user($op, &$edit, &$accou } break; case 'view': - $items[] = array( - 'title' => '', - 'value' => theme('awards_display', $account), - 'class' => 'awards', + $account->content[] = array( + '#title' => '', + '#value' => theme('awards_display', $account), + '#class' => 'awards', ); - $items[] = array( - 'title' => '', - 'value' => drupal_get_form('award_grant_form', $account), - 'class' => 'grant_award', + + $account->content[] = array( + '#title' => '', + '#value' => drupal_get_form('award_grant_form', $account), + '#class' => 'grant_award', ); - return array(t('Awards')=>$items); + break; } } @@ -109,8 +112,8 @@ function award_admin_settings() { $form['award_content_types'] = array( '#type' => 'select', '#title' => t('Award Node Types'), - '#description' => t('Select all node types which are to be able to be granted as awards. Be sure to grant appropriate permissions in !link', array('!link'=>l(t('Access Control'), 'admin/user/access'))), - '#multiple' => true, + '#description' => t('Select all node types which are to be able to be granted as awards. Be sure to grant appropriate permissions in !link', array('!link' => l(t('Access Control'), 'admin/user/permissions'))), + '#multiple' => TRUE, '#options' => node_get_types('names'), '#default_value' => variable_get('award_content_types', array()), ); @@ -123,22 +126,25 @@ function award_admin_settings() { * @ingroup forms * @ingroup themable */ -function award_grant_form($account) { +function award_grant_form(&$node, $account) { global $user; $form = array(); $types = award_get_award_content_types($account, $user); if ($types) { $_types = implode("','", $types); - $anodes = db_query("SELECT nid,title FROM {node} WHERE type IN ('$_types')"); + $placeholders = implode("','", array_fill(0, count($types), '%s')); + + $anodes = db_query("SELECT nid,title FROM {node} WHERE type IN ('" . $placeholders . "')", $types); $awards = array(); while ($anode = db_fetch_object($anodes)) { $awards[$anode->nid] = $anode->title; } + $form['grant'] = array( '#type' => 'fieldset', '#title' => t('Grant an Award'), - '#collapsible' => true, - '#collapsed' => true, + '#collapsible' => TRUE, + '#collapsed' => TRUE, ); $form['grant']['target'] = array( '#type' => 'hidden', @@ -160,8 +166,9 @@ function award_grant_form($account) { '#type' => 'submit', '#value' => t('Grant Award'), ); - } elseif (user_access('administer awards') || user_access('administer site configuration')) { - $form[]['#value'] = t('No award types have been specified that this user may receive. Please visit !link.', array('!link'=>l(t('Award Settings'), 'admin/settings/award'))); + } + elseif (user_access('administer awards') || user_access('administer site configuration')) { + $form[]['#value'] = t('No award types have been specified that this user may receive. Please visit !link.', array('!link' => l(t('Award Settings'), 'admin/settings/award'))); } return $form; } @@ -169,9 +176,10 @@ function award_grant_form($account) { /** * Validates award_grant_form */ -function award_grant_form_validate($form_id, &$values) { - if (!($node = node_load($values['award_id']))) { - form_set_error('award_id', t('Award node not found')); +function award_grant_form_validate($form, &$form_state) { + + if (!($node = node_load($form_state['values']['award_id']))) { + form_set_error('award_id', t('Award node not found!')); } elseif (!in_array($node->type, award_get_award_content_types())) { form_set_error('award_id', t('Specified node is not a valid award type!')); @@ -179,33 +187,35 @@ function award_grant_form_validate($form else { $type = node_get_types('type', $node); } - if ($target = user_load(array('uid'=>$values['target']))) { + if ($target = user_load(array('uid' => $form_state['values']['target']))) { if (!user_access("receive {$node->type} awards")) { - form_set_error(NULL, t('User is not authorized to receive @type awards', array('@type'=>$type->name))); + form_set_error(NULL, t('User is not authorized to receive @type awards', array('@type' => $type->name))); } if (!user_access("grant {$node->type} awards")) { - form_ser_error(NULL, t('You are not authorized to grant @type awards', array('@type'=>$type->name))); + form_ser_error(NULL, t('You are not authorized to grant @type awards', array('@type' => $type->name))); } - } else { + } + else { form_set_error(NULL, t('Unknown user')); } + } /** * Processes submit for award_grant_form */ -function award_grant_form_submit($form_id, $values) { +function award_grant_form_submit($form, &$form_state) { global $user; db_query("INSERT INTO {award_grants} (uid,nid,granted_by,granted_time,grant_reason) VALUES (%d,%d,%d,%d,'%s')", - $values['target'], - $values['award_id'], + $form_state['values']['target'], + $form_state['values']['award_id'], $user->uid, time(), - $values['award_reason'] + $form_state['values']['award_reason'] ); - $award = node_load($values['award_id']); - $recipient = user_load(array('uid'=>$values['target'])); - drupal_set_message(t('!award has been granted to !user', array('!award'=>l($award->title, "node/{$award->nid}"), '!user'=>theme('username', $recipient)))); + $award = node_load($form_state['values']['award_id']); + $recipient = user_load(array('uid' => $form_state['values']['target'])); + drupal_set_message(t('!award has been granted to !user', array('!award' => l($award->title, "node/{$award->nid}"), '!user' => theme('username', $recipient)))); } /** @@ -217,13 +227,12 @@ function award_grant_form_submit($form_i * @param integer $aid * The ID of the award grant to revoke */ -function award_revoke_confirm($aid) { +function award_revoke_confirm(&$node, $aid) { if (is_numeric($aid)) { if ($grant = award_get_grant($aid)) { - $grant = db_fetch_object($r); $award = node_load($grant->nid); - $account = user_load(array('uid'=>$grant->uid)); - $granter = user_load(array('uid'=>$grant->granted_by)); + $account = user_load(array('uid' => $grant->uid)); + $granter = user_load(array('uid' => $grant->granted_by)); $vars = array( '!award' => l($award->title, "node/{$award->nid}"), '!user' => theme('username', $account), @@ -233,7 +242,8 @@ function award_revoke_confirm($aid) { $q = t('Are you sure you wish to revoke !award granted to !user by !granter on !time?', $vars); $form['aid'] = array('#type' => 'value', '#value' => $aid); return confirm_form($form, $q, "user/{$account->uid}", NULL, t('Revoke')); - } else { + } + else { drupal_not_found(); exit; } @@ -247,20 +257,21 @@ function award_revoke_confirm($aid) { /** * Process a confirmed award revocation */ -function award_revoke_confirm_submit($form_id, $values) { - if ($values['confirm'] && $grant = award_get_grant($values['aid'])) { - award_revoke($values['aid']); +function award_revoke_confirm_submit($form, &$form_state) { + + if ($form_state['values']['confirm'] && $grant = award_get_grant($form_state['values']['aid'])) { + award_revoke($form_state['values']['aid']); $award = node_load($grant->nid); - $account = user_load(array('uid'=>$grant->uid)); - $granter = user_load(array('uid'=>$grant->granted_by)); + $account = user_load(array('uid' => $grant->uid)); + $granter = user_load(array('uid' => $grant->granted_by)); $vars = array( '!award' => l($award->title, "node/{$award->nid}"), '!user' => theme('username', $account), '!granter' => theme('username', $granter), '!time' => format_date($grant->granted_time, 'short'), ); - drupal_set_message(t('Award Revoked: !award granted to !user by !granted on !time')); - return "user/{$account->uid}"; + drupal_set_message(t('Award Revoked: !award granted to !user by !granter on !time', $vars)); + $form_state['redirect'] = "user/{$account->uid}"; } } @@ -291,7 +302,8 @@ function award_get_award_content_types($ $receivable[] = $t; } } - } else { + } + else { $receivable = $_types; } if ($granter) { @@ -300,7 +312,8 @@ function award_get_award_content_types($ $grantable[] = $t; } } - } else { + } + else { $grantable = $_types; } return array_intersect($receivable, $grantable); @@ -317,17 +330,20 @@ function award_get_award_content_types($ * HTML for output to browser */ function theme_awards_display($account) { + $header = array(t('Award'), t('Granted By'), t('Granted On'), t('Reason')); if ($revoke = user_access('revoke awards')) { $header[] = t('Revoke'); } + if (!$account->awards) { - $account = user_load(array('uid'=>$account->uid)); + $account = user_load(array('uid' => $account->uid)); } + foreach ($account->awards as $award) { $row = array(); $row[] = $award->award->title; - $granter = user_load(array('uid'=>$award->granted_by)); + $granter = user_load(array('uid' => $award->granted_by)); $row[] = theme('username', $granter); $row[] = format_date($award->granted_time, 'short'); $row[] = check_plain($award->grant_reason); @@ -339,12 +355,20 @@ function theme_awards_display($account) if (!$data) { $data[] = array( array( - 'colspan' => 4, + 'colspan' => 5, 'data' => t('This user has not received any awards'), ), ); } + print(implode("','", $data)->data); $out .= theme('table', $header, $data); return $out; } -?> \ No newline at end of file + +function award_theme() { + return array( + 'awards_display' => array( + 'arguments' => array('account' => NULL), + ), + ); +} \ No newline at end of file