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/help/custom', 'title' => t('customize'), 'callback' => 'helpedit_list_page', 'access' => user_access('customize help') ); $items[] = array( 'path' => 'admin/help/custom/edit', 'title' => t('edit message'), 'callback' => 'helpedit_edit_page', 'access' => user_access('customize help'), 'type' => MENU_CALLBACK ); $items[] = array( 'path' => 'admin/help/custom/save', 'title' => t('save message'), 'callback' => 'helpedit_save_page', 'access' => user_access('customize help'), 'type' => MENU_CALLBACK ); $items[] = array( 'path' => 'admin/help/custom/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 = ''. ''; $result = db_query(' SELECT * FROM {help} ORDER BY path '); while ($help = db_fetch_object($result)) { $content .= ''. ''. ''. ''. ''; } $content .= '
PathTypeMessageOperations
'.$help->path.''.($help->path_type==0?'exact':'fuzzy').''.$help->body.''. l('edit','admin/help/custom/edit/'.$help->hid).' '. l('delete','admin/help/custom/delete/'.$help->hid). '

'. l('new help message','admin/help/custom/edit'); print theme('page', $content); } /** * Page to edit a help message. */ function helpedit_edit_page ($hid = 0) { if ($hid) { $help = helpedit_load($hid); } $form = array(); $form['#method'] = 'post'; $form['#action'] = url('admin/help/custom/save'); $form['path'] = array('#type' => 'textfield', '#title' => t('Path'), '#default_value' => $help['path'], '#size' => 50, '#maxlength' => 64, '#description' => 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/%).'), '#required' => TRUE); $form['path_type'] = array('#type' => 'radios', '#title' => t('Match type'), '#options' => array(t('Exact match'), t('Fuzzy Match')), '#description' => t('Exact match means the path you entered must match the request path exactly for this help message to be displayed. Fuzzy matching allows you to use % as a wildcard in the path.')); $form['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $help['body'], '#cols' => 50, '#rows' => 6, '#required' => TRUE); $form['hid'] = array('#type' => 'hidden', '#value' => $help['hid']); $form['op'] = array('#type' => 'submit', '#value' => t('Update message')); return drupal_get_form('helpedit', $form); } /** * Save a edited help meesage. */ function helpedit_save_page () { $vars = $_POST['edit']; $path = $vars['path']; $path_type = $vars['path_type']; $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 ); 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 ); drupal_set_message(t('The message has been saved.')); } drupal_goto('admin/help/custom'); } /** * Delete a help message. */ function helpedit_delete_page ($hid = 0) { db_query('DELETE FROM {help} WHERE hid = %d', $hid); drupal_set_message(t('The help message has been deleted.')); drupal_goto('admin/help/custom'); } ?>