<?php
// $Id: mailform.php,v 1.1 2004/07/11 10:28:51 Farsus Exp $
// -------------------------------------------------------------------------//
//			       RUNCMS                                                   //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

global $HTTP_SERVER_VARS;
if ( preg_match("/mailform\.php/i", $HTTP_SERVER_VARS['PHP_SELF']) ) {
	exit();
	}

$form = new XoopsThemeForm(_AM_SENDMTOUSERS, "mailusers", "admin.php?fct=mailusers");
$form->setExtra("enctype='multipart/form-data'");

// from finduser section
if (!empty($HTTP_POST_VARS['memberslist_id'])) {
	$user_count = count($HTTP_POST_VARS['memberslist_id']);
	$display_names = "";
	for ( $i=0; $i<$user_count; $i++) {
		$uid_hidden = new XoopsFormHidden("mail_to_user[]", $HTTP_POST_VARS['memberslist_id'][$i]);
		$form->addElement($uid_hidden);
		$display_names .= "<a href='".XOOPS_URL."/userinfo.php?uid=".$HTTP_POST_VARS['memberslist_id'][$i]."' target='_blank'>".$HTTP_POST_VARS['memberslist_uname'][$HTTP_POST_VARS['memberslist_id'][$i]]."</a>, ";
	}
	$users_label = new XoopsFormLabel(_AM_SENDTOUSERS2, substr($display_names, 0, -2));
	$form->addElement($users_label);
	$display_criteria = 0;
}

if ( !empty($display_criteria) ) {
	$group_select    = new XoopsFormSelectGroup(_AM_GROUPIS."<br />", "mail_to_group", false, '----', 5, true);
	$group_select->addOption(0, '----');
	$lastlog_min     = new XoopsFormText(_AM_LASTLOGMIN."<br />"._AM_TIMEFORMAT."<br />", "mail_lastlog_min", 20, 10);
	$lastlog_max     = new XoopsFormText(_AM_LASTLOGMAX."<br />"._AM_TIMEFORMAT."<br />", "mail_lastlog_max", 20, 10);
	$regd_min        = new XoopsFormText(_AM_REGDMIN."<br />"._AM_TIMEFORMAT."<br />", "mail_regd_min", 20, 10);
	$regd_max        = new XoopsFormText(_AM_REGDMAX."<br />"._AM_TIMEFORMAT."<br />", "mail_regd_max", 20, 10);
	$idle_more       = new XoopsFormText(_AM_IDLEMORE."<br />", "mail_idle_more", 10, 5);
	$idle_less       = new XoopsFormText(_AM_IDLELESS."<br />", "mail_idle_less", 10, 5);

	$umail_ok         = new XoopsFormCheckBox('', "mail_ok", 0);
	$umail_ok->addOption(1, _AM_MAILOK);

	$inactive_cbox   = new XoopsFormCheckBox(_AM_INACTIVE."<br />", "mail_inactive");
	$inactive_cbox->addOption(1, _AMIFCHECKD);
	$inactive_cbox->setExtra("onclick='disableElement(\"mail_lastlog_min\"); disableElement(\"mail_lastlog_max\"); disableElement(\"mail_idle_more\"); disableElement(\"mail_idle_less\"); disableElement(\"mail_to_group\");'");

	$criteria_tray = new XoopsFormElementTray(_AM_SENDTOUSERS, "<br /><br />");
	$criteria_tray->addElement($group_select);
	$criteria_tray->addElement($lastlog_min);
	$criteria_tray->addElement($lastlog_max);
	$criteria_tray->addElement($idle_more);
	$criteria_tray->addElement($idle_less);

	$criteria_tray->addElement($umail_ok);

	$criteria_tray->addElement($inactive_cbox);
	$criteria_tray->addElement($regd_min);
	$criteria_tray->addElement($regd_max);
	$form->addElement($criteria_tray);
}

$fname_text      = new XoopsFormText(_AM_MAILFNAME, "mail_fromname", 30, 255, $meta['title']);
$fromemail       = !empty($xoopsConfig['adminmail']) ? $xoopsConfig['adminmail'] : $xoopsUser->getVar("email", "E");
$femail_text     = new XoopsFormText(_AM_MAILFMAIL, "mail_fromemail", 30, 255, $xoopsUser->getVar("email", "E"));
$subject_caption = _AM_MAILSUBJECT."<br /><br /><span style='font-size:x-small;font-weight:bold;'>"._AM_MAILTAGS."</span><br /><span style='font-size:x-small;font-weight:normal;'>"._AM_MAILTAGS2."</span>";
$subject_text    = new XoopsFormText($subject_caption, "mail_subject", 50, 255);
$body_caption    = _AM_MAILBODY."<br /><br /><span style='font-size:x-small;font-weight:bold;'>"._AM_MAILTAGS."</span><br /><span style='font-size:x-small;font-weight:normal;'>"._AM_MAILTAGS1."<br />"._AM_MAILTAGS2."<br />"._AM_MAILTAGS3."<br />"._AM_MAILTAGS4."</span>";
$body_text       = new XoopsFormTextArea($body_caption, "mail_body", "", 10);
$to_checkbox     = new XoopsFormCheckBox(_AM_SENDTO, "mail_send_to", "mail");
$to_checkbox->addOption("mail", _AM_EMAIL);
$to_checkbox->addOption("pm", _AM_PM);

$to_emails = new XoopsFormText(_AM_TOEMAILS, "mail_to_emails", 55, 255);
$priority  = new XoopsFormSelect(_AM_PRIORITY, "mail_priority", 3);
$priority->addOptionArray(array(1 => '1 (Highest)', 2 => '2 (High)', 3 => '3 (Normal)', 4 => '4 (Low)', 5 => '5 (Lowest)'));
$mail_type = new XoopsFormRadio(_AM_TYPE, "mail_type", "text/plain");
$mail_type->addOption("text/html", "HTML");
$mail_type->addOption("text/plain", "TEXT");

$reciept = new XoopsFormCheckBox(_AM_RECIEPT, "mail_reciept", 0);
$reciept->addOption(1, _YES);

$file_select = new XoopsFormElementTray(_AM_ATTACH);
$file_browse = new XoopsFormFile('', 'attachment', 512000);
$file_inline = new XoopsFormCheckBox('', "inline", 0);
$file_inline->addOption(1, _AM_INLINE);
$file_select->addElement($file_browse);
$file_select->addElement($file_inline);

$op_hidden     = new XoopsFormHidden("op", "send");
$submit_button = new XoopsFormButton("", "mail_submit", _SEND, "submit");

$form->addElement($to_emails);
$form->addElement($priority);
$form->addElement($mail_type);
$form->addElement($reciept);
$form->addElement($fname_text);
$form->addElement($femail_text);
$form->addElement($subject_text);
$form->addElement($body_text);
$form->addElement($file_select);
$form->addElement($to_checkbox);
$form->addElement($op_hidden);
$form->addElement($submit_button);

$form->setRequired(array("mail_subject", "mail_body", "mail_send_to"));
?>
