{include file="header.tpl.html" application_title="Eventum Installation"}

{literal}
<script language="JavaScript">
<!--
function validateForm(f)
{
    if (isWhitespace(f.hostname.value)) {
        selectField(f, 'hostname');
        alert('{/literal}{t escape=js}Please enter the hostname for the server of this installation of Eventum.{/t}{literal}');
        return false;
    }
    if (isWhitespace(f.relative_url.value)) {
        selectField(f, 'relative_url');
        alert('{/literal}{t escape=js}Please enter the relative URL of this installation of Eventum.{/t}{literal}');
        return false;
    }
    if (isWhitespace(f.db_hostname.value)) {
        selectField(f, 'db_hostname');
        alert('{/literal}{t escape=js}Please enter the database hostname for this installation of Eventum.{/t}{literal}');
        return false;
    }
    if (isWhitespace(f.db_name.value)) {
        selectField(f, 'db_name');
        alert('{/literal}{t escape=js}Please enter the database name for this installation of Eventum.{/t}{literal}');
        return false;
    }
    if (isWhitespace(f.db_username.value)) {
        selectField(f, 'db_username');
        alert('{/literal}{t escape=js}Please enter the database username for this installation of Eventum.{/t}{literal}');
        return false;
    }
    if (f.alternate_user.checked) {
        if (isWhitespace(f.eventum_user.value)) {
            selectField(f, 'eventum_user');
            alert('{/literal}{t escape=js}Please enter the alternate username for this installation of Eventum.{/t}{literal}');
            return false;
        }
    }

    var field = getFormElement(f, 'setup[smtp][from]');
    if (isWhitespace(field.value)) {
        selectField(f, 'setup[smtp][from]');
        alert('{/literal}{t escape=js}Please enter the sender address that will be used for all outgoing notification emails.{/t}{literal}');
        return false;
    }
    if (!isEmail(field.value)) {
        selectField(f, 'setup[smtp][from]');
        alert('{/literal}{t escape=js}Please enter a valid email address for the sender address.{/t}{literal}');
        return false;
    }
    field = getFormElement(f, 'setup[smtp][host]');
    if (isWhitespace(field.value)) {
        selectField(f, 'setup[smtp][host]');
        alert('{/literal}{t escape=js}Please enter the SMTP server hostname.{/t}{literal}');
        return false;
    }
    field = getFormElement(f, 'setup[smtp][port]');
    if ((isWhitespace(field.value)) || (!isNumberOnly(field.value))) {
        selectField(f, 'setup[smtp][port]');
        alert('{/literal}{t escape=js}Please enter the SMTP server port number.{/t}{literal}');
        return false;
    }
    var field1 = getFormElement(f, 'setup[smtp][auth]', 0);
    var field2 = getFormElement(f, 'setup[smtp][auth]', 1);
    if ((!field1.checked) && (!field2.checked)) {
        alert('{/literal}{t escape=js}Please indicate whether the SMTP server requires authentication or not.{/t}{literal}');
        return false;
    }
    if (field1.checked) {
      field = getFormElement(f, 'setup[smtp][username]');
      if (isWhitespace(field.value)) {
          selectField(f, 'setup[smtp][username]');
          alert('{/literal}{t escape=js}Please enter the SMTP server username.{/t}{literal}');
          return false;
      }
      field = getFormElement(f, 'setup[smtp][password]');
      if (isWhitespace(field.value)) {
          selectField(f, 'setup[smtp][password]');
          alert('{/literal}{t escape=js}Please enter the SMTP server password.{/t}{literal}');
          return false;
      }
    }
    return true;
}
function toggleAlternateUserFields()
{
    var f = getForm('install_form');
    var element = getPageElement('alternate_user_row');
    if (f.alternate_user.checked) {
        element.style.display = '';
    } else {
        element.style.display = 'none';
    }
}

function disableAuthFields(f, bool)
{
  if (bool) {
      var bgcolor = '#CCCCCC';
  } else {
      var bgcolor = '#FFFFFF';
  }
  var field = getFormElement(f, 'setup[smtp][username]');
  field.disabled = bool;
  field.style.backgroundColor = bgcolor;
  field = getFormElement(f, 'setup[smtp][password]');
  field.disabled = bool;
  field.style.backgroundColor = bgcolor;
}
//-->
</script>
{/literal}

