{* Error and confirmation messages *}
{include file="messages.tpl"}

{strip}
{if (isset($error) and $error gt 0) or !empty($sql_error)}
   <div class="error block">
      <h2>{l}Error{/l}</h2>
      <p>{l}An error occured while saving.{/l}</p>
      {if !empty($errorMsg)}
         <p>{$errorMsg|escape}</p>
      {/if}
      {if !empty($sql_error)}
         <p>{l}The database server returned the following message:{/l}</p>
         <p>{$sql_error|escape}</p>
      {/if}
   </div>
{/if}

{if $posted}
   <div class="success block">
      {l}User saved.{/l}
   </div>
{/if}

<div class="block">
   <form method="post" action="">
   <table class="formPage">

   {if isset($action) and ($action eq 'N' or $action eq 'E')}
   <thead>
      <tr>
         <th colspan="2">
            {if $action eq 'N'}
               {l}Create new user{/l}
            {elseif $action eq 'E'}
               {l}Edit user{/l}
            {/if}
         </th>
      </tr>
  </thead>
  {/if}

   <tbody>
      <tr>
         <td class="label required"><label for="LOGIN">{l}Login{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="LOGIN" name="LOGIN" value="{$LOGIN|trim}" maxlength="{$smarty.const.USER_LOGIN_MAX_LENGTH}" class="text" />
            {validate form="conf_users_edit" id="v_LOGIN" message=$smarty.capture.field_char_required}
            {validate form="conf_users_edit" id="v_LOGIN_LENGTH" message=$smarty.capture.invalid_length|replace:'#MIN#':$smarty.const.USER_LOGIN_MIN_LENGTH|replace:'#MAX#':$smarty.const.USER_LOGIN_MAX_LENGTH}
            {validate form="conf_users_edit" id="v_LOGIN_U" message=$smarty.capture.login_not_unique}
         </td>
      </tr>
      <tr>
         <td class="label required"><label for="NAME">{l}Name{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="NAME" name="NAME" value="{$NAME|trim}" maxlength="{$smarty.const.USER_NAME_MAX_LENGTH}" class="text" />
            {validate form="conf_users_edit" id="v_NAME" message=$smarty.capture.field_char_required}
            {validate form="conf_users_edit" id="v_NAME_LENGTH" message=$smarty.capture.invalid_length|replace:'#MIN#':$smarty.const.USER_NAME_MIN_LENGTH|replace:'#MAX#':$smarty.const.USER_NAME_MAX_LENGTH}
         </td>
      </tr>
      <tr>
         <td class="label{if $action eq 'N'} required{/if}"><label for="PASSWORD">{l}Password{/l}:</label></td>
         <td class="smallDesc">
            <input type="password" id="PASSWORD" name="PASSWORD" value="" maxlength="{$smarty.const.USER_PASSWORD_MAX_LENGTH}" class="text" />
            {validate form="conf_users_edit" id="v_PASSWORD" message=$smarty.capture.field_pass_required}
            {validate form="conf_users_edit" id="v_PASSWORD_LENGTH" message=$smarty.capture.invalid_length|replace:'#MIN#':$smarty.const.USER_PASSWORD_MIN_LENGTH|replace:'#MAX#':$smarty.const.USER_PASSWORD_MAX_LENGTH}
         </td>
      </tr>
      <tr>
         <td class="label{if $action eq 'N'} required{/if}"><label for="PASSWORDC">{l}Confirm Password{/l}:</label></td>
         <td class="smallDesc">
            <input type="password" id="PASSWORDC" name="PASSWORDC" value="" maxlength="{$smarty.const.USER_PASSWORD_MAX_LENGTH}" class="text" />
            {validate form="conf_users_edit" id="v_PASSWORDC" message=$smarty.capture.password_not_match}
         </td>
      </tr>
      <tr>
         <td class="label"><label for="LANGUAGE">{l}Preffered Language{/l}:</label></td>
         <td class="smallDesc">
            {html_options options=$languages selected=$LANGUAGE name="LANGUAGE" id="LANGUAGE"}
            {validate form="conf_users_edit" id="v_LANGUAGE" message=$smarty.capture.field_required}
         </td>
      </tr>
      <tr>
         <td class="label required"><label for="EMAIL">{l}Email{/l}:</label></td>
         <td class="smallDesc">
            <input type="text" id="EMAIL" name="EMAIL" value="{$EMAIL|trim}" maxlength="255" class="text" />
            {validate form="conf_users_edit" id="v_EMAIL" message=$smarty.capture.invalid_email}
            {validate form="conf_users_edit" id="v_EMAIL_U" message=$smarty.capture.email_not_unique}
         </td>
      </tr>
   <td class="label required"><label for="cemail">{l}Confirm Email{/l}:</label></td>
<td class="smallDesc">
<input type="checkbox" id="cemail" name="cemail" value="1" {if $cemail}checked="checked"{/if} />
 <p class="msg notice info">{l}Check this to confirm an users email and allow their links to show.{/l}</p>        
</td>


      <!-- user avatar related -->
      <tr>
       <td class="label">{l}Current Photo{/l}:</td>
       <td class="smallDesc" align="left"><img src="{$AUTH_IMG}"></td>
      </tr>
      <!-- end -->
      <tr>
         <td class="label required"><label for="LEVEL">{l}User Type{/l}:</label></td>
         <td class="smallDesc">
            {html_options options=$admin_user selected=$LEVEL name="LEVEL" id="LEVEL"}
         </td>
      </tr>
      <tr>
         <td class="label"><label for="SUBMIT_NOTIF">{l}Link Submit Notification{/l}:</label></td>
         <td class="smallDesc">
            <input type="checkbox" id="SUBMIT_NOTIF" name="SUBMIT_NOTIF" value="1" {if $SUBMIT_NOTIF}checked="checked"{/if}/>
         </td>
      </tr>
      <tr>
         <td class="label"><label for="PAYMENT_NOTIF">{l}Link Payment Notification{/l}:</label></td>
         <td class="smallDesc">
            <input type="checkbox" id="PAYMENT_NOTIF" name="PAYMENT_NOTIF" value="1" {if $PAYMENT_NOTIF}checked="checked"{/if}/>
         </td>
      </tr>
   </tbody>

   <tfoot>
      <tr>
         <td><input type="reset" id="reset-user-submit" name="reset" value="{l}Reset{/l}" alt="{l}Reset form{/l}" title="{l}Reset form{/l}" class="button" /></td>
         <td><input type="submit" id="send-user-submit" name="submit" value="{l}Save{/l}" alt="{l}Save form{/l}" title="{l}Save user{/l}" class="button" /></td>
      </tr>
   </tfoot>
   </table>
   </form>
</div>
{/strip}