{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('Please enter the hostname for the server of this installation of Eventum.');
        return false;
    }
    if (isWhitespace(f.relative_url.value)) {
        selectField(f, 'relative_url');
        alert('Please enter the relative URL of this installation of Eventum.');
        return false;
    }
    if (isWhitespace(f.db_hostname.value)) {
        selectField(f, 'db_hostname');
        alert('Please enter the database hostname for this installation of Eventum.');
        return false;
    }
    if (isWhitespace(f.db_name.value)) {
        selectField(f, 'db_name');
        alert('Please enter the database name for this installation of Eventum.');
        return false;
    }
    if (isWhitespace(f.db_username.value)) {
        selectField(f, 'db_username');
        alert('Please enter the database username for this installation of Eventum.');
        return false;
    }
    if (f.alternate_user.checked) {
        if (isWhitespace(f.eventum_user.value)) {
            selectField(f, 'eventum_user');
            alert('Please enter the alternate username for this installation of Eventum.');
            return false;
        }
    }

    var field = getFormElement(f, 'setup[smtp][from]');
    if (isWhitespace(field.value)) {
        selectField(f, 'setup[smtp][from]');
        alert('Please enter the sender address that will be used for all outgoing notification emails.');
        return false;
    }
    if (!isEmail(field.value)) {
        selectField(f, 'setup[smtp][from]');
        alert('Please enter a valid email address for the sender address.');
        return false;
    }
    field = getFormElement(f, 'setup[smtp][host]');
    if (isWhitespace(field.value)) {
        selectField(f, 'setup[smtp][host]');
        alert('Please enter the SMTP server hostname.');
        return false;
    }
    field = getFormElement(f, 'setup[smtp][port]');
    if ((isWhitespace(field.value)) || (!isNumberOnly(field.value))) {
        selectField(f, 'setup[smtp][port]');
        alert('Please enter the SMTP server port number.');
        return false;
    }
    var field1 = getFormElement(f, 'setup[smtp][auth]', 0);
    var field2 = getFormElement(f, 'setup[smtp][auth]', 1);
    if ((!field1.checked) && (!field2.checked)) {
        alert('Please indicate whether the SMTP server requires authentication or not.');
        return false;
    }
    if (field1.checked) {
      field = getFormElement(f, 'setup[smtp][username]');
      if (isWhitespace(field.value)) {
          selectField(f, 'setup[smtp][username]');
          alert('Please enter the SMTP server username.');
          return false;
      }
      field = getFormElement(f, 'setup[smtp][password]');
      if (isWhitespace(field.value)) {
          selectField(f, 'setup[smtp][password]');
          alert('Please enter the SMTP server password.');
          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;">An Error Was Found</span></td>
        </tr>
        <tr>
          <td colspan="2" class="default">
            <br />
            <b>Details: {$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>Thank You, Eventum is now properly setup and ready to be used. Open the following URL to login on it for the first time:</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 />
            Email Address: admin@example.com (literally)<br />
            Password: admin<br />
            <br />
            <b>NOTE: For security reasons it is highly recommended that the default password be changed as soon as possible.
            <br /><br />
            <hr size="1" noshade color="#000000">
            Remember to protect your 'setup' directory (like changing its permissions) to prevent anyone else
            from changing your existing Eventum configuration.<br /><br />
            In order to check if your permissions are setup correctly visit the <a class="link" href="check_permissions.php">Check Permissions</a> page.
            {if not $is_imap_enabled}
            <br /><br />
            <hr size="1" noshade color="#000000">
            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.
            {/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>Eventum Installation</h1>
            <hr size="1" noshade color="#000000">
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>Server Hostname: *</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');">SSL Server</a></b></span>
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>Eventum Relative URL: *</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>MySQL Server Hostname: *</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>MySQL Database: *</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>MySQL Table Prefix:</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');">Drop Tables If They Already Exist</a></b>
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>MySQL Username: *</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>Note:</b> This user requires permission to create and drop tables in the specified database.<br />This value is used only for these installation procedures, and is not saved if you provide a separate user below.)</i></span>
          </td>
        </tr>
        <tr>
          <td width="180" class="default" align="right">
            <b>MySQL Password:</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();">Use a Separate MySQL User for Normal Eventum Use</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>Enter the details below:</b>
                            </td>
                          </tr>
                          <tr>
                            <td class="default" align="right">
                              <nobr>&nbsp;<b>Username: *</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>Password:</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');">Create User and Permissions</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>SMTP Configuration</b></h2>
            <hr size="1" noshade color="#000000">
          </td>
        </tr>
        <tr>
          <td colspan="2" class="small_default" align="center">
            <b>Note:</b> The SMTP (outgoing mail) configuration is needed to make sure emails are properly sent when creating new users/projects.
            &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>(must be a valid email address)</i></span>
          </td>
        </tr>
        <tr>
          <td width="100" class="default" align="right">
            <b>Hostname: *</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>Port: *</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>Requires Authentication?&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);">Yes</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);">No</a>
          </td>
        </tr>
        <tr>
          <td width="100" class="default" align="right">
            <b>Username:&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>Password:&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="Start Installation &gt;&gt;" tabindex="{$tabindex}">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" class="default">
      <b>* Required Fields</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"}