<?xml version="1.0" encoding="UTF-8"?>
<dynaForm name="processes_New" width="600px" labelWidth="40%" enableTemplate="1">
  <THETITLE type="title" group="1">
    <en><![CDATA[Configuration]]></en>
  </THETITLE>
  <MESS_ENABLED type="checkbox" value="1">
    <en><![CDATA[Enable Email Notifications]]></en>
  </MESS_ENABLED>
  <MESS_ENGINE type="dropdown" sqlconnection="dbarray">
  select * from mails
  <en><![CDATA[Email Engine]]></en>
</MESS_ENGINE>
  <MESS_SERVER type="text" size="35" maxlength="100" required="true">
    <en><![CDATA[Server]]></en>
  </MESS_SERVER>
  <MESS_PORT type="text" size="5" maxlength="5" validate="Int">
    <en><![CDATA[Port (default 25)]]></en>
  </MESS_PORT>
  <MESS_RAUTH type="checkbox" value="1">
    <en><![CDATA[Require authentication]]></en>
  </MESS_RAUTH>
  <MESS_ACCOUNT type="text" size="35" maxlength="50" validate="Email">
    <en><![CDATA[SMTP Username]]></en>
  </MESS_ACCOUNT>
  <MESS_PASSWORD type="password" size="35" maxlength="50">
    <en><![CDATA[SMTP Password]]></en>
  </MESS_PASSWORD>
  <MESS_PASSWORD_HIDDEN type="hidden" size="35" maxlength="100">
    <en/>
  </MESS_PASSWORD_HIDDEN>
  <MESS_TEST_MAIL type="checkbox" value="1">
    <en><![CDATA[Send a test mail]]></en>
  </MESS_TEST_MAIL>
  <MESS_TEST_MAIL_TO type="text" size="35" maxlength="100" required="true">
    <en><![CDATA[Mail to]]></en>
  </MESS_TEST_MAIL_TO>
  <SMTPSecure type="radiogroup" required="0" mode="edit" options="Array" viewAlign="horizontal" defaultValue="none">
    <en><![CDATA[Use Secure Connection]]><option name="none"><![CDATA[No]]></option><option name="tls"><![CDATA[TLS]]></option><option name="ssl"><![CDATA[SSL]]></option></en>
  </SMTPSecure>
  <MESS_BACKGROUND type="checkbox" value="1">
    <en><![CDATA[Run in the background]]></en>
  </MESS_BACKGROUND>
  <MESS_EXECUTE_EVERY type="text" size="5" maxlength="5" required="true" validate="Int" defaultValue="5">
    <en><![CDATA[Execute every (in minutes)]]></en>
  </MESS_EXECUTE_EVERY>
  <MESS_SEND_MAX type="text" size="5" maxlength="5" required="true" validate="Int" defaultValue="50">
    <en><![CDATA[Maximun number of mails sended by attempt]]></en>
  </MESS_SEND_MAX>
  <MESS_TRY_SEND_INMEDIATLY type="checkbox" value="1">
    <en><![CDATA[Try to send emails immediately]]></en>
  </MESS_TRY_SEND_INMEDIATLY>
  <TEST type="button" onclick="javascript:verifyFields();">
    <en><![CDATA[Test]]></en>
  </TEST>
  <SAVE_CHANGES type="button" onclick="javascript:verifyData(this.form);">
    <en><![CDATA[Save Changes]]></en>
  </SAVE_CHANGES>
  <SAVE_CHANGES2 type="button" onclick="javascript:verifyData(this.form);">
    <en><![CDATA[Save Changes]]></en>
  </SAVE_CHANGES2>
  <JS type="javascript"><![CDATA[
	leimnud.event.add(getField('MESS_SERVER'), 'change', function() {
	  getField('MESS_PASSWORD_HIDDEN').value = '';
	  getField('MESS_PASSWORD').value = '';
	}.extend(getField('MESS_ENABLED')));
	   
	leimnud.event.add(getField('MESS_PASSWORD'), 'change', function() {
	  if (getField('MESS_PASSWORD').value != '') {
		  getField('MESS_PASSWORD_HIDDEN').value = '';
		}		
	}.extend(getField('MESS_ENABLED')));
	 
	getField('MESS_PASSWORD_HIDDEN').value  = getField('MESS_PASSWORD').value;		
	getField('MESS_PASSWORD').value = '';
    //settings events
    leimnud.event.add(getField('MESS_RAUTH'), 'click', function() {
      if (this.checked)
        showRowById('MESS_PASSWORD');
      else
        hideRowById('MESS_PASSWORD');
    }.extend(getField('MESS_RAUTH')));
    
    leimnud.event.add(getField('MESS_TEST_MAIL'), 'click', function() {
      if (this.checked)     
        showRowById('MESS_TEST_MAIL_TO');
      else
        hideRowById('MESS_TEST_MAIL_TO');
    }.extend(getField('MESS_TEST_MAIL')));
    
    leimnud.event.add(getField('MESS_ENABLED'), 'click', function() {
      if (this.checked) {
        showRowById('MESS_ENGINE');
        switch (getField('MESS_ENGINE').value) {
          case 'MAIL':
            hideRowById('MESS_SERVER');
            hideRowById('MESS_PORT');
            hideRowById('MESS_ACCOUNT');
            hideRowById('MESS_PASSWORD');
            hideRowById('SAVE_CHANGES2');
            hideRowById('SMTPSecure');
            showRowById('TEST');
            showRowById('MESS_TEST_MAIL');
            if ( getField('MESS_TEST_MAIL').checked )
              showRowById('MESS_TEST_MAIL_TO');
            else
              hideRowById('MESS_TEST_MAIL_TO');
            
            getField('SAVE_CHANGES').disabled = true;
          break;
          
          case 'PHPMAILER':
            hideRowById('SAVE_CHANGES2');
            showRowById('MESS_SERVER');
            showRowById('MESS_PORT');
            showRowById('MESS_ACCOUNT');
            showRowById('MESS_PASSWORD');
            showRowById('TEST');
            showRowById('SMTPSecure');
            showRowById('MESS_RAUTH');
            showRowById('MESS_TEST_MAIL');
            
            if ( getField('MESS_TEST_MAIL').checked)
              showRowById('MESS_TEST_MAIL_TO');
            else
              hideRowById('MESS_TEST_MAIL_TO');
            //we're checking if the required authentication is checked
            if ( getField('MESS_RAUTH').checked)
              showRowById('MESS_PASSWORD');
            else
              hideRowById('MESS_PASSWORD');
            
            getField('SAVE_CHANGES').disabled = true;
           break;
         }
          //showRowById('MESS_BACKGROUND');////enable this line in the next release
          if (getField('MESS_BACKGROUND').checked) {
            showRowById('MESS_EXECUTE_EVERY');
            showRowById('MESS_SEND_MAX');
            showRowById('MESS_TRY_SEND_INMEDIATLY');
          }
          else {
            hideRowById('MESS_EXECUTE_EVERY');
            hideRowById('MESS_SEND_MAX');
            hideRowById('MESS_TRY_SEND_INMEDIATLY');
          }
      } else {
        hideRowById('MESS_ENGINE');
        hideRowById('MESS_SERVER');
        hideRowById('MESS_PORT');
        hideRowById('MESS_ACCOUNT');
        hideRowById('MESS_PASSWORD');
        hideRowById('MESS_BACKGROUND');
        hideRowById('MESS_EXECUTE_EVERY');
        hideRowById('MESS_SEND_MAX');
        hideRowById('MESS_TRY_SEND_INMEDIATLY');
        hideRowById('TEST');
        hideRowById('SMTPSecure');
        hideRowById('MESS_RAUTH');
        hideRowById('MESS_TEST_MAIL');
        hideRowById('MESS_TEST_MAIL_TO');
        showRowById('SAVE_CHANGES2');
        getField('SAVE_CHANGES').disabled = false;
      }
    }.extend(getField('MESS_ENABLED')));
    
    leimnud.event.add(getField('MESS_ENGINE'), 'change', function() {
      switch (this.value) {
        case 'MAIL':
          hideRowById('MESS_SERVER');
          hideRowById('MESS_PORT');
          hideRowById('MESS_ACCOUNT');
          hideRowById('MESS_PASSWORD');
          hideRowById('MESS_RAUTH');
          showRowById('MESS_TEST_MAIL');
          if ( getField('MESS_TEST_MAIL').checked)
            showRowById('MESS_TEST_MAIL_TO');
          else
            hideRowById('MESS_TEST_MAIL_TO');
          
          getField('SAVE_CHANGES').disabled = true
        break;
        
        case 'PHPMAILER':
          hideRowById('SAVE_CHANGES2');
        
        case 'OPENMAIL':
          showRowById('MESS_SERVER');
          showRowById('MESS_PORT');
          showRowById('MESS_ACCOUNT');
          showRowById('MESS_PASSWORD');
          showRowById('TEST');
          showRowById('MESS_RAUTH');
          showRowById('MESS_TEST_MAIL');
          if ( getField('MESS_TEST_MAIL').checked )
            showRowById('MESS_TEST_MAIL_TO');
          else
            hideRowById('MESS_TEST_MAIL_TO');
          
          getField('SAVE_CHANGES').disabled = true;
        break;
      }
    }.extend(getField('MESS_ENGINE')));
    
    leimnud.event.add(getField('MESS_BACKGROUND'), 'click', function() {
      if (this.checked) {
        showRowById('MESS_EXECUTE_EVERY');
        showRowById('MESS_SEND_MAX');
        showRowById('MESS_TRY_SEND_INMEDIATLY');
      }
      else {
        hideRowById('MESS_EXECUTE_EVERY');
        hideRowById('MESS_SEND_MAX');
        hideRowById('MESS_TRY_SEND_INMEDIATLY');
      }
    }.extend(getField('MESS_BACKGROUND')));
    
    if (!getField('MESS_ENABLED').checked) {
      hideRowById('MESS_ENGINE');
      hideRowById('MESS_SERVER');
      hideRowById('MESS_PORT');
      hideRowById('MESS_ACCOUNT');
      hideRowById('MESS_PASSWORD');
      hideRowById('MESS_BACKGROUND');
      hideRowById('MESS_EXECUTE_EVERY');
      hideRowById('MESS_SEND_MAX');
      hideRowById('MESS_TRY_SEND_INMEDIATLY');
      //hideRowById('TEST');
    }
    
    switch (getField('MESS_ENGINE').value) {
      case 'MAIL':
        hideRowById('MESS_SERVER');
        hideRowById('MESS_PORT');
        hideRowById('MESS_ACCOUNT');
        hideRowById('MESS_PASSWORD');
      break;
      case 'PHPMAILER':
      case 'OPENMAIL':
        showRowById('MESS_SERVER');
        showRowById('MESS_PORT');
        showRowById('MESS_ACCOUNT');
        showRowById('MESS_PASSWORD');
      break;
    }
    
    hideRowById('MESS_BACKGROUND');//delete this line in the next release
    if (!getField('MESS_BACKGROUND').checked) {
      hideRowById('MESS_EXECUTE_EVERY');
      hideRowById('MESS_SEND_MAX');
      hideRowById('MESS_TRY_SEND_INMEDIATLY');
    }
    if ( getField('MESS_RAUTH').checked)
      showRowById('MESS_PASSWORD');
    else
      hideRowById('MESS_PASSWORD');
    getField('SAVE_CHANGES').disabled = true;
    initSet();
  ]]></JS>
</dynaForm>
