Revision [1980]

This is an old revision of FeedbackActionUpgrade made by NilsLindenberg on 2004-10-25 18:13:41.

 

Feedback Action Upgrade


This is an upgraded version of FeedbackAction. It allows not only to send feedback to the Wikka administrator but also to any other registered user via a user GET variable

This action is meant as a module to integrate the FeedbackAction into the UserAdmin tool.
To use it as a standalone action simply add {{userfeedback}} in one of your pages.
 



Save the following code as actions/userfeedback.php.

-- DarTar



actions/userfeedback.php



<?php

// Displays a form to send feedback to the site administrator, as specified in the configuration file,
// or to a registered user as specified by a "user" GET variable

// 1. Build feedback form

if ($_GET["user"]) {
    // feedback-to-user form
    $form = '<p>Send feedback to :'.$this->Link($_GET["user"]).'</p>
        <form method="post" action="'
.$this->GetPageTag().'?user='.$_GET["user"].'&mail=result">
        Comments:<br />
        <textarea name="comments" rows="15" cols="40">'
.$_POST["comments"].'</textarea><br />
        <input type="submit" />
        </form>'
;
} else {
    // feedback-to-admin form
    $form = '<p>Fill in the form below to send us your comments:</p>
        <form method="post" action="'
.$this->GetPageTag().'?mail=result">
        Name: <input name="name" value="'
.$_POST["name"].'"type="text" /><br />
        Email: <input name="email" value="'
.$_POST["email"].'" type="text" /><br />
        Comments:<br />
        <textarea name="comments" rows="15" cols="40">'
.$_POST["comments"].'</textarea><br />
        <input type="submit" />
        </form>'
;
}

// 2. Validate form

if ($_GET["mail"]=="result") {
   
    $comments = $_POST["comments"];

    if ($_GET["user"]) {
        // A. feedback-to-user validation
        // Sender
        $name = $this->GetUserName();
        $senderdata =  $this->LoadSingle("select email from ".$this->config["table_prefix"]."users WHERE name =\"".$name."\"");
        $email = $senderdata["email"];
       
        // Recipient
        $recipient = $_GET["user"];
        $recipientdata = $this->LoadSingle("select email from ".$this->config["table_prefix"]."users WHERE name =\"".$recipient."\"");
        $recipientmail = $recipientdata["email"];

        if (!$recipientmail) {
            echo $this->Format("== User ".$recipient." unknown == --- ");
            echo $this->Format("Sorry, the recipient of your message (**".$recipient."**) is unknown --- --- --- ");
            echo $this->Format("Return to the [[".$this->GetConfigValue("root_page")." main page]]");
       
        } elseif (!$comments) {
            // some text must be entered
            echo "<p class=\"error\">Please enter some text</p>";  
            echo $alert;
            echo $form;
        }

    } else {
        // B. feedback-to-admin validation

        $name = $_POST["name"];
        $email = $_POST["email"];
        $recipient = $this->GetConfigValue("admin_users");
        $recipientmail = $this->GetConfigValue("admin_email");
        list($user, $host) = sscanf($email, "%[a-zA-Z0-9._-]@%[a-zA-Z0-9._-]");
        if (!$name) {
            // a valid name must be entered
            echo "<p class=\"error\">Please enter your name</p>";  
            echo $form;
        } elseif (!$email || !strchr($email, "@") || !$user || !$host) {
            // a valid email address must be entered
            echo "<p class=\"error\">Please enter a valid email address</p>";  
            echo $form;
        } elseif (!$comments) {
                    // some text must be entered
                    echo "<p class=\"error\">Please enter some text</p>";
                    echo $alert;
                    echo $form;
        }

    }

    // 3. Form is valid => send feedback

    if ($name && $email && $comments && $recipientmail) {
   
        // send email and display message
        $msg = "Name:\t".$name."\n";
        $msg .= "Email:\t".$email."\n";
        $msg .= "Comments:".$comments."\n";
        $subject = "Feedback from ".$this->GetConfigValue("wakka_name");
        $mailheaders = "From:".$email."\n";
        $mailheaders .= "Reply-To:".$email."\n\n";
        mail($recipientmail, $subject, $msg, $mailheaders);
        echo $this->Format("== Feedback sent! == --- ");
        echo $this->Format("Thanks for your interest: your message has been sent to [[".$recipient."]] --- --- ");
        // optionally displays the feedback text
        echo $this->Format("---- ''**Your name:** ".$name."---**Your email:** ".$email."---**Your comments:**".$comments."'' ---- ");
        echo $this->Format(" --- Return to the [[".$this->GetConfigValue("root_page")." main page]]");
    }

} else {

    // Print form
    echo $form;

}
?>




CategoryDevelopment
There are 2 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki