function faq_ask_submit in FAQ_Ask 6.2
Same name and namespace in other branches
- 8 faq_ask.module \faq_ask_submit()
- 7 faq_ask.module \faq_ask_submit()
1 string reference to 'faq_ask_submit'
- faq_ask_form_alter in ./faq_ask.module
- Implementation of hook_form_alter().
This is how we build the "ask question" form.
File
- ./faq_ask.module, line 406
- This module is an add-on to the FAQ module that allows users with the 'ask question'
permission to create a question which will be queued for an 'expert' to answer.
Code
function faq_ask_submit($form, &$form_state) {
$terms = array();
$vocabs = variable_get('faq_ask_vocabularies', 0);
if (FALSE == variable_get('faq_ask_categorize', FALSE)) {
foreach ($form_state['values']['taxonomy'] as $vid => $term_array) {
if (in_array($vid, $vocabs)) {
$terms = array_merge($terms, $term_array);
}
elseif ($vid == 'tags') {
foreach ($term_array as $termname) {
$t = taxonomy_get_term_by_name($termname);
foreach ($t as $term_obj) {
$terms[$term_obj->tid] = $term_obj->tid;
}
}
}
}
}
if (variable_get('faq_ask_notify', FALSE)) {
$params = array(
'category' => -1,
'question' => $form_state['values']['title'],
'question_details' => $form_state['values']['detailed_question'],
'nid' => $form_state['nid'],
'creator' => theme('username', node_load($form_state['nid']), array(
'plain' => TRUE,
)),
);
if (empty($terms)) {
$expert = db_fetch_object(db_query("SELECT uid FROM {faq_expert} WHERE tid='0'"));
faq_ask_notify_expert($expert->uid, $params);
}
else {
$result = db_query("SELECT uid FROM {faq_expert} WHERE tid IN ('%s')", implode(",", $terms));
while ($expert = db_fetch_object($result)) {
$expert_terms = db_query("SELECT tid FROM {faq_expert} WHERE uid='%d'", $expert->uid);
$params['category'] = '';
while ($params['category'] == '' && ($term = db_fetch_object($expert_terms))) {
if (in_array($term->tid, $terms)) {
$term_node = taxonomy_get_term($term->tid);
$params['category'] = $term_node->name;
}
}
faq_ask_notify_expert($expert->uid, $params);
}
}
}
if (isset($form_state['values']['faq_email'])) {
if (strlen($form_state['values']['faq_email']) > 4) {
_faq_ask_set_faq_notification($form_state['nid'], $form_state['values']['faq_email']);
drupal_set_message(t('Your question has been submitted. An e-mail will be sent to <i>@mail</i> when answered.', array(
'@mail' => $form_state['values']['faq_email'],
)), 'status');
if (module_exists('simplenews') && ($tid = variable_get('faq_ask_notify_asker_simplenews_tid', '0'))) {
if (function_exists('simplenews_subscribe_user')) {
simplenews_subscribe_user($form_state['values']['faq_email'], $tid, variable_get('faq_ask_notify_asker_simplenews_confirm', 1), 'FAQ-Ask');
}
}
}
}
elseif (isset($form_state['values']['faq_notify'])) {
if ($form_state['values']['faq_notify']) {
global $user;
$email = $user->mail;
_faq_ask_set_faq_notification($form_state['nid'], $email);
drupal_set_message(t('Your question has been submitted. An e-mail will be sent to <i>@mail</i> when answered.', array(
'@mail' => $email,
)), 'status');
}
else {
_faq_ask_delete_faq_notification($form_state['nid']);
}
}
else {
drupal_set_message(t('Your question has been submitted. It will appear in the FAQ listing as soon as it has been answered.'), 'status');
}
}