{if $result != '' and $result != 'success'}
<br />
<table width="400" bgcolor="#003366" border="0" cellspacing="0" cellpadding="1" align="center">
  <tr>
    <td>
      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0">
        <tr>
          <td><img src="{$rel_url}images/icons/error.gif" hspace="2" vspace="2" border="0" align="left"></td>
          <td width="100%" class="default"><span style="font-weight: bold; font-size: 160%; color: red;">{t}An Error Was Found{/t}</span></td>
        </tr>
        <tr>
          <td colspan="2" class="default">
            <br />
            <b>{t}Details:{/t} {$result}</b>
            <br /><br />
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
{/if}

{if $result == 'success'}
<br />
<table width="400" bgcolor="#003366" border="0" cellspacing="0" cellpadding="1" align="center">
  <tr>
    <td>
      <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0">
        <tr>
          <td width="100%" class="default"><span style="font-weight: bold; font-size: 160%;">Success!</span></td>
        </tr>
        <tr>
          <td class="default">
            <br />
            <b>{t}Thank You, Eventum is now properly setup and ready to be used. Open the following URL to login on it for the first time:{/t}</b>
            <br />
            <a class="link" href="{if $smarty.post.is_ssl == 'yes'}https://{else}http://{/if}{$smarty.post.hostname}{$smarty.post.relative_url}">{if $smarty.post.is_ssl == 'yes'}https://{else}http://{/if}{$smarty.post.hostname}{$smarty.post.relative_url}</a>
            <br /><br />
            {t}Email Address{/t}: admin@example.com {t}(literally){/t}<br />
            {t}Password{/t}: admin<br />
            <br />
            <b>{t}NOTE: For security reasons it is highly recommended that the default password be changed as soon as possible.{/t}
            <br /><br />
            <hr size="1" noshade color="#000000">
            {t 1="setup"}Remember to protect your '%1' directory (like changing its permissions) to prevent anyone else from changing your existing Eventum configuration.{/t}
            <br /><br />
            {t}In order to check if your permissions are setup correctly visit the{/t} <a class="link" href="check_permissions.php">{t}Check Permissions{/t}</a> {t}page{/t}.
            {if not $is_imap_enabled}
            <br /><br />
            <hr size="1" noshade color="#000000">
            {t}WARNING: If you want to use the email integration features to download messages saved on a IMAP/POP3 server, you will need to enable the IMAP extension in your PHP.INI configuration file. See the PHP manual for more details.{/t}
            {/if}
            </b>
            <br /><br />
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
{else}
<br />
<table width="600" bgcolor="#000000" border="0" cellspacing="0" cellpadding="1" align="center">
<form name="install_form" action="{$smarty.server.PHP_SELF}" method="post" onSubmit="javascript:return validateForm(this);">
<input type="hidden" name="cat" value="install">
  <tr>
    <td>
      <table bgcolor="#CCCCCC" width="100%" cellspacing="1" cellpadding="2" border="0">
        <tr>
          <td colspan="2" align="center">
            <h1>{t}Eventum Installation{/t}</h1>
            <hr size="1" noshade color="#000000">
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>{t}Server Hostname:{/t} *</b>
          </td>
          <td>
            {assign var="tabindex" value="1"}
            <input type="text" name="hostname" value="{$smarty.post.hostname|default:$smarty.server.HTTP_HOST}" class="default" size="30" tabindex="{$tabindex}">
            {include file="error_icon.tpl.html" field="hostname"}
            <input type="checkbox" name="is_ssl" value="yes" tabindex="{$tabindex}" {if $ssl_mode == 'enabled'}checked{/if}> <span class="default"><b><a id="link" class="link" href="javascript:void(null);" onClick="javascript:toggleCheckbox('install_form', 'is_ssl');">{t}SSL Server{/t}</a></b></span>
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>{t}Eventum Relative URL:{/t} *</b>
          </td>
          <td>
            <input type="text" name="relative_url" value="{$smarty.post.rel_url|default:$rel_url}" class="default" size="30" tabindex="{$tabindex}">
            {include file="error_icon.tpl.html" field="relative_url"}
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <nobr>&nbsp;<b>{t}MySQL Server Hostname:{/t} *</b></nobr>
          </td>
          <td>
            <input type="text" name="db_hostname" class="default" size="30" tabindex="{$tabindex}" value="{$smarty.post.db_hostname}">
            {include file="error_icon.tpl.html" field="db_hostname"}
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>{t}MySQL Database:{/t} *</b>
          </td>
          <td>
            <input type="text" name="db_name" class="default" size="30" tabindex="{$tabindex}" value="{$smarty.post.db_name}">
            {include file="error_icon.tpl.html" field="db_name"}
            <input type="checkbox" name="create_db" value="yes" tabindex="{$tabindex}" {if $smarty.post.create_db == 'yes'}checked{/if}> <span class="default"><b><a id="link" class="link" href="javascript:void(null);" onClick="javascript:toggleCheckbox('install_form', 'create_db');">Create Database</a></b></span>
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>{t}MySQL Table Prefix:{/t}</b>
          </td>
          <td>
            <input type="text" name="db_table_prefix" value="{$smarty.post.db_table_prefix|default:'eventum_'}" class="default" size="30" tabindex="{$tabindex}">
          </td>
        </tr>
        <tr>
          <td colspan="2" class="default" align="center">
            <input type="checkbox" name="drop_tables" value="yes" tabindex="{$tabindex}" {if $smarty.post.drop_tables == 'yes'}checked{/if}> <b><a id="link" class="link" href="javascript:void(null);" onClick="javascript:toggleCheckbox('install_form', 'drop_tables');">{t}Drop Tables If They Already Exist{/t}</a></b>
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>{t}MySQL Username:{/t} *</b>
          </td>
          <td>
            <input type="text" name="db_username" class="default" size="20" tabindex="{$tabindex}" value="{$smarty.post.db_username}">
            {include file="error_icon.tpl.html" field="db_username"}
          </td>
        </tr>
        <tr>
          <td colspan="2" align="center">
            <span class="small_default"><i>(<b>{t}Note{/t}:</b> {t}This user requires permission to create and drop tables in the specified database.{/t}<br />{t}This value is used only for these installation procedures, and is not saved if you provide a separate user below.{/t})</i></span>
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>{t}MySQL Password:{/t}</b>
          </td>
          <td>
            <input type="password" name="db_password" class="default" size="20" tabindex="{$tabindex}" value="{$smarty.post.db_password}">
          </td>
        </tr>
        <tr>
          <td colspan="2" class="default" align="center">
            <input type="checkbox" name="alternate_user" value="yes" onClick="javascript:toggleAlternateUserFields();"  tabindex="{$tabindex}" {if $smarty.post.alternate_user == 'yes'}checked{/if}> <b><a id="link" class="link" href="javascript:void(null);" onClick="javascript:toggleCheckbox('install_form', 'alternate_user');toggleAlternateUserFields();">{t}Use a Separate MySQL User for Normal Eventum Use{/t}</a></b>
          </td>
        </tr>
        <tr id="alternate_user_row">
          <td colspan="2" align="center">
            <table>
              <tr>
                <td>
                  <table width="300" cellpadding="1" cellspacing="0" bgcolor="white" border="0">
                    <tr>
                      <td>
                        <table width="100%" border="0" cellspacing="0" cellpadding="1" bgcolor="#C0C0C0">
                          <tr>
                            <td colspan="2" class="default">
                              <b>{t}Enter the details below:{/t}</b>
                            </td>
                          </tr>
                          <tr>
                            <td class="default" align="right">
                              <nobr>&nbsp;<b>{t}Username:{/t} *</b>&nbsp;</nobr>
                            </td>
                            <td>
                              <nobr><input type="text" class="default" name="eventum_user" size="20" value="{$smarty.post.eventum_user}" tabindex="{$tabindex}">&nbsp;</nobr>
                              {include file="error_icon.tpl.html" field="eventum_user"}
                            </td>
                          </tr>
                          <tr>
                            <td class="default" align="right">
                              <nobr>&nbsp;<b>{t}Password:{/t}</b>&nbsp;</nobr>
                            </td>
                            <td>
                              <nobr><input type="password" class="default" name="eventum_password" size="20" value="{$smarty.post.eventum_password}" tabindex="{$tabindex}">&nbsp;</nobr>
                            </td>
                          </tr>
                          <tr>
                            <td colspan="2" class="default" align="center">
                              <input type="checkbox" name="create_user" value="yes" tabindex="{$tabindex}" {if $smarty.post.create_user == 'yes'}checked{/if}> <b><a id="link" class="link" href="javascript:void(null);" onClick="javascript:toggleCheckbox('install_form', 'create_user');">{t}Create User and Permissions{/t}</a></b>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td colspan="2" class="default" align="right">
            &nbsp;
          </td>
        </tr>
        <tr>
          <td class="default" align="center" colspan="2">
            <h2><b>{t}SMTP Configuration{/t}</b></h2>
            <hr size="1" noshade color="#000000">
          </td>
        </tr>
        <tr>
          <td colspan="2" class="small_default" align="center">
            <b>Note:</b> {t}The SMTP (outgoing mail) configuration is needed to make sure emails are properly sent when creating new users/projects.{/t}
            &nbsp;
            <hr size="1" noshade color="#000000">
          </td>
        </tr>
        <tr>
          <td width="100" class="default" align="right">
            <b>Sender: *</b>
          </td>
          <td width="80%">
            <input type="text" class="default" name="setup[smtp][from]" size="30" value="{$smarty.request.setup.smtp.from|escape:"html"}" tabindex="{$tabindex}">
            {include file="error_icon.tpl.html" field="setup[smtp][from]"}
            <span class="small_default"><i>({t}must be a valid email address{/t})</i></span>
          </td>
        </tr>
        <tr>
          <td width="100" class="default" align="right">
            <b>{t}Hostname:{/t} *</b>
          </td>
          <td width="80%">
            <input type="text" class="default" name="setup[smtp][host]" size="30" value="{$smarty.request.setup.smtp.host|escape:"html"}" tabindex="{$tabindex}">
            {include file="error_icon.tpl.html" field="setup[smtp][host]"}
          </td>
        </tr>
        <tr>
          <td width="100" class="default" align="right">
            <b>{t}Port:{/t} *</b>
          </td>
          <td width="80%">
            <input type="text" class="default" name="setup[smtp][port]" size="5" value="{$smarty.request.setup.smtp.port}" tabindex="{$tabindex}">
            {include file="error_icon.tpl.html" field="setup[smtp][port]"}
          </td>
        </tr>
        <tr>
          <td width="100" class="default" align="right">
            <b>{t}Requires Authentication?{/t}&nbsp;</b>
          </td>
          <td width="80%" class="default">
            <input type="radio" name="setup[smtp][auth]" value="1" {if $smarty.request.setup.smtp.auth == 1}checked{/if} onClick="javascript:disableAuthFields(this.form, false);" tabindex="{$tabindex}">
            <a id="link" class="link" href="javascript:void(null);" onClick="javascript:checkRadio('install_form', 'setup[smtp][auth]', 0);disableAuthFields(getForm('install_form'), false);">{t}Yes{/t}</a>&nbsp;&nbsp;
            <input type="radio" name="setup[smtp][auth]" value="0" {if $smarty.request.setup.smtp.auth != 1}checked{/if} onClick="javascript:disableAuthFields(this.form, true);" tabindex="{$tabindex}">
            <a id="link" class="link" href="javascript:void(null);" onClick="javascript:checkRadio('install_form', 'setup[smtp][auth]', 1);disableAuthFields(getForm('install_form'), true);">{t}No{/t}</a>
          </td>
        </tr>
        <tr>
          <td width="100" class="default" align="right">
            <b>{t}Username:{/t}&nbsp;</b>
          </td>
          <td width="80%">
            <input type="text" class="default" name="setup[smtp][username]" size="20" value="{$smarty.request.setup.smtp.username|escape:"html"}" tabindex="{$tabindex}">
            {include file="error_icon.tpl.html" field="setup[smtp][username]"}
          </td>
        </tr>
        <tr>
          <td width="100" class="default" align="right">
            <b>{t}Password:{/t}&nbsp;</b>
          </td>
          <td width="80%">
            <input type="password" class="default" name="setup[smtp][password]" size="20" value="{$smarty.request.setup.smtp.password|escape:"html"}" tabindex="{$tabindex}">
            {include file="error_icon.tpl.html" field="setup[smtp][password]"}
          </td>
        </tr>
        <tr>
          <td colspan="2" bgcolor="#666666" align="right">
            <input style="font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 90%;" type="submit" value="{t}Start Installation{/t} &gt;&gt;" tabindex="{$tabindex}">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" class="default">
      <b>* {t}Required Fields{/t}</b>
    </td>
  </tr>
</form>
</table>

{literal}
<script language="JavaScript">
<!--
window.onload = setFocus;
function setFocus()
{
    document.install_form.hostname.focus();
    toggleAlternateUserFields();
{/literal}
    {if $smarty.request.setup.smtp.auth != 1}
    disableAuthFields(getForm('install_form'), true);
    {/if}
{literal}
}
//-->
</script>
{/literal}
{/if}

{include file="footer.tpl.html"}