<?php
##############################################################
##In-portal													##
##############################################################
##					      In-portal							##
##					Intechnic Corporation					##
##			   All Rights Reserved, 1998-2002				##
##															##	
##	No portion of this code may be copied, reproduced or	##	
##	   otherwise redistributed without proper written		##
##	  consent of Intechnic Corporation.  Violation will		##
##	   result in revocation of the license and support		##
##	 privileges along maximum prosecution allowed by law.	##
##############################################################
if(!strlen($pathtoroot))
{
  $path=dirname(realpath(__FILE__));
  if(strlen($path))
  {
    /* determine the OS type for path parsing */
    $pos = strpos($path,":");
    if ($pos === false)
    {
      $gOS_TYPE="unix";
      $pathchar = "/";
    }
    else
    {
      $gOS_TYPE="win";
      $pathchar="\\";
    }
    $p = $path.$pathchar;
    /*Start looking for the root flag file */
    while(!strlen($pathtoroot) && strlen($p))
    {
      $sub = substr($p,strlen($pathchar)*-1);
      if($sub==$pathchar)
      {
        $filename = $p."root.flg";
      }
      else
        $filename = $p.$pathchar."root.flg";
      if(file_exists($filename))
      {
        $pathtoroot = $p;
      }
      else
      {
        $parent = realpath($p.$pathchar."..".$pathchar);
	if($parent!=$p)
	{
	  $p = $parent;
	}
	else
	  $p = "";
      }
    }
    if(!strlen($pathtoroot))
      $pathtoroot = ".".$pathchar;
  }
  else
  {
    $pathtoroot = ".".$pathchar;
  }
}

$sub = substr($pathtoroot,strlen($pathchar)*-1);
if($sub!=$pathchar)
{
  $pathtoroot = $pathtoroot.$pathchar;
}
//echo $pathtoroot;
//print_r($_GET);
//print_r($_POST);
require_once($pathtoroot."kernel/startup.php");
//admin only util

/* set the destination of the image upload, relative to the root path */
$DestDir = "kernel/images/";

$rootURL="http://".ThisDomain().$objConfig->Get("Site_Path");

$admin = $objConfig->Get("AdminDirectory");
if(!strlen($admin))
    $admin = "admin";

$localURL=$rootURL."kernel/";
$adminURL = $rootURL.$admin;
$imagesURL = $adminURL."/images"; 
$cssURL = $adminURL."/include";
$browseURL = $adminURL."/browse";

//$pathtolocal = $pathtoroot."kernel/";
require_once ($pathtoroot.$admin."/include/elements.php");
require_once ($pathtoroot."kernel/admin/include/navmenu.php");
//require_once ($pathtolocal."admin/include/navmenu.php");
require_once($pathtoroot.$admin."/browse/toolbar.php");
//require_once($pathtoroot.$admin."/listview/listview.php");
require_once($pathtoroot.$admin."/editor/FCKeditor/fckeditor.php");

$m = GetModuleArray();
foreach($m as $key=>$value)
{
    $path = $pathtoroot. $value."admin/include/parser.php";
    if(file_exists($path))
    {
      include_once($path);
    }
}

$objLangEdit = new clsLanguageList();
$objLangEdit->SourceTable = $objSession->GetEditTable("Language");
$objLangEdit->EnablePaging = FALSE;
$en = (int)$_GET["en"];
$objLangEdit->Query_Item("SELECT * FROM ".$objLangEdit->SourceTable);
$itemcount=$objLangEdit->NumItems();
$l = $objLangEdit->GetItemByIndex($en);
$LangId = $l->Get("LanguageId");

unset($objEditItems);

$objEditItems = new clsEmailMessageList();
$objEditItems->SourceTable = $objSession->GetEditTable("EmailMessage");
$objEditItems->EnablePaging = FALSE;
if(is_array($_POST["itemlist"]))
{
  $EventId = $_POST["itemlist"][0];
}
else
{ 
  $EventId = $_POST["itemlist"];
}

$m = $objEditItems->GetMessage($EventId,$LangId);

$objEvents = new clsEventList();

$ev = $objEvents->GetItem($EventId);

if($m===FALSE)
{
  $m = new clsEmailMessage();
  $m->tablename = $objEditItems->SourceTable;
  $m->Set("EventId",$EventId);
  $m->Set("LanguageId",$LangId);
  $id = (int)GetMinValue($m->tablename,"EmailMessageId");
  $m->Set("EmailMessageId",$id-1);  
  $m->Create();
  $m->Set("EmailMessageId",$id-1);  
  $m->headers = explode("\n",$objConfig->Get("Smtp_DefaultHeaders"));
}
else
{
  $m->ReadTemplate();
}
$subject = $m->subject;

