PageRenderTime 40ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/qa-include/pages/feedback.php

http://github.com/q2a/question2answer
PHP | 184 lines | 120 code | 41 blank | 23 comment | 17 complexity | a5284a477e47ada5dadcafb100cbeb7b MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. Question2Answer by Gideon Greenspan and contributors
  4. http://www.question2answer.org/
  5. Description: Controller for feedback page
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. More about this license: http://www.question2answer.org/license.php
  15. */
  16. if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
  17. header('Location: ../../');
  18. exit;
  19. }
  20. require_once QA_INCLUDE_DIR . 'app/captcha.php';
  21. require_once QA_INCLUDE_DIR . 'db/selects.php';
  22. // Get useful information on the logged in user
  23. $userid = qa_get_logged_in_userid();
  24. if (isset($userid) && !QA_FINAL_EXTERNAL_USERS) {
  25. list($useraccount, $userprofile) = qa_db_select_with_pending(
  26. qa_db_user_account_selectspec($userid, true),
  27. qa_db_user_profile_selectspec($userid, true)
  28. );
  29. }
  30. $usecaptcha = qa_opt('captcha_on_feedback') && qa_user_use_captcha();
  31. // Check feedback is enabled and the person isn't blocked
  32. if (!qa_opt('feedback_enabled'))
  33. return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
  34. if (qa_user_permit_error()) {
  35. $qa_content = qa_content_prepare();
  36. $qa_content['error'] = qa_lang_html('users/no_permission');
  37. return $qa_content;
  38. }
  39. // Send the feedback form
  40. $feedbacksent = false;
  41. if (qa_clicked('dofeedback')) {
  42. require_once QA_INCLUDE_DIR . 'app/emails.php';
  43. require_once QA_INCLUDE_DIR . 'util/string.php';
  44. $inmessage = qa_post_text('message');
  45. $inname = qa_post_text('name');
  46. $inemail = qa_post_text('email');
  47. $inreferer = qa_post_text('referer');
  48. if (!qa_check_form_security_code('feedback', qa_post_text('code')))
  49. $pageerror = qa_lang_html('misc/form_security_again');
  50. else {
  51. if (empty($inmessage))
  52. $errors['message'] = qa_lang('misc/feedback_empty');
  53. if ($usecaptcha)
  54. qa_captcha_validate_post($errors);
  55. if (empty($errors)) {
  56. $subs = array(
  57. '^message' => $inmessage,
  58. '^name' => empty($inname) ? '-' : $inname,
  59. '^email' => empty($inemail) ? '-' : $inemail,
  60. '^previous' => empty($inreferer) ? '-' : $inreferer,
  61. '^url' => isset($userid) ? qa_path_absolute('user/' . qa_get_logged_in_handle()) : '-',
  62. '^ip' => qa_remote_ip_address(),
  63. '^browser' => @$_SERVER['HTTP_USER_AGENT'],
  64. );
  65. if (qa_send_email(array(
  66. 'fromemail' => qa_opt('from_email'),
  67. 'fromname' => $inname,
  68. 'replytoemail' => qa_email_validate(@$inemail) ? $inemail : null,
  69. 'replytoname' => $inname,
  70. 'toemail' => qa_opt('feedback_email'),
  71. 'toname' => qa_opt('site_title'),
  72. 'subject' => qa_lang_sub('emails/feedback_subject', qa_opt('site_title')),
  73. 'body' => strtr(qa_lang('emails/feedback_body'), $subs),
  74. 'html' => false,
  75. ))) {
  76. $feedbacksent = true;
  77. } else {
  78. $pageerror = qa_lang_html('main/general_error');
  79. }
  80. qa_report_event('feedback', $userid, qa_get_logged_in_handle(), qa_cookie_get(), array(
  81. 'email' => $inemail,
  82. 'name' => $inname,
  83. 'message' => $inmessage,
  84. 'previous' => $inreferer,
  85. 'browser' => @$_SERVER['HTTP_USER_AGENT'],
  86. ));
  87. }
  88. }
  89. }
  90. // Prepare content for theme
  91. $qa_content = qa_content_prepare();
  92. $qa_content['title'] = qa_lang_html('misc/feedback_title');
  93. $qa_content['error'] = @$pageerror;
  94. $qa_content['form'] = array(
  95. 'tags' => 'method="post" action="' . qa_self_html() . '"',
  96. 'style' => 'tall',
  97. 'fields' => array(
  98. 'message' => array(
  99. 'type' => $feedbacksent ? 'static' : 'text',
  100. 'label' => qa_lang_html_sub('misc/feedback_message', qa_opt('site_title')),
  101. 'tags' => 'name="message" id="message"',
  102. 'value' => qa_html(@$inmessage),
  103. 'rows' => 8,
  104. 'error' => qa_html(@$errors['message']),
  105. ),
  106. 'name' => array(
  107. 'type' => $feedbacksent ? 'static' : 'text',
  108. 'label' => qa_lang_html('misc/feedback_name'),
  109. 'tags' => 'name="name"',
  110. 'value' => qa_html(isset($inname) ? $inname : @$userprofile['name']),
  111. ),
  112. 'email' => array(
  113. 'type' => $feedbacksent ? 'static' : 'email',
  114. 'label' => qa_lang_html('misc/feedback_email'),
  115. 'tags' => 'name="email"',
  116. 'value' => qa_html(isset($inemail) ? $inemail : qa_get_logged_in_email()),
  117. 'note' => $feedbacksent ? null : qa_opt('email_privacy'),
  118. ),
  119. ),
  120. 'buttons' => array(
  121. 'send' => array(
  122. 'label' => qa_lang_html('main/send_button'),
  123. ),
  124. ),
  125. 'hidden' => array(
  126. 'dofeedback' => '1',
  127. 'code' => qa_get_form_security_code('feedback'),
  128. 'referer' => qa_html(isset($inreferer) ? $inreferer : @$_SERVER['HTTP_REFERER']),
  129. ),
  130. );
  131. if ($usecaptcha && !$feedbacksent)
  132. qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], @$errors);
  133. $qa_content['focusid'] = 'message';
  134. if ($feedbacksent) {
  135. $qa_content['form']['ok'] = qa_lang_html('misc/feedback_sent');
  136. unset($qa_content['form']['buttons']);
  137. }
  138. return $qa_content;