<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: ecard.php,v 1.10.2.5 2004/08/27 16:02:56 kirilt Exp $



/*phpPowerCards 2.0 - Postcard Script that uses simple Text
flatfiles (no Database needed) - or MySQL Database - Easy Installation -
Author: Marc Giombetti <marc@giombetti.com>
Get your copy at www.giombetti.com/?cat=PHP */

function displayMedia($row)
{
    global $gallerypath;

    $template = $row['displaytag'];
    $template = str_replace(':FNAME:', $gallerypath . '/' . $row['galloc'] . '/' . $row['img'], $template);
    $template = str_replace(':WIDTH:', $row['width'], $template);
    $template = str_replace(':HEIGHT:', $row['height'], $template);
    $template = str_replace(':DESCRIP:', $row['description'], $template);
    return $template;
}


function displayPostCardForm($pid) {
    global $adminpath, $mpnTables;

    include "$adminpath/config.php";

    $name = $email = null;
    $name = $GLOBALS['uinf']['uname'];
    $email = $GLOBALS['uinf']['email'];

    galleryHeader();
    OpenTable();

    if (!isset($pid) || $pid=="")
    {
        echo '<br><b>'._GALPICERROR.'</b><br><br>';
    }
    else
    {
        $sql  = 'SELECT gp.img, gp.width, gp.height, gp.description, gc.galloc, gm.displaytag FROM ';
        $sql .= $mpnTables['gallery_pictures'] . ' gp, ' . $mpnTables['gallery_categories'] . ' gc, ';
        $sql .= $mpnTables['gallery_media_types'] . ' gm ';
        $sql .= "WHERE gp.gid = gc.gallid AND gp.extension = gm.extension AND gp.pid = '$pid' LIMIT 1";
        $result = mysql_query($sql);
        $prow = mysql_fetch_array( $result );

        $img = displayMedia($prow);

        echo $img;
        echo '
      <form name="form" method="post" action="myegallery.php">
        <input type="hidden" name="do" value="ecard_send">
            <input type="hidden" name="pid" value="' . $pid . '">

        <table border="0" cellspacing="0" cellpadding="5" align="center">
          <tr>
            <td>
              <div align="left"> <span class="bignewgray">
                '._GALRECIPIENTSNAME.'
                </span><br>
                <input type="TEXT" size="25" name="name_to" value="">
              </div>
            </td>
            <td>
              <div align="left"><span class="bignewgray">
                '._GALRECIPIENTSMAIL.'
                </span><br>
                <input type="TEXT" size="25" name="email_to" value="">
              </div>
            </td>
          </tr>
        </table>
        <br>
        <center>
          <table border=0 cellspacing=0 cellpadding=5 width="430" >
            <tr>
              <td> <span class="bignewgray">
                '._GALYOURNAME.'
                </span><br>
                <input type="TEXT" size="25" name="name_from" value="' . $name . '">
              </td>
              <td> <span class="bignewgray">
                '._GALYOURMAIL.'
                </span><br>
                <input type="TEXT" size="25" name="email_from" value="' . $email . '">
              </td>
            </tr>
          </table>
        </center>
        <br>
        <center>
          <table border=0 cellspacing=0 cellpadding=5 >
            <tr>
              <td>
                <p class="bignewgray">
                  '._GALENTERMESSAGE.'
                </p>
                <p align="center">
                  <textarea name="comment" wrap="VIRTUAL" cols="50" rows="9"></textarea>
                  <br>
                </p>
                <p>&nbsp;</p>
              </td>
            </tr>
          </table>
          <table width="100" border="0" cellspacing="5" cellpadding="5">
            <tr>
              <td>
                <input class="button" type="SUBMIT" name="Send" value="'._GALSEND.'">
              </td>
            </tr>
          </table>
          <br>
        </center>
        </form>';
    }

    CloseTable();
    print '<p align="right">'
         .'<font class="meg-sub">'
         .sprintf(_GALCOPYRIGHT, _GALVERSION, "$modulepath/file=credits.php")
         .'</font>'
         .'</p>';
    include("footer.php");
}


function ecard_send()
{
    global $mpnTables, $mailmethod, $smtp, $HTTP_POST_VARS;

    if (isset( $_POST['Send'] ))
    {
        $pid        = $HTTP_POST_VARS['pid'];
        $to_name    = trim( stripslashes( $HTTP_POST_VARS['name_to'] ));
        $to_email   = trim( stripslashes( $HTTP_POST_VARS['email_to'] ));
        $from_name  = trim( stripslashes( $HTTP_POST_VARS['name_from'] ));
        $from_email = trim( stripslashes( $HTTP_POST_VARS['email_from'] ));
        $comment    = trim( strip_tags( stripslashes( $HTTP_POST_VARS['comment'] )));

        if ($pid == '' || $to_name == '' || $to_email == '' || $from_name == '' || $from_email == '' || $comment == '')
        {
            goBack( translate('E-Card is missing items') );
        }

        $sql  = 'SELECT gp.img, gp.width, gp.height, gp.description, gc.galloc, gm.displaytag FROM ';
        $sql .= $mpnTables['gallery_pictures'] . ' gp, ' . $mpnTables['gallery_categories'] . ' gc, ';
        $sql .= $mpnTables['gallery_media_types'] . ' gm ';
        $sql .= "WHERE gp.gid = gc.gallid AND gp.extension = gm.extension AND gp.pid = '$pid' LIMIT 1";
        $result = mysql_query($sql);
        $prow = mysql_fetch_array( $result );

        $img = $text_img = 'gallery/gallery/' . $prow['galloc'] . '/' . $prow['img'];
        $img = str_replace($img, _MPN_ROOT_URI . $img, displayMedia($prow));

        require_once('class.phpmailer.php');
        $mail = new phpmailer();

        /* SET MAIL DELIVERY OPTIONS */
        $mail->IsHTML(true);
        if ($mailmethod == "0") {
            $mail->IsMail();
        } else {
            $mail->IsSMTP();
            $mail->Host = $smtp;
        }

        $html_message  = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' . "\n";
        $html_message .= '<html>' . "\n";
        $html_message .= '<head>' . "\n";
        $html_message .= '<title></title>' . "\n";
        $html_message .= '</head>' . "\n";
        $html_message .= '<body>' . "\n";
        $html_message .= $img . '<br />' . $comment . "\n";
        $html_message .= '</body>' . "\n";
        $html_message .= '</html>' . "\n";

        $text_message  = _MPN_ROOT_URI . $text_img . "\n";
        $text_message .= $comment;

        $mail->From = $from_email;
        $mail->FromName = $from_name;
        $mail->AddAddress($to_email, $to_name);
        $mail->Subject = translate('An E-Card for you');
        $mail->Body = $html_message;
        $mail->AltBody = $text_message;
        $mail->Send();

        //header('location: ./myegallery.php?do=showpic&pid=' . $pid );
	  $_SERVER['F_LIB'] -> redirectRequest( './myegallery.php?do=showpic&pid=' . $pid );
        exit;
    }
}

?>
