hey i've got the book learnind drupal 6 module development and i love it !!!
but now i'm at chapter 6 and i wrote the code that they give for a administration module i've cleared all the php and syntax errors, granted the administer users permision for the authenticated users but i keep getting the acces denied paged here is the code i hope someone has some usefull help i think it's only neccasery to check out the functions emailusers_menu and emailusers_user but i posted the whole module just in case

thanxxx

<?php
// $Id$
/**
* This module provides an email interface for administrators.
* Using this module, administrators can send email to a user from the
* user's "view" page.
* @file
*/
/**
* implementation of hook_help()
*/

function emailusers_help($path, $arg){
if($path == 'admin/help#emailusers'){

$txt= ' This module provides a way for administrators to email users. It assumes that Drupal mailer is configured';
return '

'.t($txt).'

';
}
}

/**
* Implementation of hook_menu()
*/

function emailusers_menu(){
// Need to pass User ID here:
$items['admin/emailusers/compose/%'] = array(
'title' => 'Compose message',
'page callback' => 'emailusers_compose',
'page arguments' => array(3), // <- userID (from % in node path)
'acces arguments' => array('administer users'),
'type' => MENU_CALLBACK,);
return $items;
}

/**
* Compose a message.
* This creates the form necessary to compose an email message.
*
* @param $to
* The address to send to.
* @return
* HTML.
*/

function emailusers_compose($userid){
$userid = intval($userid);
if($userid == 0){
return t('User ID must be an integer');
}
$account = user_load($userid);
if (empty($account)){
return t('No such user found');
}
$to = $account->mail;
$sb= '

'. t('Send a email to @email.', array('@email' => $to)).'

';
$sb .= drupal_get_form('emailusers_compose_form', $account);
return $sb;
}

function emailusers_compose_form($content, $account){
// This is a value only -- equivalent to a hidden field, except
// that it is never rendered into the HTML.
$form['to'] = array(
'#type' => 'value',
'#value' => $account,);
// Create a fieldset for the body:
$form['message'] = array('#type' => 'fieldset', '#title' => t('Compose a message'),);
// Textfield for subject of the body
$form['message']['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#size' => 50,
'#maxlength' => 255,
'#description' => t('The subject of the email message'),);
// And a text area for the body.
$form['message']['body'] = array(
'#type' => 'textarea',
'#title' =>t('Message'),
'#cols' => 50,
'#rows' => 5,
'#description' => t('The body of the email message'),);
// Create a fieldset for details
$form['details'] = array(
'#type' => 'fieldset',
'#title' => t('Details'),);

// Checkbox: if checked, CC the author, too.
$form['details']['cc_me'] = array(
'#type' => 'checkbox',
'#title' => t('BCC yourself'),
'#default_value' => 1,
'#description' => t('If this is checked, the message wil also be send to you'),);
// Finally, a submit button:
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send mail'),);
}

/**
* Form submission handler, which functions like a hook.
* Note that the params $form and &$form_state are new in D6. They
* replace $form_id and $form_values.
*/

function emailusers_compose_form_submit($form, &$form_state){
$form_values = $form_state['values'];
$account = $form_values['to'];
drupal_mail('emailusers', 'composemessage', $account->mail, user_preferred_language($account), $form_values, variable_get('site_mail', null),true );
$form_state['redirect'] = sprintf('user/%d', $account->userid);
}

/**
* Implementation of hook_mail()
*/

function emailusers_mail($key, &$message, $params){
// Just catch calls to this hook from compose form.
if($key == 'composemessage'){
$language = $params['language'];
$account = $params['to'];
if($params['cc_me']){
// Look up current user's email address:
$my_account = user_load_current(null);
$message['header']['bcc'] = $my_account->mail;
}
$message['to'] = $account->mail;
$message['subject'] = t('Drupal message: '. array(), $language->language);
// If these were automatically-generated messages, they should be
// run through t(), but since text is user-entered, don't use
// t().
$message['subject'] .= $params['subject'];
$message['body'] = $params['body'];
}
}

/**
* Implements hook_mail_alter().
*/
function emailusers_mail_alter(&$message) {
$append = "\n=======================\n"
."This message was sent from !site_name (!website). "
."If you believe this message to be a case of abuse, "
."please contact !site_email.\n";
$args = array(
'!website' => url('', array('absolute' => true)),
'!site_email' => variable_get('site_mail', null),
'!site_name' => variable_get('site_name', 'Unknown'),
);
$message['body'] .= t($append, $args);
}

/**
* Implementation of hook_user().
*/

function emailusers_user($op, &$edit, &$account, $category){
if($op =='view' && user_access('administer users')){
// Create the outer "block"
$account->content['EmailUsers'] = array(
'#type' => 'user_profile_category',
'#attributes' => array('class' => 'user-member'),
'#weight' => 0,
'#title' => 'Contact User',);
// Create the content of the block
$account->content['EmailUsers']['EmailLink'] = array(
'#type' => 'user_profile_item',
'#title' => t('Send a message to this user from the site administrator'),
'#value' => l('Email','admin/emailusers/compose/'. $account->uid),);
}
}

Comments

yelvington’s picture

Computers are fussy about spelling.

'acces arguments' => array('administer users'),
dutchslab’s picture

I got the same book, and had NEARLY the same problem, also a typo ;)

A troubleshooting method I discovered was to download the code samples and errata from here:

http://www.packtpub.com/view_errata/book/drupal-6-module-development

Then replace their code with your code, and/or diff it to potentially narrow down the issue.

geremy