if(strlen($subject))
  $subject = substr($subject,strpos($subject,":")+2);

$action = "m_emailevent_edit";

$envar = "env=" . BuildEnv() . "&en=$en";
$section = 'in-portal:lang_email';
$ado = &GetADODBConnection();

/* page header */
$charset = GetRegionalOption('Charset');
print <<<END
<html>
<head>
  <title>In-portal</title>
  <meta http-equiv="content-type" content="text/html;charset=$charset">
  <meta http-equiv="Pragma" content="no-cache">
  <script language="JavaScript">
    imagesPath='$imagesURL'+'/';
  </script>
  <script src="$browseURL/common.js"></script>
  <script src="$browseURL/toolbar.js"></script>
  <script src="$browseURL/utility.js"></script>
  <script src="$browseURL/checkboxes.js"></script>
 
  <script language="JavaScript1.2" src="$browseURL/fw_menu.js"></script>
  <link rel="stylesheet" type="text/css" href="$browseURL/checkboxes.css">
  <link rel="stylesheet" type="text/css" href="$cssURL/style.css">
  <link rel="stylesheet" type="text/css" href="$browseURL/toolbar.css">
END;

$objListToolBar = new clsToolBar();

$objListToolBar->Add("msg_save", "la_Save","#","swap('msg_save','toolbar/tool_select_f2.gif');", "swap('msg_save', 'toolbar/tool_select.gif');","edit_submit('language','LangEditStatus','".$admin."/config/addlang_email.php',0);",$imagesURL."/toolbar/tool_select.gif");
$objListToolBar->Add("msg_cancel", "la_Cancel","#","swap('msg_cancel','toolbar/tool_cancel_f2.gif');", "swap('msg_cancel', 'toolbar/tool_cancel.gif');","msg_submit('language','".$admin."/config/addlang_email.php');", $imagesURL."/toolbar/tool_cancel.gif");
 

$title = prompt_language("la_Text_Editing")." ".prompt_language("la_Text_MailEvent")." '".prompt_language($ev->Get("Description"))."'";
if($ev->Get("Type")==0)
{
    $title .= " - ".prompt_language("la_Text_User");
}
else
   $title .= " - ".prompt_language("la_Text_Admin");

int_header($objListToolBar,NULL,$title);
?> 

<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tableborder">
<form ID="language" name="langage" action="" method=POST>   
  <input type="hidden" name="LangEditStatus" VALUE="0">
  <INPUT TYPE="HIDDEN" NAME="Action" VALUE="m_emailevent_edit">
  <INPUT TYPE="HIDDEN" NAME="MessageId" VALUE="<?php echo $m->Get("EmailMessageId"); ?>">

  <?php int_subsection_title(prompt_language("la_tab_General")); ?>

  <tr <?php int_table_color(); ?>> 
    <td valign="top"><span class="text"><?php echo prompt_language("la_prompt_Subject"); ?></span></td>
    <td> 
      <input type="text" tabindex="1" name="subject" class="text" size="60" value="<?php echo htmlspecialchars($subject); ?>">
    </td>
    <td></td>
  </tr>

  <TR <?php int_table_color(); ?>> 
    <td valign="top"><span class="text"><?php echo prompt_language("la_prompt_sendmethod"); ?></SPAN></TD>
     <TD><span class="text">
        <input type="RADIO" tabindex="2" NAME="sendhtml" VALUE="0" <?php if($m->Get("MessageType")!="html") echo "CHECKED"; ?>><?php echo prompt_language("la_prompt_plaintext"); ?>
        <INPUT TYPE="RADIO" tabindex="2" NAME="sendhtml" VALUE="1" <?php if($m->Get("MessageType")=="html") echo "CHECKED"; ?>><?php echo prompt_language("la_prompt_html"); ?>
        </span>
     </td>
     <td></td>
  </TR>

  <tr <?php int_table_color(); ?>> 
    <td valign="top"><span class="text"><?php echo prompt_language("la_prompt_headers"); ?></span></td>
    <td> 
        <textarea name="headers" tabindex="3" id="headers" rows="5" cols="60"><?php echo implode("\n",$m->headers); ?></textarea>
    </td>
    <td></td>
  </tr>

  <?php int_subsection_title(prompt_language("la_tab_Message")); ?>
  <tr <?php int_table_color(); ?>> 
    <td valign="top" COLSPAN=3>
<?php
//   $oFCKeditor = new FCKeditor();
//   $oFCKeditor->Value = $m->body;
//   $oFCKeditor->CreateFCKeditor( 'messageBody', '100%',300 ) ;    
?>
		<TEXTAREA name="messageBody" rows=20 cols=85><?php echo $m->body; ?></TEXTAREA>
    </td>
  </tr>
</FORM>
</TABLE>
<?php int_footer(); ?>