./README.txt                                                                                        0100755 0000770 0000765 00000002072 10210255172 010521  0                                                                                                    ustar   tenk                                                                                                                                                                                                                                                   Every page in drupal can have a help message displayed to guide visitors 
to your site in to the proper usage of various features.  A clean install 
of Drupal does not provide any way of editing these help messages in a visual 
way.  If you want to add any help messages to your site you would need to 
write your own module, which many people do not know, or even want to know, 
how to do.

This module provides the ability to assign help messages to any page on a 
drupal site through a simple interface in the administration section of the
site.

Send comments to aran@electroniclife.org

Note: Tables still need to be written and SQL needs to be 
tested on other databases.  Until that happens helpedit only 
support MySQL.

Installation
--------
- Copy helpedit.module to your modules directory.
- Run the SQL in helpedit.mysql.
- Go to administer->modules and enable the helpedit module.
- Go to administer->users->configure->permissions and modify 
  the "customize help" permission to suite your needs.

Usage
--------
- Go to administer->help->custom to get started.

$id$
                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ./helpedit.module                                                                                   0100644 0000770 0000765 00000013720 10310646153 012033  0                                                                                                    ustar   tenk                                                                                                                                                                                                                                                   <?php
/* $Id: helpedit.module,v 1.1.2.2 2005/04/27 15:10:21 arandeltac Exp $ */


/**
 * Load help text from the DB.
 */
function helpedit_help($section) {
	$pathAlias = drupal_get_path_alias($_GET['q']); //added by IW
	global $user; //give access to current user info - JM
	
	$query = '
		SELECT body 
		FROM {help}
		JOIN (users, users_roles, help_roles)
		ON (help.hid=help_roles.hid 
			AND help_roles.rid=users_roles.rid 
			AND users.uid=users_roles.uid)
		WHERE 
			((path_type = 0 AND ("%1$s" = path OR "'.$pathAlias.'" = path)) OR 
			(path_type = 1 AND ("%1$s" LIKE path OR "'.$pathAlias.'" LIKE path)))
			AND users.uid='.$user->uid;	
	$result = db_query($query, $section);
	if ($result) {
		$help = db_fetch_object( $result );
		return t($help->body);
	}
}

/**
 * Declare permissions.
 */
function helpedit_perm() {
  return array(
    'customize help'
  );
}

/**
 * Declare administration pages.
 */
function helpedit_menu($may_cache) {
	$items = array();
	if ($may_cache) {
		$items[] = array(
			'path'     => 'admin/customhelp',
			'title'    => t('custom help'),
			'callback' => 'helpedit_list_page',
			'access'   => user_access('customize help')
		);
		$items[] = array(
			'path'     => 'admin/customhelp/edit',
			'title'    => t('edit message'),
			'callback' => 'helpedit_edit_page',
			'access'   => user_access('customize help'),
			'type'     => MENU_CALLBACK
		);
		$items[] = array(
			'path'     => 'admin/customhelp/save',
			'title'    => t('save message'),
			'callback' => 'helpedit_save_page',
			'access'   => user_access('customize help'),
			'type'     => MENU_CALLBACK
		);
		$items[] = array(
			'path'     => 'admin/customhelp/delete',
			'title'    => t('delete message'),
			'callback' => 'helpedit_delete_page',
			'access'   => user_access('customize help'),
			'type'     => MENU_CALLBACK
		);
	}
	return $items;
}

/**
 * Helper function for loading a help row.
 */
function helpedit_load($hid) {
	  return db_fetch_array(db_query('SELECT * FROM {help} WHERE hid = %d', $hid));
	}

/**
 * Page that lists all help messages and commands for creating/editing/deleteing.
 */
