category in e-mail

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

Post Reply
sergey.khodjamirian
Posts: 35
Joined: Wed Aug 09, 2006 11:36 am

category in e-mail

Post by sergey.khodjamirian »

I have made some changes to the way e-mails are sent from the app.

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?
Thorsten
Posts: 15747
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

you need no changes in the templates.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
sergey.khodjamirian
Posts: 35
Joined: Wed Aug 09, 2006 11:36 am

Post by sergey.khodjamirian »

Thorsten,

Thanks. I have sent those to be uploaded and we'll see what happens.

A few quick questions:

I have removed the right hand column from index.tpl. Now that bit is blank, but I wish the middle column to stretch out to fill that blank space. Do I change stuff in style.css?

Also, phpmyFAQ 1.6.4 is out - I see from CHANGEDFILES, that some files have been changed. Obviously, I want these bug fixes to be part of the install I have currently. Which files from the new build should I replace the current ones with to fix these bugs? I can upload them all, but I was wondering if anything in particular is very important.


thanks!

Sergey
Thorsten
Posts: 15747
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,
sergey.khodjamirian wrote:I have removed the right hand column from index.tpl. Now that bit is blank, but I wish the middle column to stretch out to fill that blank space. Do I change stuff in style.css?
yes, you have to decrease the width of the "right column" in style.css.
sergey.khodjamirian wrote:Also, phpmyFAQ 1.6.4 is out - I see from CHANGEDFILES, that some files have been changed. Obviously, I want these bug fixes to be part of the install I have currently. Which files from the new build should I replace the current ones with to fix these bugs? I can upload them all, but I was wondering if anything in particular is very important.
If you're using only one language, you need no update. :-)

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
sergey.khodjamirian
Posts: 35
Joined: Wed Aug 09, 2006 11:36 am

Post by sergey.khodjamirian »

Okay great.

The e-mail notifications work. However...

When I click add question or ask question and pick a sub-category, the subject line of the e-mail runs:

" - Approve" or " Answer"

So I tried picking a main category instead. What happened then was that for ask question action, the subject line of the e-mail contains:

"Main Category Name Answer"

Which is perfect!

I did the same for add question. So when adding question, I picked the main category. However the subject line of this e-mail says:

" - Approve"

Finally, when a comment is posted, the e-mail that is generated also brings about a blank in the subject line where the category should be.


I am thinking of changing this around a bit to make it simpler.

So that when a user adds an faq or submits an faq, they can only select main categories. Is there a way of changing the code so this happens? Then the subject of an e-mail stemming from these actions will read either "Main Cat - Approve" or "Main Cat - Answer".

And when a user comments on an faq, an e-mail is sent to the admin with subject line: "Main Cat - Review"

I hope this didnt confuse you too much.

Thanks.

Sergey
Thorsten
Posts: 15747
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,
sergey.khodjamirian wrote:So that when a user adds an faq or submits an faq, they can only select main categories. Is there a way of changing the code so this happens? Then the subject of an e-mail stemming from these actions will read either "Main Cat - Approve" or "Main Cat - Answer".
okay... you mean only main categories in the dropdown list?

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
sergey.khodjamirian
Posts: 35
Joined: Wed Aug 09, 2006 11:36 am

Post by sergey.khodjamirian »

Yea, so when a user wants to submit a new Q&A as well as ask a question he/she can only select main categories.

Plus when....

...user adds a Q&A - email subject line reads: "[selected main category] - Approve"

...user asks a questions - email subject line reads: "[selected main category] - Answer"

...user comments on a Q&A record - e-mail subject line reads: "[main category of Q&A] - Review"

Thanks.

Sergey
sergey.khodjamirian
Posts: 35
Joined: Wed Aug 09, 2006 11:36 am

Post by sergey.khodjamirian »

Sorry Thorsten,

Turns out I don't need any of this. Hope there was no inconvenience.

Cheers,

Sergey
Thorsten
Posts: 15747
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

no problem as I didn't had the time to answer yet. :-)

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply