<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.7 www.exoops.info 2006/03 
// $Id: kontact.php,v 1.6 2004/02/13 19:51:04 nobse 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, $bcoosConfig,$_POST, $_GET;
    
    if ( empty($_POST['submit']) ) {
        include(XOOPS_ROOT_PATH."/header.php");
    	OpenTable();
    	$user_comments    = '';
        $contact_reason   = $_GET['title'];
        $author   = $_GET['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(_NAME.'*', 'user_name', 30, 60, $user_name);
        $mail_email       = new XoopsFormText(_EMAIL.'*', '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',$_GET['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($_POST['contact_reason']);
		$user_comments    = $myts->oopsStripSlashesGPC($_POST['user_comments']);
		$user_name        = $myts->oopsStripSlashesGPC($_POST['user_name']);
		$user_email       = $myts->oopsStripSlashesGPC($_POST['user_email']);
		$user_url         = $myts->oopsStripSlashesGPC($_POST['user_url']);
		$empfanger           = $_POST['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($_POST['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($_POST['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);
    }
?>
