<?php
// $Id: kontact.php,v 1.1 2004/07/11 10:27:51 Farsus Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Half-Dead
// Author Website : http://www.e-xoops.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

    include_once("header.php");
    include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php");
    
    
    global $db, $myts, $xoopsUser, $xoopsConfig, $meta, $HTTP_POST_VARS, $HTTP_GET_VARS;
    
    if ( empty($HTTP_POST_VARS['submit']) ) {
        include(XOOPS_ROOT_PATH."/header.php");
    	OpenTable();
    	$user_comments    = '';
        $contact_reason   = $HTTP_GET_VARS['title'];
        $author   = $HTTP_GET_VARS['auth'];
    	$user_name        = !empty($xoopsUser) ? $xoopsUser->getVar("uname", "E")     : "";
    	$user_email       = !empty($xoopsUser) ? $xoopsUser->getVar("email", "E")     : "";
    	$user_url         = !empty($xoopsUser) ? $xoopsUser->getVar("url", "E")       : "";
        $mail_url         = new XoopsFormText(_CAL_URL2, 'user_url', 30, 255, $user_url);
        $mail_name        = new XoopsFormText(_CAL_NAME.'*', 'user_name', 30, 60, $user_name);
        $mail_email       = new XoopsFormText(_CAL_EMAIL2.'*', 'user_email', 30, 60, $user_email);        
        $mail_reason = new XoopsFormText(_CAL_REASON.'*', 'contact_reason', 50, 60, $contact_reason);
        
        $mail_comments   = new XoopsFormTextArea(_CAL_COMMENTS.'*', 'user_comments', $user_comments);
        $mail_options  = new XoopsFormElementTray(_CAL_OPTIONS, '&nbsp;');
        $mail_reciept  = new XoopsFormCheckBox(_CAL_RECIEPT, 'mail_reciept', 0);
        $mail_reciept->addOption(1, '&nbsp;');
        $mail_priority = new XoopsFormSelect(_CAL_PRIORITY, 'mail_priority', 3);
        $mail_priority->addOptionArray(array(1 => '1 (Highest)', 2 => '2 (High)', 3 => '3 (Normal)', 4 => '4 (Low)', 5 => '5 (Lowest)'));
        $mail_options->addElement($mail_reciept);
        $mail_options->addElement($mail_priority);       
        $umail		 = new XoopsFormHidden('umail',$HTTP_GET_VARS['umail']);
        $mail_op     = new XoopsFormHidden('op', 'contact');
        $mail_submit = new XoopsFormButton('', 'submit', _SUBMIT, 'submit');
        $contact_form = new XoopsThemeForm(_CAL_CONTACT.$author, 'contact', 'kontact.php');
        $contact_form->setExtra("enctype='multipart/form-data'");
        $contact_form->addElement($mail_url);
        $contact_form->addElement($mail_name);
        $contact_form->addElement($mail_email);
        $contact_form->addElement($mail_reason);
        $contact_form->addElement($mail_comments);
        $contact_form->addElement($mail_options);
        $contact_form->addElement($umail);
        $contact_form->addElement($mail_op);
        $contact_form->addElement($mail_submit);
        $contact_form->setRequired(array('user_name', 'user_email', 'contact_reason', 'user_comments'));
        $contact_form->display();
    	CloseTable();
    	include_once(XOOPS_ROOT_PATH.'/footer.php');
	} else {
		$contact_reason   = $myts->oopsStripSlashesGPC($HTTP_POST_VARS['contact_reason']);
		$user_comments    = $myts->oopsStripSlashesGPC($HTTP_POST_VARS['user_comments']);
		$user_name        = $myts->oopsStripSlashesGPC($HTTP_POST_VARS['user_name']);
		$user_email       = $myts->oopsStripSlashesGPC($HTTP_POST_VARS['user_email']);
		$user_url         = $myts->oopsStripSlashesGPC($HTTP_POST_VARS['user_url']);
		$empfanger           = $HTTP_POST_VARS['umail'];		
		$xoopsMailer =& getMailer();
		$xoopsMailer->useMail();
		$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/ecal/');
		$xoopsMailer->setTemplate('contact.tpl');
		$xoopsMailer->setToEmails($empfanger);
		$xoopsMailer->setFromEmail($user_email);
		$xoopsMailer->setFromName($user_name);
		$xoopsMailer->setSubject(_CT_CONTACT." - ".$contact_reason);
		$xoopsMailer->setPriority($HTTP_POST_VARS['mail_priority']);

		$xoopsMailer->assign("URL", $user_url);
		$xoopsMailer->assign("NAME", $user_name);
		$xoopsMailer->assign("EMAIL", $user_email);
		$xoopsMailer->assign("REASON", $contact_reason);
		$xoopsMailer->assign("COMMENTS", $user_comments);
		$xoopsMailer->assign("AGENT", _HTTP_USER_AGENT);
		$xoopsMailer->assign("IP", _REMOTE_ADDR);
		$xoopsMailer->assign("TIME", formatTimestamp(time(), 'm'));

		if ( !empty($HTTP_POST_VARS['mail_reciept']) ) {
			$xoopsMailer->setReciept($user_email);
		}
		
		$xoopsMailer->send();
		$message_errors .= $xoopsMailer->getErrors();
        $messagesent = _CAL_MESSAGESENT."<br /><br />".$message_errors."";
        redirect_header(XOOPS_URL.'/modules/ecal/index.php', 2, $messagesent);
    }
?>
