--- question.module 2006-04-16 01:40:44.000000000 -0500
+++ question.module.ak 2006-04-16 01:40:35.000000000 -0500
@@ -53,11 +53,11 @@
}
/**
- * Implementation of hook_node_name().
+ * Implementation of hook_node_info().
*
*/
-function question_node_name($node) {
- return t('question');
+function question_node_info() {
+ return array('question' => array('name' => t('question'), 'base' => 'question'));
}
/**
@@ -91,7 +91,8 @@
'access' => user_access('manage questions'));
$items[] = array('path' => 'admin/question', 'title' => t('questions'),
'access' => user_access('manage questions'), 'callback'=>'question_list_page');
- $items[] = array('path' => 'question', 'access' => TRUE, 'callback'=>'question_submit', 'title' => t('ask a question'));
+ $items[] = array('path' => 'question', 'title' => t('ask a question'),
+ 'access' => TRUE, 'callback'=>'question_add');
}
return $items;
@@ -102,30 +103,57 @@
*
*/
function question_form(&$node) {
- $output = '';
+
if (arg(2)=='question' && is_numeric(arg(3))) {
$que = db_fetch_object(db_query('SELECT * FROM {question_queue} WHERE qid = %d', arg(3)));
$node->questioner = $que->questioner;
$node->question = $que->question;
- $output .= form_hidden('qid', arg(3));
- }
-
- // In order to be able to attach taxonomy terms to this node, we need
- // to display the appropriate form elements.
- if (function_exists('taxonomy_node_form')) {
- $output .= implode('', taxonomy_node_form('question', $node));
- }
-
- $output .= form_textfield(t('Questioner'), 'questioner', $node->questioner, 60, 128, t("The person asking the question. Can be the user's id (uid), username, or an email address."));
+ $form['qid'] = array(
+ '#type' => 'hidden',
+ '#value' => arg(3),
+ );
+ }
+
+ $form['title'] = array('#type' => 'textfield',
+ '#title' => t('Subject'),
+ '#default_value' => $node->title,
+ '#size' => 60,
+ '#maxlength' => 128,
+ '#weight' => -8,
+ '#required' => TRUE);
+
+ $form['questioner'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Questioner'),
+ '#default_value' => $node->questioner,
+ '#size' => 60,
+ '#maxlength' => 128,
+ '#weight' => -7,
+ '#description' => t("The person asking the question. Can be the user's id (uid), username, or an email address."),
+ );
// Now we define the form elements specific to our node type.
- $output .= form_textarea(t('Question'), 'question', $node->question, 60, 20);
- $output .= filter_form('q_format', $node->q_format);
-
- $output .= form_textarea(t('Answer'), 'answer', $node->answer, 60, 20);
- $output .= filter_form('a_format', $node->a_format);
+ $form['question'] = array('#weight' => -6);
+ $form['question']['question'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Question'),
+ '#default_value' => $node->question,
+ '#cols' => 60,
+ '#rows' => 20
+ );
+ $form['question']['q_format'] = filter_form($node->q_format, 10, array('q_format'));
+
+ $form['answer'] = array('#weight' => -5);
+ $form['answer']['answer'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Answer'),
+ '#default_value' => $node->answer,
+ '#cols' => 60,
+ '#rows' => 20
+ );
+ $form['answer']['a_format'] = filter_form($node->a_format, 10, array('a_format'));
- return $output;
+ return $form;
}
/**
@@ -182,9 +210,22 @@
function question_settings() {
// require users to be registered in order to ask questions?
- $output .= form_checkbox(t('Require registered users?'), 'question_require_registered', 1, variable_get('question_require_registered', FALSE), t('Should we require users to be authenticated in order to submit questions?'));
- $output .= form_textfield(t('Path to "Thank You" node'), 'question_thanks', variable_get('question_thanks', FALSE), 40, 100, t('This is where users will end up after they submit the question form. Example: "node/454".
Leave blank and user will be returned to the form page with a thank you message.'));
- return $output;
+ $form['question_require_registered'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Require registered users?'),
+ '#return_value' => 1,
+ '#default_value' => variable_get('question_require_registered', FALSE),
+ '#description' => t('Should we require users to be authenticated in order to submit questions?'),
+);
+ $form['question_thanks'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Path to "Thank You" node'),
+ '#default_value' => variable_get('question_thanks', FALSE),
+ '#size' => 40,
+ '#maxlength' => 100,
+ '#description' => t('This is where users will end up after they submit the question form. Example: "node/454".
Leave blank and user will be returned to the form page with a thank you message.'),
+ );
+ return $form;
}
@@ -196,15 +237,18 @@
}
switch ($op) {
case 'delete':
- $hidden = form_hidden('qid', $qid);
- $output = theme('confirm', t('Are you sure you want to delete this item?'), 'admin/question', NULL, NULL, NULL, $hidden);
+ $form['qid'] = array(
+ '#type' => 'hidden',
+ '#value' => $qid
+ );
+ return confirm_form('question_queue_item_delete', $form, t('delete question'), 'admin/question', t('Are you sure you want to delete this question?'));
break;
default:
$headers = array(t('Question'), t('Operations'));
$sql = 'SELECT * FROM {question_queue} ORDER BY qid DESC';
$result = pager_query($sql);
while ($r = db_fetch_object($result)) {
- $rows[$r->qid]['question']['data'] = ''.$r->questioner.'
'.check_output($r->question);
+ $rows[$r->qid]['question']['data'] = ''.$r->questioner.'
'.check_markup($r->question);
$rows[$r->qid]['question']['style'] = 'vertical-align:top;border-bottom:solid 1px #666;';
$rows[$r->qid]['operations']['data'] = l(t('delete'), 'admin/question/delete/'.$r->qid).' '.l(t('promote'), 'node/add/question/'.$r->qid, array('title'=>t('create a question node based on this submission')));
$rows[$r->qid]['operations']['style'] = 'vertical-align:top;border-bottom:solid 1px #666;';
@@ -212,59 +256,7 @@
$output = theme('table', $headers, $rows, array('style'=>'width:100%', 'cellpadding'=>'5'));
$output .= theme('pager');
}
- print theme('page', $output);
-}
-
-/**
- * This is the callback for question forms submitted to the 'question' url
- * Submitted questions are inserted into the question queue database table
- * Other stuff could happen here like emailing admin, actions, etc.
- *
- */
-
-function question_submit() {
- if ($_POST['op']['Submit Question']) {
- $edit = $_POST['edit'];
-
- // validate...
- if ($edit['question']==''){
- //dude, it's required
- form_set_error('question', t('Please enter a question.'));
- $output = theme('question_qform', $edit);
- print theme('page', $output);
- return; // end this function
- }
-
- $qid = db_next_id('question_queue');
- global $user;
- $quid = $user->uid;
- db_query('INSERT INTO {question_queue} (qid, questioner, quid, question) VALUES (%d, "%s", %d, "%s")', $qid, $edit['questioner'], $quid, $edit['question']);
- $path = variable_get('question_thanks', '');
- $dest = $_REQUEST['destination'];
- unset($_REQUEST['destination']);
- if (strlen(trim($path))) {
- // if the 'question thank you node' variable was set...
- drupal_goto($path);
- }
- else {
- // if not...
- drupal_set_message(t('Thank you for submitting your question.'));
- if ($dest) {
- //go back to the original question node...
- drupal_goto($dest);
- }
- else {
- // last resort
- drupal_goto('node');
- }
- }
- }
- else {
- drupal_set_title(t("Submit a Question"));
- // initial form...
- $output = theme('question_qform');
- print theme('page', $output);
- }
+ return $output;
}
function question_queue_item_delete($qid) {
@@ -327,8 +319,8 @@
if ($node->questioner) {
$output .= '