
      <table width="100%" bgcolor="{$cell_color}" border="0" cellspacing="0" cellpadding="1" align="center">
        <tr>
          <td>
            <table bgcolor="#FFFFFF" width="100%" cellspacing="1" cellpadding="2" border="0">
              {literal}
              <script language="JavaScript">
              <!--
              function validateForm(f)
              {
                  if (isWhitespace(f.email.value)) {
                      alert('{/literal}{t escape=js}Please enter the email of this user.{/t}{literal}');
                      selectField(f, 'email');
                      return false;
                  }
                  if (!isEmail(f.email.value)) {
                      alert('{/literal}{t escape=js}Please enter a valid email address.{/t}{literal}');
                      selectField(f, 'email');
                      return false;
                  }
                  if (f.cat.value == 'update') {
                      if ((!isWhitespace(f.password.value)) && (f.password.value.length < 6)) {
                          alert('{/literal}{t escape=js}Please enter a password of at least 6 characters.{/t}{literal}');
                          selectField(f, 'password');
                          return false;
                      }
                  } else {
                      if ((isWhitespace(f.password.value)) || (f.password.value.length < 6)) {
                          alert('{/literal}{t escape=js}Please enter a password of at least 6 characters.{/t}{literal}');
                          selectField(f, 'password');
                          return false;
                      }
                  }
                  if (isWhitespace(f.full_name.value)) {
                      alert('{/literal}{t escape=js}Please enter the full name of this user.{/t}{literal}');
                      selectField(f, 'full_name');
                      return false;
                  }
                  var has_project_selected = false;
                  var projects = new Array({/literal}{$project_list|@count}{literal});
                  {/literal}
                  {foreach from=$project_list key=prj_id item=prj_title name=projects}
                  projects[{$smarty.foreach.projects.iteration-1}] = {$prj_id};
                  {/foreach}
                  {literal}
                  for (i = 0; i < projects.length; i++) {
                    if ((getFormElement(getForm('user_form'), 'role[' + projects[i] + ']').selectedIndex > 0) ||
                        (getFormElement(getForm('user_form'), 'role[' + projects[i] + ']').type == 'hidden' &&
                        getFormElement(getForm('user_form'), 'role[' + projects[i] + ']').value != '')) {
                        has_project_selected = true;
                    }
                  }
                  if (!has_project_selected) {
                      alert('{/literal}{t escape=js}Please assign the appropriate projects for this user.{/t}{literal}');
                      selectField(f, 'projects[]');
                      return false;
                  }
                  return true;
              }
              //-->
              </script>
              {/literal}
              <form name="user_form" onSubmit="javascript:return validateForm(this);" method="post" action="{$smarty.server.PHP_SELF}">
              {if $smarty.get.cat == 'edit'}
              <input type="hidden" name="cat" value="update">
              <input type="hidden" name="id" value="{$smarty.get.id}">
              {else}
              <input type="hidden" name="cat" value="new">
              {/if}
              <tr>
                <td colspan="2" class="default">
                  <b>{t}Manage Users{/t}</b>
                </td>
              </tr>
              {if $result != ""}
              <tr>
                <td colspan="2" bgcolor="{$cell_color}" align="center" class="error">
                  {if $smarty.post.cat == "new"}
                    {if $result == -1}
                      {t}An error occurred while trying to add the new user.{/t}
                    {elseif $result == 1}
                      {t}Thank you, the user was added successfully.{/t}
                    {/if}
                  {elseif $smarty.post.cat == "update"}
                    {if $result == -1}
                      {t}An error occurred while trying to update the user information.{/t}
                    {elseif $result == 1}
                      {t}Thank you, the user was updated successfully.{/t}
                    {/if}
                  {/if}
                </td>
              </tr>
              {/if}
              <tr>
                <td width="120" bgcolor="{$cell_color}" class="default_white">
                  <b>{t}Email Address{/t}:</b>
                </td>
                <td bgcolor="{$light_color}">
                  <input type="text" name="email" size="40" class="default" value="{$info.usr_email}">
                  {include file="error_icon.tpl.html" field="email"}
                </td>
              </tr>
              <tr>
                <td width="120" bgcolor="{$cell_color}" class="default_white">
                  <b>{t}Password{/t}:</b>
                </td>
                <td bgcolor="{$light_color}">
                  <input type="password" name="password" size="20" class="default">
                  {if $smarty.get.cat == 'edit'}
                  <span class="default">({t}leave empty to keep the current password{/t})</span>
                  {/if}
                  {include file="error_icon.tpl.html" field="password"}
                </td>
              </tr>
              <tr>
                <td width="120" bgcolor="{$cell_color}" class="default_white">
                  <b>{t}Full Name{/t}:</b>
                </td>
                <td bgcolor="{$light_color}">
                  <input type="text" name="full_name" size="40" class="default" value="{$info.usr_full_name}">
                  {include file="error_icon.tpl.html" field="full_name"}
                </td>
              </tr>
              <tr>
                <td width="120" bgcolor="{$cell_color}" class="default_white">
                  <nobr><b>{t}Assigned Projects and Roles{/t}:</b></nobr>
                </td>
                <td bgcolor="{$light_color}">
                  <table border="0">
                    {foreach from=$project_list key=prj_id item=prj_name}
                    <tr>
                      <td class="default">{$prj_name}:</td>
                      <td>
                        {if $info.roles.$prj_id.pru_role == $roles.customer}
                        <span class="default">{t}Customer{/t}</span>
                        <input type="hidden" name="role[{$prj_id}]" value="{$roles.customer}">
                        {else}
                        <select name="role[{$prj_id}]" class="default"  {if $current_role < $info.roles.$prj_id.pru_role}disabled{/if}>
                        {html_options options=$project_roles[$prj_id] selected=$info.roles.$prj_id.pru_role}
                        </select>
                        {if $current_role < $info.roles.$prj_id.pru_role}<input type="hidden" name="role[{$prj_id}]" value="{$info.roles.$prj_id.pru_role}">{/if}
                        {include file="error_icon.tpl.html" field="role[$prj_id]"}
                        {/if}
                      </td>
                    </tr>
                    {/foreach}
                  </table>
                </td>
              </tr>
              <tr>
                <td colspan="2" bgcolor="{$cell_color}" align="center">
                  {if $smarty.get.cat == 'edit'}
                  <input class="button" type="submit" value="{t}Update User{/t}">
                  {else}
                  <input class="button" type="submit" value="{t}Create User{/t}">
                  {/if}
                  <input class="button" type="reset" value="{t}Reset{/t}">
                </td>
              </tr>
              </form>
              <tr>
                <td colspan="2" class="default">
                  <b>{t}Existing Users{/t}:</b>
                </td>
              </tr>
              <tr>
                <td colspan="2">
                  <script language="JavaScript">
                  <!--
                  var active_users = new Array();
                  {section name="i" loop=$list}
                  {if $list[i].usr_status == 'active'}
                  active_users[{$smarty.section.i.index}] = '{$list[i].usr_email|escape:"html"}';
                  {/if}
                  {/section}
                  var page_url = '{$smarty.server.PHP_SELF}';
                  {literal}
                  function checkDelete(f)
                  {
                      var total_selected = getTotalCheckboxesChecked(f, 'items[]');
                      var total = getTotalCheckboxes(f, 'items[]');
                      if (getSelectedOption(f, 'status') == 'inactive') {
                          if (active_users.length < 2) {
                              alert('{/literal}{t escape=js}You cannot change the status of the only active user left in the system.{/t}{literal}');
                              return false;
                          }
                          if (total == total_selected) {
                              alert('{/literal}{t escape=js}You cannot inactivate all of the users in the system.{/t}{literal}');
                              return false;
                          }
                      }
                      if (!hasOneChecked(f, 'items[]')) {
                          alert('{/literal}{t escape=js}Please select at least one of the users.{/t}{literal}');
                          return false;
                      }
                      if (!confirm('{/literal}{t escape=js}This action will change the status of the selected users.{/t}{literal}')) {
                          return false;
                      } else {
                          return true;
                      }
                  }
                  function showCustomerUsers(f)
                  {
                      var field = getFormElement(f, 'show_customers', 0);
                      if (field.checked) {
                          window.location.href = page_url + "?" + replaceParam(window.location.href, 'show_customers', '1');
                      } else {
                          window.location.href = page_url + "?" + replaceParam(window.location.href, 'show_customers', '0');
                      }
                  }
                  //-->
                  </script>
                  {/literal}
                  <table border="0" width="100%" cellpadding="1" cellspacing="1">
                    <form name="change_status_form" onSubmit="javascript:return checkDelete(this);" method="post" action="{$smarty.server.PHP_SELF}">
                    <input type="hidden" name="cat" value="change_status">
                    <tr>
                      <td bgcolor="{$cell_color}" nowrap><input type="button" value="{t}All{/t} " class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'items[]');"></td>
                      <td bgcolor="{$cell_color}" class="default_white">&nbsp;<b>{t}Full Name{/t}</b></td>
                      <td bgcolor="{$cell_color}" class="default_white">&nbsp;<b>{t}Role{/t}</b></td>
                      <td bgcolor="{$cell_color}" class="default_white">&nbsp;<b>{t}Email Address{/t}</b></td>
                      <td bgcolor="{$cell_color}" class="default_white">&nbsp;<b>{t}Status{/t}</b></td>
                      <td bgcolor="{$cell_color}" class="default_white">&nbsp;<b>{t}Group{/t}</b></td>
                    </tr>
                    {section name="i" loop=$list}
                    {cycle values=$cycle assign="row_color"}
                    <tr>
                      <td width="4" nowrap bgcolor="{$row_color}" align="center">
                        <input type="checkbox" name="items[]" value="{$list[i].usr_id}" {if $smarty.section.i.total == 0}disabled{/if}>
                      </td>
                      <td width="15%" bgcolor="{$row_color}" class="default">
                        &nbsp;<a class="link" href="{$smarty.server.PHP_SELF}?cat=edit&id={$list[i].usr_id}" title="{t}update this entry{/t}">{$list[i].usr_full_name}</a>
                      </td>
                      <td width="15%" bgcolor="{$row_color}" class="default" nowrap>
                        {foreach from=$list[i].roles item=role_data}
                          &nbsp;{$role_data.prj_title}: {$role_data.role}<br />
                        {/foreach}
                      </td>
                      <td width="35%" bgcolor="{$row_color}" class="default">
                        &nbsp;<a href="mailto:{$list[i].usr_email}" class="link" title="{t}send email to{/t} {$list[i].usr_email}">{$list[i].usr_email}</a>
                      </td>
                      <td width="20%" bgcolor="{$row_color}" class="default">
                        &nbsp;{$list[i].usr_status|capitalize}
                      </td>
                      <td width="15%" bgcolor="{$row_color}" class="default">
                        &nbsp;{$list[i].group_name}
                      </td>
                    </tr>
                    {sectionelse}
                    <tr>
                      <td colspan="6" bgcolor="{$light_color}" align="center" class="default">
                        <i>{t}No users could be found.{/t}</i>
                      </td>
                    </tr>
                    {/section}
                    <tr>
                      <td colspan="6" bgcolor="{$cell_color}">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0">
                          <tr>
                            <td>
                              <input type="button" value="{t}All{/t}" class="shortcut" onClick="javascript:toggleSelectAll(this.form, 'items[]');">
                              <input type="submit" value="{t}Update Status{/t} &gt;&gt;" class="button">
                              <select name="status" class="default">
                                <option value="active">{t}Active{/t}</option>
                                <option value="inactive">{t}Inactive{/t}</option>
                              </select>
                            </td>
                            <td align="right" bgcolor="{$cell_color}" class="default_white">
                              <input type="checkbox" id="show_customers" name="show_customers" value="yes" {if $smarty.get.show_customers == 1}checked{/if} onClick="javascript:showCustomerUsers(this.form);">
                              <label for="show_customers">{t}Show Customers{/t}</label>&nbsp;
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                    </form>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>

