Joseph L. LeBlanc
homeportfoliojoomlabiocontactblog
articles
guides
tutorials
all
forum
Subscribe in NewsGator Online

Learning Joomla! for the first time? Buy the Joomla! 1.5 Essential training CD-ROM or watch it on Lynda.com.

 

Daily Message with E-mail PDF Print E-mail

dailymessage.html.php

<?

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

Access outside of Mambo is disallowed here.

class dailymessage_HTML {

This class contains a series of functions handling the component's output. Queries have been avoided and variables are passed instead.

function FillAllFields()
{
    ?><center><font color="#FF0000">Please fill in all of the fields.</font></center><?
}

FillAllFields displays a message when the visitor has not given enough information to send a mailing.


function Success()
{
    ?>
        <center><b>Message sent successfully.</b><BR><BR>
        <input type="button" value="Close" class="button" onClick="{window.close();}">
        </center>
    <?

}

Once an e-mail has been successfully sent, this function displays the success message and provides a button for closing the window.


function EmailForm($option, $id, $sendername, $emailfrom, $emailto, $note)
{

        ?>
        <form action="index2.php" method="post">
        <table>
        <tr><td colspan="2" align="center">Send this message</td></tr>
        <tr><td align="left">Your Name:</td> <td><input name="sendername" value="<? echo $sendername; ?>"></td></tr>
        <tr><td align="left">Your e-mail:</td> <td><input name="emailfrom" value="<? echo $emailfrom; ?>"></td></tr>
        <tr><td align="left">Your friend's e-mail:</td> <td><input name="emailto" value="<? echo $emailto;
?>"></td></tr>
        <tr><td align="left">An additional note (optional):</td> <td><textarea name="note" rows="5" cols="30">
<? echo $note; ?></textarea></td></tr>
        <tr><td colspan="2" align="center"><input type="submit" value="Send Message" class="button"> 
<input type="button" value="Cancel" class="button" onClick="{window.close();}"></td></tr>
        </table>

Fields on this form are populated by previously entered values, when present. If the visitor omits an essential value, repeated data entry will not be necessary. Submit and Cancel buttons are also generated.

        <input type="hidden" name="id" value="<? echo $id; ?>">
        <input type="hidden" name="task" value="sendemail">
        <input type="hidden" name="option" value="<? echo $option; ?>">

The 'option' variable tells Mambo which component to load, while 'task' is used within dailymessage.php. To ensure the correct Daily Message loads the correct message, the 'id' variable is set to the appropriate database row number.

        </form>
        <?
}


function ListMessages($option, $bold, $italic, $underline, $showdate, $starttags, $endtags, &$rows)
{

?><table><?


foreach($rows as $row)
{
        $button = "<a href=\"#\" onClick=\"javascript:{ window.open('index2.php?option=$option&task=emailform&id=" . $row->id . "', 'emailform', 'height=350,width=400'); }\"><img src=\"images/M_images/emailButton.png\" border=\"0\"></a>";

Although most of the code for this function has been copied directly out of the original dailymessage.php file, the "email-a-friend" link is new. The code is set to open a pop-up window and load the current component, but using the index2.php file. Instead of loading a fully-featured page with modules, index2.php loads the CSS file for the current template, then loads the component output. This allows for a consistent look and feel, while providing space within a visually small area. The image used is part of a standard Mambo installation.

        if($showdate == 1)
                echo "<tr><td>" . mosFormatDate($row->date) . "</td>";
        else
                echo "<tr>";

        echo "<td>" . $starttags . $row->message . $endtags . " " . $button . "</td></tr>";

This portion of code is identical to the original location in dailymessage.php, except that a forced space and the e-mail button have been added.

}

?></table><?

}

} // class dailymessage_HTML

?>

Download a copy of the new component here. This will not interfere with any of the other Daily Message tutorials.