function helpedit_list_page () {
	$content = 
		'<table cellspacing="0">'.
		'<tr><th>Path</th><th>Type</th><th>Message</th><th>Operations</th></tr>';
	$result = db_query('
		SELECT * 
		FROM {help} 
		ORDER BY path
	');
	while ($help = db_fetch_object($result)) {
		$content .=
			'<tr class="light">'.
				'<td class="active">'.$help->path.'</td>'.
				'<td>'.($help->path_type==0?'exact':'fuzzy').'</td>'.
				'<td>'.$help->body.'</td>'.
				'<td>'.
					l('edit','admin/customhelp/edit/'.$help->hid).' '.
					l('delete','admin/customhelp/delete/'.$help->hid).
				'</td>';
	}
	$content .= 
		'</table><p>'.
		l('new help message','admin/customhelp/edit');
	print theme('page', $content);
}

/**
 * Page to edit a help message.
 */
function helpedit_edit_page ($hid = 0) {
  if ($hid) {
    $help = helpedit_load($hid);
   	
 	 $result = db_query('SELECT role.rid FROM {role}
  					JOIN (help_roles)
					ON help_roles.rid=role.rid 
					WHERE help_roles.hid="%d"',$hid);
	$selected =  array();
	while ($role = db_fetch_array($result)){
	  $selected[] = $role['rid'];
	}
  }
  	
	//added code to populate array with current roles - JM
  	$options = array();
 	$result = db_query('SELECT rid, name FROM {role}');
 	while($role = db_fetch_object($result)){
    	$options[$role->rid] = $role->name;
    }
    
  $content = form(
		form_textfield( t('Path'), 'path', $help['path'], 50, 64, t('The existing path you wish to provide a help message for. This can either be an exact path (like node/23) or an fuzzy path (like node/%).'), NULL, TRUE ).
		form_radio( t('Exact match'), 'path_type', '0', ($help['path_type']==0?TRUE:FALSE), t('The path you entered must match the request path exactly for this help message to be displayed.') ).
		form_radio( t('Fuzzy match'), 'path_type', '1', ($help['path_type']==1?TRUE:FALSE), t('Fuzzy matching allows you to use % as a wildcard in the path.') ).
		form_checkboxes( t('Choose Roles'), 'rid', $selected, $options, t('You must choose at least one role that this message will appear for.'), '',	TRUE).
		form_textarea( t('Body'), 'body', $help['body'], 50, 6, NULL, NULL, TRUE ).
    form_hidden('hid', $help['hid']).
    form_submit(t('Update message'))
	,'post',url('admin/customhelp/save'));


	print theme('page', $content);
}

/**
 * Save a edited help meesage.
 */
function helpedit_save_page () {
	$vars      = $_POST['edit'];
	$path      = $vars['path'];
	$path_type = $vars['path_type'];
	$rid       = $vars['rid'];
	$body      = $vars['body'];
	$hid       = $vars['hid'];
	
	if (!$hid) {
		db_query(
			'INSERT INTO {help} SET path="%s",path_type=%d,body="%s"', 
			$path, $path_type, $body
		);
		//the next three lines are a messy way of getting the hid of the recent row -JM
		$result = db_query('SELECT last_insert_id()');
		$LastInsert = db_fetch_array($result);
		$hid=array_pop($LastInsert);
		
		foreach($rid as $i){
			db_query('INSERT INTO {help_roles} (hid, rid) VALUES ("%d", "%d")',$hid, $i);
		}
		
		drupal_set_message(t('The message has been created.'));
	}
	else {
		db_query(
			'UPDATE {help} SET path="%s",path_type=%d,body="%s" WHERE hid=%d', 
			$path, $path_type, $body, $hid
		);
		
		db_query('DELETE FROM {help_roles} WHERE hid="%d"',$hid);
		foreach($rid as $i){
			db_query('INSERT INTO {help_roles} (hid, rid) VALUES ("%d", "%d")',$hid, $i);
		}
		drupal_set_message(t('The message has been saved.'));
	}
	drupal_goto('admin/customhelp');
}

/**
 * Delete a help message.
 */
function helpedit_delete_page ($hid = 0) {
  db_query('DELETE FROM {help} WHERE hid = %d', $hid);
  db_query('DELETE FROM {help_roles} WHERE hid="%d"',$hid); //removes all relationships & could be one query -JM
  drupal_set_message(t('The help message has been deleted.'));
  drupal_goto('admin/customhelp');
}

?>                                                ./helpedit.mysql                                                                                    0100644 0000770 0000765 00000000747 10307443040 011714  0                                                                                                    ustar   tenk                                                                                                                                                                                                                                                   -- $Id: helpedit.mysql,v 1.1.2.1 2005/02/27 05:28:26 arandeltac Exp $

--
-- Table structure for table 'help'
--

CREATE TABLE help (
  hid int(10) unsigned NOT NULL auto_increment,
	path varchar(64) NOT NULL default '',
	path_type tinyint(3) unsigned NOT NULL default '0',
  body longtext,
  PRIMARY KEY  (hid)
) TYPE=MyISAM;


CREATE TABLE help_roles (
  hid int(10) unsigned NOT NULL default '0',
  rid int(10) unsigned NOT NULL default '0',
  KEY (hid),
  KEY (rid)
) ENGINE=MyISAM;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          