<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.2 www.exoops.info 2006/03 
// $Id: index.php,v 1.11 2003/03/19 06:59:52 half-dead 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');
$bcoosConfig['title'] .= " - "._MI_CONTACT_NAME;
if (empty($_POST['submit'])) {
	if ($bcoosConfig['startpage'] == 'contact') {
		$xoopsOption['show_rblock'] = 1;
		include_once(XOOPS_ROOT_PATH.'/header.php');
		make_cblock();
		echo '<br />';
		} else {
			$xoopsOption['show_rblock'] = 0;
			include_once(XOOPS_ROOT_PATH.'/header.php');
		}
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function admin_editlink($op, $anchor='') {
global $xoopsUser, $xoopsModule,$bcoosConfig;
if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
	echo "<a href='admin/index.php?op=$op#$anchor'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."edit.gif' border='0' alt='"._EDIT."' valign='top'  /></a> ";
}
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function show_contact() {
global $db, $myts, $xoopsUser, $bcoosConfig,$_POST, $_FILES;
include_once("./cache/config.php");
if ( empty($_POST['submit']) ) {
	OpenTable();
	$user_comments    = '';
	$company_name     = '';
	$company_location = !empty($xoopsUser) ? $xoopsUser->getVar("user_from", "E") : "";
	$user_name        = !empty($xoopsUser) ? $xoopsUser->getVar("uname", "E")     : "";
	$user_email       = !empty($xoopsUser) ? $xoopsUser->getVar("email", "E")     : "";
	$user_url         = !empty($xoopsUser) ? $xoopsUser->getVar("url", "E")       : "";
	if ($xoopsUser) {
		if ($xoopsUser->getVar("user_icq")) {
			$user_im         = 'ICQ';
			$user_im_details = $xoopsUser->getVar("user_icq", "E");
			} elseif ($xoopsUser->getVar("user_aim")) {
				$user_im         = 'AIM';
				$user_im_details = $xoopsUser->getVar("user_aim", "E");
				} elseif ($xoopsUser->getVar("user_yim")) {
					$user_im         = 'YIM';
					$user_im_details = $xoopsUser->getVar("user_yim", "E");
					} elseif ($xoopsUser->getVar("user_msnm")) {
						$user_im         = 'MSNM';
						$user_im_details = $xoopsUser->getVar("user_msnm", "E");
					}
	}
	$query = $db->query("SELECT contact_text, contact_options, contact_reasons FROM ".$db->prefix("contact")."");
	list($contact_text, $contact_options, $contact_reason) = $db->fetchRow($query);
	if ($contact_text) {
		$contact_options = explode('|', $contact_options);
		$allow_html      = $contact_options[0];
		$allow_smileys   = $contact_options[1];
		$allow_bbcode    = $contact_options[2];
		admin_editlink('edit_contact');
		$myts->setType('admin');
		OpenTable();
		echo $myts->makeTareaData4Show($contact_text, $allow_html, $allow_smileys, $allow_bbcode);
		CloseTable();
	}
	include_once('include/contactform.php');
	CloseTable();
	include_once(XOOPS_ROOT_PATH.'/footer.php');
	} else {
		$company_name     = $myts->oopsStripSlashesGPC($_POST['company_name']);
		$company_location = $myts->oopsStripSlashesGPC($_POST['company_location']);
		$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']);
		$user_im          = $myts->oopsStripSlashesGPC($_POST['user_im']);
		$user_im_details  = $myts->oopsStripSlashesGPC($_POST['user_im_details']);
		$xoopsMailer =& getMailer();
		$xoopsMailer->useMail();
		$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/contact/');
		$xoopsMailer->setTemplate('contact.tpl');
		$xoopsMailer->setToEmails($bcoosConfig['adminmail']);
		$xoopsMailer->setToEmails(explode(',', $contactConfig['bcc_to']));
		$xoopsMailer->setFromEmail($user_email);
		$xoopsMailer->setFromName($user_name);
		$xoopsMailer->setSubject(_CT_CONTACT." - ".$contact_reason);
		$xoopsMailer->setPriority($_POST['mail_priority']);
		$xoopsMailer->assign("COMPANY", $company_name);
		$xoopsMailer->assign("LOCATION", $company_location);
		$xoopsMailer->assign("URL", $user_url);
		$xoopsMailer->assign("IM", $user_im);
		$xoopsMailer->assign("IMNO", $user_im_details);
		$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);
		}
		if ( $contactConfig['allow_attachment'] && !empty($_FILES['mail_attachment']['name']) ) {
			if ($xoopsUser || $contactConfig['annon_attachment']) {
				include_once(XOOPS_ROOT_PATH.'/class/upload.class.php');
				$upload = new Upload();
				$upload->setUploadPath(XOOPS_ROOT_PATH.'/modules/contact/cache');
				$upload->setDestinationFileName('mail_attachment');
				$upload->setAllowedMimeTypes(".gif|.jpeg|.jpg|.png");
				$upload->setMaxFileSize($contactConfig['max_file_size']);
				$result = $upload->doUpload();
				if ($result) {
					$xoopsMailer->attachFile(XOOPS_ROOT_PATH.'/modules/contact/cache/'.$upload->HTTP_POST_FILES[$upload->uploadFieldName]['name'], $upload->HTTP_POST_FILES[$upload->uploadFieldName]['type']);
					@unlink(XOOPS_ROOT_PATH.'/modules/contact/cache/'.$upload->HTTP_POST_FILES[$upload->uploadFieldName]['name']);
					} else {
						$message_errors = $upload->errors(0);
					}
			}
		}
		$xoopsMailer->send();
		$message_errors .= $xoopsMailer->getErrors();
		if ($contactConfig['send_confirmation'] == 1) {
			$xoopsMailer =& getMailer();
			$xoopsMailer->useMail();
			$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/contact/');
			$xoopsMailer->setTemplate('confirmation.tpl');
			$xoopsMailer->setToEmails($user_email);
			$xoopsMailer->setFromEmail($bcoosConfig['adminmail']);
			$xoopsMailer->setFromName($bcoosConfig['title']);
			$xoopsMailer->setSubject(_CT_RECIEVED);
			$xoopsMailer->assign("NAME", $user_name);
			$xoopsMailer->assign("SIGNATURE", $bcoosConfig['adminmail']);
			$xoopsMailer->assign("SITENAME", $bcoosConfig['title']);
			$xoopsMailer->send();
			$message_errors .= $xoopsMailer->getErrors();
		}
	$messagesent = _CT_MESSAGESENT."<br /><br />".$message_errors."";
	redirect_header(XOOPS_URL.'/index.php', 2, $messagesent);
}
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function show_link() {
global $db, $myts;
$sql = "
	SELECT
	intro_text,
	intro_options,
	text_caption,
	text_alt,
	text_custom,
	logo_img,
	logo_alt,
	logo_custom,
	button_img,
	button_alt,
	button_custom,
	banner_img,
	banner_alt,
	banner_custom
	FROM ".$db->prefix("contact")."";
$query = $db->query($sql);
list($intro_text, $intro_options, $text_caption, $text_alt, $text_custom, $logo_img, $logo_alt, $logo_custom, $button_img, $button_alt, $button_custom, $banner_img, $banner_alt, $banner_custom) = $db->fetchRow($query);
if ($text_caption || $text_custom || $logo_img || $logo_custom || $button_img || $button_custom || $banner_img || $banner_custom) {
	OpenTable();
	if ($intro_text) {
		$intro_options = explode('|', $intro_options);
		$allow_html      = $intro_options[0];
		$allow_smileys   = $intro_options[1];
		$allow_bbcode    = $intro_options[2];
		$myts->setType('admin');
		admin_editlink('edit_link');
		OpenTable();
		echo $myts->makeTareaData4Show($intro_text, $allow_html, $allow_smileys, $allow_bbcode);
		CloseTable();
	}
	if ($text_custom) {
		?>
		<h6><?php admin_editlink('edit_link', 'text');?><?php echo _CT_TEXT;?>:</h6>
		<?php echo $text_custom;?><br /><br />
		<textarea class="textarea" rows="5" cols="60"><?php echo $text_custom;?></textarea>
		<?php
		} elseif ($text_caption) {
			$text_caption = $myts->makeTboxData4Show($text_caption);
			$text_alt     = $myts->makeTboxData4Show($text_alt);
			?>
			<h6><?php admin_editlink('edit_link', 'text');?><?php echo _CT_TEXT;?>:</h6>
			<a href="<?php echo XOOPS_URL;?>/" title="<?php echo $text_alt;?>"><?php echo $text_caption;?></a><br /><br />
			<textarea class="textarea" rows="5" cols="60"><a href="<?php echo XOOPS_URL;?>/" title="<?php echo $text_alt;?>"><?php echo $text_caption;?></a></textarea>
			<?php
		}
	if ($button_custom) {
		?>
		<h6><?php admin_editlink('edit_link', 'button');?><?php echo _CT_BUTTON;?>:</h6>
		<?php echo $button_custom;?><br /><br />
		<textarea class="textarea" rows="5" cols="60"><?php echo $button_custom;?></textarea>
		<?php
		} elseif ($button_img) {
			$button_alt = $myts->makeTboxData4Show($button_alt);
			?>
			<h6><?php admin_editlink('edit_link', 'button');?><?php echo _CT_BUTTON;?>:</h6>
			<a href="<?php echo XOOPS_URL;?>/" ><img src="<?php echo formatURL(XOOPS_URL.'/modules/contact/cache/images/', $button_img);?>" alt="<?php echo $button_alt;?>" border="0" /></a><br /><br />
			<textarea class="textarea" rows="5" cols="60"><a href="<?php echo XOOPS_URL;?>/"><img src="<?php echo formatURL(XOOPS_URL.'/modules/contact/cache/images/', $button_img);?>" alt="<?php echo $button_alt;?>" border="0" /></a></textarea>
			<?php
		}
	if ($logo_custom) {
		?>
		<h6><?php admin_editlink('edit_link', 'logo');?><?php echo _CT_LOGO;?>:</h6>
		<?php echo $logo_custom;?><br /><br />
		<textarea class="textarea" rows="5" cols="60"><?php echo $logo_custom;?></textarea>
		<?php
		} elseif ($logo_img) {
			$logo_alt = $myts->makeTboxData4Show($logo_alt);
			?>
			<h6><?php admin_editlink('edit_link', 'logo');?><?php echo _CT_LOGO;?>:</h6>
			<a href="<?php echo XOOPS_URL;?>/"><img src="<?php echo formatURL(XOOPS_URL.'/modules/contact/cache/images/', $logo_img);?>" alt="<?php echo $logo_alt;?>" border="0" /></a><br /><br />
			<textarea class="textarea" rows="5" cols="60"><a href="<?php echo XOOPS_URL;?>/"><img src="<?php echo formatURL(XOOPS_URL.'/modules/contact/cache/images/', $logo_img);?>" alt="<?php echo $logo_alt;?>" border="0" /></a></textarea>
			<?php
		}
	if ($banner_custom) {
		?>
		<h6><?php admin_editlink('edit_link', 'banner');?><?php echo _CT_BANNER;?>:</h6>
		<?php echo $banner_custom;?><br /><br />
		<textarea class="textarea" rows="5" cols="60"><?php echo $banner_custom;?></textarea>
		<?php
		} elseif ($banner_img) {
			$banner_alt = $myts->makeTboxData4Show($banner_alt);
			?>
			<h6><?php admin_editlink('edit_link', 'banner');?><?php echo _CT_BANNER;?>:</h6>
			<a href="<?php echo XOOPS_URL;?>/"><img src="<?php echo formatURL(XOOPS_URL.'/modules/contact/cache/images/', $banner_img);?>" alt="<?php echo $banner_alt;?>" border="0" /></a><br /><br />
			<textarea class="textarea" rows="5" cols="60"><a href="<?php echo XOOPS_URL;?>/"><img src="<?php echo formatURL(XOOPS_URL.'/modules/contact/cache/images/', $banner_img);?>" alt="<?php echo $banner_alt;?>" border="0" /></a></textarea>
			<?php
		}
	CloseTable();
	include_once(XOOPS_ROOT_PATH.'/footer.php');
	} else {
		show_contact();
	}
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function show_about() {
global $db, $myts;
$query = $db->query("SELECT about_text, about_options FROM ".$db->prefix("contact")."");
list($about_text, $about_options) = $db->fetchRow($query);
if ($about_text) {
	$about_options = explode('|', $about_options);
	$allow_html    = $about_options[0];
	$allow_smileys = $about_options[1];
	$allow_bbcode  = $about_options[2];
	$myts->setType('admin');
	admin_editlink('edit_about');
	OpenTable();
	echo $myts->makeTareaData4Show($about_text, $allow_html, $allow_smileys, $allow_bbcode);
	CloseTable();
	include_once(XOOPS_ROOT_PATH.'/footer.php');
	} else {
		show_contact();
	}
exit();
}
//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function show_policy() {
global $db, $myts;
$query = $db->query("SELECT policy_text, policy_options FROM ".$db->prefix("contact")."");
list($policy_text, $policy_options) = $db->fetchRow($query);
if ($policy_text) {
	$policy_options = explode('|', $policy_options);
	$allow_html     = $policy_options[0];
	$allow_smileys  = $policy_options[1];
	$allow_bbcode   = $policy_options[2];
	$myts->setType('admin');
	admin_editlink('edit_policy');
	OpenTable();
	echo $myts->makeTareaData4Show($policy_text, $allow_html, $allow_smileys, $allow_bbcode);
	CloseTable();
	include_once(XOOPS_ROOT_PATH.'/footer.php');
	} else {
		show_contact();
	}
exit();
}
// ------------------------------------------------------------------------- //
$op = !empty($_POST['op']) ? $_POST['op'] : $_GET['op'];
switch($op) {
	case 'about':
		show_about();
		break;
	case 'contact':
		show_contact();
		break;
	case 'policy':
		show_policy();
		break;
	case 'link':
		show_link();
		break;
	default:
		show_about();
}
?>
