<?php
// $Id: index.php,v 1.1 2004/07/11 10:27:49 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: Half-Dead
// Author Website : http://www.e-xoops.com
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

include_once('header.php');

if (empty($HTTP_POST_VARS['submit'])) {
	if ($xoopsConfig['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;

if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
	echo "<a href='admin/index.php?op=$op#$anchor' target='_blank'><img src='images/editicon.gif' border='0' alt='"._EDIT."' valign='top'  /></a> ";
}
}

//---------------------------------------------------------------------------------------//
/**
* Description
*
* @param type $var description
* @return type description
*/
function show_contact() {
global $db, $myts, $xoopsUser, $xoopsConfig, $meta, $HTTP_POST_VARS, $HTTP_POST_FILES;

include_once("./cache/config.php");

if ( empty($HTTP_POST_VARS['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->fetch_row($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($HTTP_POST_VARS['company_name']);
		$company_location = $myts->oopsStripSlashesGPC($HTTP_POST_VARS['company_location']);
		$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']);
		$user_im          = $myts->oopsStripSlashesGPC($HTTP_POST_VARS['user_im']);
		$user_im_details  = $myts->oopsStripSlashesGPC($HTTP_POST_VARS['user_im_details']);

		$xoopsMailer =& getMailer();
		$xoopsMailer->useMail();
		$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/contact/');
		$xoopsMailer->setTemplate('contact.tpl');
		$xoopsMailer->setToEmails($xoopsConfig['adminmail']);
		$xoopsMailer->setToEmails(explode(',', $contactConfig['bcc_to']));
		$xoopsMailer->setFromEmail($user_email);
		$xoopsMailer->setFromName($user_name);
		$xoopsMailer->setSubject(_CT_CONTACT." - ".$contact_reason);
		$xoopsMailer->setPriority($HTTP_POST_VARS['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($HTTP_POST_VARS['mail_reciept']) ) {
			$xoopsMailer->setReciept($user_email);
		}

		if ( $contactConfig['allow_attachment'] && !empty($HTTP_POST_FILES['mail_attachment']['name']) ) {
			if ($xoopsUser || $contactConfig['annon_attachment']) {
				include_once(XOOPS_ROOT_PATH.'/class/fileupload.php');
				$upload = new fileupload();
				$upload->set_upload_dir(XOOPS_ROOT_PATH.'/cache/', 'mail_attachment');
				$upload->set_overwrite(1, 'mail_attachment');
				$upload->set_accepted($contactConfig['allowed_extensions'], 'mail_attachment');
				$upload->set_max_file_size(intval($contactConfig['max_file_size']), 'mail_attachment');
				$result = $upload->upload();
				if ($result['mail_attachment']['filename']) {
					$xoopsMailer->attachFile(XOOPS_ROOT_PATH.'/cache/'.$result['mail_attachment']['filename'], $result['mail_attachment']['type']);
					@unlink(XOOPS_ROOT_PATH.'/cache/'.$result['mail_attachment']['filename']);
					} 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($xoopsConfig['adminmail']);
			$xoopsMailer->setFromName($meta['title']);
			$xoopsMailer->setSubject(_CT_RECIEVED);
			$xoopsMailer->assign("NAME", $user_name);
			$xoopsMailer->assign("SIGNATURE", $xoopsConfig['adminmail']);
			$xoopsMailer->assign("SITENAME", $meta['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->fetch_row($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;?>" target="_blank"><?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;?>" target="_blank"><?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;?>/" target="_blank"><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;?>/" target="_blank"><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;?>/" target="_blank"><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;?>/" target="_blank"><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;?>/" target="_blank"><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;?>/" target="_blank"><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->fetch_row($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->fetch_row($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($HTTP_POST_VARS['op']) ? $HTTP_POST_VARS['op'] : $HTTP_GET_VARS['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();
}
?>
