My goal is to make it so that when a user either submits an faq, asks a question or comments on an faq, the following happens:
An email is sent, where the subject contains the category name.
The way I understand it.
save.php deals with the first thing - submit an faq
savequestion.php deals with the second one - ask a question
savecomment.php deals with third one - comment
This is how I've changed the three above files, so that the category name instead of "title" appears in the subject:
Code: Select all
<?php
/**
* $Id: save.php,v 1.12.2.15.2.7 2006/06/01 20:51:53 thorstenr Exp $
*
* Saves a user FAQ record and sends an email to the user
*
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @since 2002-09-16
* @copyright (c) 2001-2006 phpMyFAQ Team
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*/
if (!defined('IS_VALID_PHPMYFAQ')) {
header('Location: http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']));
exit();
}
$captcha = new PMF_Captcha($db, $sids, $pmf->language, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR']);
if ( isset($_POST['username']) && $_POST['username'] != ''
&& isset($_POST['usermail']) && checkEmail($_POST['usermail'])
&& isset($_POST['rubrik']) && is_array($_POST['rubrik'])
&& isset($_POST['thema']) && $_POST['thema'] != ''
&& isset($_POST['content']) && $_POST['content'] != ''
&& IPCheck($_SERVER['REMOTE_ADDR'])
&& checkBannedWord(htmlspecialchars(strip_tags($_POST['thema'])))
&& checkBannedWord(htmlspecialchars(strip_tags($_POST['content'])))
&& checkCaptchaCode() ) {
Tracking("save_new_entry",0);
$datum = date("YmdHis");
$content = $db->escape_string(safeHTML(nl2br($_POST["content"])));
$contentlink = $db->escape_string(safeHTML($_POST["contentlink"]));
if (substr($contentlink,7) != "") {
$content = $content."<br />".$PMF_LANG["msgInfo"]."<a href=\"http://".substr($contentlink,7)."\" target=\"_blank\">".$contentlink."</a>";
}
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
$lang = trim(strtolower(substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2)));
} else {
$lang = "en";
}
$thema = $db->escape_string(safeHTML($_POST["thema"]));
$selected_category = $_POST["rubrik"];
$keywords = $db->escape_string(safeHTML($_POST["keywords"]));
$author = $db->escape_string(safeHTML($_POST["username"]));
$usermail = $IDN->encode($db->escape_string(safeHTML($_POST["usermail"])));
$db->query(sprintf("INSERT INTO %sfaqdata (id, lang, solution_id, revision_id, active, thema, content, keywords, author, email, comment, datum) VALUES (%d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", SQLPREFIX, $db->nextID(SQLPREFIX."faqdata", "id"), $lang, getSolutionId(), 0, 'no', $thema, $content, $keywords, $author, $usermail, 'y', $datum));
foreach ($selected_category as $_category) {
$db->query(sprintf("INSERT INTO %sfaqcategoryrelations (category_id, category_lang, record_id, record_lang) VALUES (%d, '%s', %d, '%s')", SQLPREFIX, intval($_category), $lang, $db->insert_id(SQLPREFIX.'faqdata', 'id'), $lang));
}
$db->query(sprintf("INSERT INTO %sfaqvisits (id, lang, visits, last_visit) VALUES (%d, '%s', %d, %d)", SQLPREFIX, $db->insert_id(SQLPREFIX.'faqdata', 'id'), $lang, 1, time()));
$additional_header = array();
$additional_header[] = 'MIME-Version: 1.0';
$additional_header[] = 'Content-Type: text/plain; charset='. $PMF_LANG['metaCharset'];
if (strtolower($PMF_LANG['metaCharset']) == 'utf-8') {
$additional_header[] = 'Content-Transfer-Encoding: 8bit';
}
$additional_header[] = 'From: '.$usermail;
$subject = $categories[$selected_category]["name"]." - Approve";
if (function_exists('mb_encode_mimeheader')) {
$subject = mb_encode_mimeheader($subject);
}
$body = unhtmlentities($PMF_LANG['msgMailCheck']);
if (ini_get('safe_mode')) {
mail($IDN->encode($PMF_CONF["adminmail"]), $subject, $body, implode("\r\n", $additional_header));
} else {
mail($IDN->encode($PMF_CONF["adminmail"]), $subject, $body, implode("\r\n", $additional_header), "-f$usermail");
}
$tpl->processTemplate ("writeContent", array(
"msgNewContentHeader" => $PMF_LANG["msgNewContentHeader"],
"Message" => $PMF_LANG["msgNewContentThanks"]
));
} else {
if (IPCheck($_SERVER["REMOTE_ADDR"]) == FALSE) {
$tpl->processTemplate ("writeContent", array(
"msgNewContentHeader" => $PMF_LANG["msgNewContentHeader"],
"Message" => $PMF_LANG["err_bannedIP"]
));
} else {
Tracking("error_save_entry", 0);
$tpl->processTemplate ("writeContent", array(
"msgNewContentHeader" => $PMF_LANG["msgNewContentHeader"],
"Message" => $PMF_LANG["err_SaveEntries"]
));
}
}
$tpl->includeTemplate("writeContent", "index");
?>
Code: Select all
<?php
/**
* $Id: savequestion.php,v 1.11.2.9.2.8 2006/04/25 12:07:24 matteo Exp $
*
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @author David Saez Padros <david@ols.es>
* @since 2002-09-17
* @copyright (c) 2001-2006 phpMyFAQ Team
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*/
if (!defined('IS_VALID_PHPMYFAQ')) {
header('Location: http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']));
exit();
}
$captcha = new PMF_Captcha($db, $sids, $pmf->language, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR']);
if ( isset($_POST['username']) && $_POST['username'] != ''
&& isset($_POST['usermail']) && checkEmail($_POST['usermail'])
&& isset($_POST['content']) && $_POST['content'] != ''
&& IPCheck($_SERVER['REMOTE_ADDR'])
&& checkBannedWord(htmlspecialchars(strip_tags($_POST['content'])))
&& checkCaptchaCode() ) {
if (isset($_POST['try_search'])) {
$suchbegriff = strip_tags($_POST['content']);
$printResult = searchEngine($suchbegriff, $numr);
echo $numr;
} else {
$numr = 0;
}
if ($numr == 0) {
$cat = new category;
$categories = $cat->getAllCategories();
$usermail = $db->escape_string($IDN->encode($_POST['usermail']));
$username = $db->escape_string(strip_tags($_POST['username']));
$selected_category = intval($_POST['rubrik']);
list($user, $host) = explode("@", $usermail);
if (checkEmail($usermail)) {
$datum = date("YmdHis");
$content = strip_tags($_POST['content']);
$result = $db->query("INSERT INTO ".SQLPREFIX."faqfragen (id, ask_username, ask_usermail, ask_rubrik, ask_content, ask_date) VALUES (".$db->nextID(SQLPREFIX."faqfragen", "id").", '".$db->escape_string($username)."', '".$db->escape_string($usermail)."', ".$selected_category.", '".$db->escape_string($content)."', '".$datum."')");
$questionMail = $PMF_LANG["msgMailAnswer"]."\n\n".wordwrap($content, 72);
$additional_header = array();
$additional_header[] = 'MIME-Version: 1.0';
$additional_header[] = 'Content-Type: text/plain; charset='. $PMF_LANG['metaCharset'];
if (strtolower($PMF_LANG['metaCharset']) == 'utf-8') {
$additional_header[] = 'Content-Transfer-Encoding: 8bit';
}
$additional_header[] = 'From: '.'<'.$IDN->encode($usermail).'>';
$subject = $categories[$selected_category]["name"]." Answer";
if (function_exists('mb_encode_mimeheader')) {
$subject = mb_encode_mimeheader($subject);
}
$body = strip_tags($questionMail);
$body = str_replace(array("\r\n", "\r", "\n"), "\n", $body);
$body = str_replace(array("\r\n", "\r", "\n"), "\n", $body);
if (strstr(PHP_OS, 'WIN') !== NULL) {
// if windows, cr must "\r\n". if other must "\n".
$body = str_replace("\n", "\r\n", $body);
}
mail($IDN->encode($PMF_CONF['adminmail']), $subject, $body, implode("\r\n", $additional_header));
$tpl->processTemplate ("writeContent", array(
"msgQuestion" => $PMF_LANG["msgQuestion"],
"Message" => $PMF_LANG["msgAskThx4Mail"],
));
} else {
$tpl->processTemplate ("writeContent", array(
"msgQuestion" => $PMF_LANG["msgQuestion"],
"Message" => $PMF_LANG["err_noMailAdress"],
));
}
} else {
$tpl->templates['writeContent'] = $tpl->readTemplate('template/asksearch.tpl');
$tpl->processTemplate ('writeContent', array(
'msgQuestion' => $PMF_LANG["msgQuestion"],
'printResult' => $printResult,
'msgAskYourQuestion' => $PMF_LANG['msgAskYourQuestion'],
'msgContent' => $_POST['content'],
'postUsername' => urlencode($_REQUEST['username']),
'postUsermail' => urlencode($_REQUEST['usermail']),
'postRubrik' => urlencode($_REQUEST['rubrik']),
'postContent' => urlencode($_REQUEST['content']),
'writeSendAdress' => $_SERVER['PHP_SELF'].'?'.$sids.'action=savequestion',
));
}
} else {
if (IPCheck($_SERVER["REMOTE_ADDR"]) == FALSE) {
$tpl->processTemplate ("writeContent", array(
"msgQuestion" => $PMF_LANG["msgQuestion"],
"Message" => $PMF_LANG["err_bannedIP"],
));
} else {
$tpl->processTemplate ("writeContent", array(
"msgQuestion" => $PMF_LANG["msgQuestion"],
"Message" => $PMF_LANG["err_SaveQuestion"],
));
}
}
$tpl->includeTemplate("writeContent", "index");
?>
Code: Select all
<?php
/**
* $Id: savecomment.php,v 1.7.2.9.2.6 2006/04/25 12:07:24 matteo Exp $
*
* Saves the posted comment
*
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @since 2002-08-29
* @copyright (c) 2001-2006 phpMyFAQ Team
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*/
if (!defined('IS_VALID_PHPMYFAQ')) {
header('Location: http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['SCRIPT_NAME']));
exit();
}
$captcha = new PMF_Captcha($db, $sids, $pmf->language, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR']);
if ( isset($_POST['user']) && $_POST['user'] != ''
&& isset($_POST['mail']) && checkEmail($_POST['mail'])
&& isset($_POST['comment']) && $_POST['comment'] != ''
&& IPCheck($_SERVER['REMOTE_ADDR'])
&& checkBannedWord(htmlspecialchars(strip_tags($_POST['comment'])))
&& checkCaptchaCode() ) {
$id = (isset($_POST["id"])) ? (int)$_POST["id"] : 0;
Tracking("save_comment", $id);
$helped = ""; // not used in this version - maybe in the future
$comment = nl2br($db->escape_string(safeHTML($_POST["comment"])));
$comment_by_user = $db->escape_string(safeHTML($_POST["user"]));
$comment_by_mail = $db->escape_string(safeHTML($_POST["mail"]));
$result = $db->query("INSERT INTO ".SQLPREFIX."faqcomments (id_comment, id, usr, email, comment, datum, helped) VALUES (".$db->nextID(SQLPREFIX."faqcomments", "id_comment").", ".$id.", '".$comment_by_user."', '".$comment_by_mail."', '".$comment."', ".time().", '".$helped."')");
$commentMail = "Please review http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?action=artikel&cat=".$cat."&id=".$id."&artlang=".$lang." - ".$PMF_LANG["msgCategory"].": ".$categories[$selected_category]["name"].
"\n\n".
wordwrap($_POST["comment"], 72);
$additional_header = array();
$additional_header[] = 'MIME-Version: 1.0';
$additional_header[] = 'Content-Type: text/plain; charset='. $PMF_LANG['metaCharset'];
if (strtolower($PMF_LANG['metaCharset']) == 'utf-8') {
$additional_header[] = 'Content-Transfer-Encoding: 8bit';
}
$additional_header[] = 'From: '.'<'.$IDN->encode($comment_by_mail).'>';
$subject = $categories[$selected_category]["name"]." Answer";
if (function_exists('mb_encode_mimeheader')) {
$subject = mb_encode_mimeheader($subject);
}
$body = strip_tags($commentMail);
$body = str_replace(array("\r\n", "\r", "\n"), "\n", $body);
$body = str_replace(array("\r\n", "\r", "\n"), "\n", $body);
if (strstr(PHP_OS, 'WIN') !== NULL) {
// if windows, cr must "\r\n". if other must "\n".
$body = str_replace("\n", "\r\n", $body);
}
mail($IDN->encode($PMF_CONF['adminmail']), $subject, $body, implode("\r\n", $additional_header), '-f'.$IDN->encode($comment_by_mail));
$tpl->processTemplate ("writeContent", array(
"msgCommentHeader" => $PMF_LANG["msgWriteComment"],
"Message" => $PMF_LANG["msgCommentThanks"]
));
} else {
if (IPCheck($_SERVER["REMOTE_ADDR"]) == FALSE) {
$tpl->processTemplate ("writeContent", array(
"msgCommentHeader" => $PMF_LANG["msgWriteComment"],
"Message" => $PMF_LANG["err_bannedIP"]
));
} else {
Tracking("error_save_comment", $id);
$tpl->processTemplate ("writeContent", array(
"msgCommentHeader" => $PMF_LANG["msgWriteComment"],
"Message" => $PMF_LANG["err_SaveComment"]
));
}
}
$tpl->includeTemplate("writeContent", "index");
Is this going to be okay? Should I change anything in templates?