Index: /trunk/lib/App.inc.php
===================================================================
--- /trunk/lib/App.inc.php	(revision 675)
+++ /trunk/lib/App.inc.php	(revision 676)
@@ -479,5 +479,6 @@
          */
 
-        $safe_http_host = preg_replace('/[^a-z\d.:-]/', '', getenv('HTTP_HOST'));
+        // To get a safe hostname, remove host port and invalid hostname characters.
+        $safe_http_host = preg_replace('/[^a-z\d.:-]/', '', strtok(getenv('HTTP_HOST'), ':'));
         if ('' != $safe_http_host && '' == $this->getParam('site_hostname')) {
             $this->setParam(array('site_hostname' => $safe_http_host));
@@ -487,5 +488,5 @@
         // and is used whenever a URL need be used to the current site.
         // Not available on CLI scripts obviously.
-        if ($safe_http_host && '' == $this->getParam('site_url')) {
+        if ('' != $safe_http_host && '' == $this->getParam('site_url')) {
             $this->setParam(array('site_url' => sprintf('%s://%s', (getenv('HTTPS') ? 'https' : 'http'), $safe_http_host)));
         }
Index: /trunk/services/admins.php
===================================================================
--- /trunk/services/admins.php	(revision 675)
+++ /trunk/services/admins.php	(revision 676)
@@ -79,9 +79,10 @@
 $page = new PageNumbers();
 $page->setPerPage(getFormData('per_page'), 50);
-$page->setPageNumber(getFormData('page_number'));
+$page->setPageNumber(getFormData('page_number', (getFormData('sort') ? 1 : null)));
 
 // Query parameters to retain only locally.
 $locally_carried_queries = array(
     'search_query',
+    'break_list_cache' => $app->validBoomerangURL('accounts'),
 );
 
@@ -129,5 +130,5 @@
 
 case 'insert' :
-    if (getFormdata('cancel', false)) {
+    if (getFormdata('btn_cancel', false)) {
         if ($app->validBoomerangURL('admins')) {
             // Display boomerang page.
@@ -145,5 +146,5 @@
     } else {
         $admin_id = insertRecord(getFormData());
-        if (getFormdata('repeat', false)) {
+        if (getFormdata('btn_repeat', false)) {
             // Display function again.
             $app->dieURL($_SERVER['PHP_SELF'] . '?op=add', $locally_carried_queries);
@@ -158,9 +159,9 @@
 
 case 'update' :
-    if (getFormdata('reset', false)) {
+    if (getFormdata('btn_reset', false)) {
         $app->raiseMsg(_("Saved values have been reloaded."), MSG_NOTICE, __FILE__, __LINE__);
         $app->dieURL($_SERVER['PHP_SELF'] . '?op=edit&admin_id=' . getFormData('admin_id'), $locally_carried_queries);
     }
-    if (getFormdata('cancel', false)) {
+    if (getFormdata('btn_cancel', false)) {
         // Remove lock
         $lock->select($auth->getParam('db_table'), $auth->getParam('db_primary_key'), getFormData('admin_id'));
@@ -181,5 +182,5 @@
     } else {
         updateRecord(getFormData());
-        if (getFormdata('repeat', false)) {
+        if (getFormdata('btn_repeat', false)) {
             // Display edit function with next available ID.
             $qid = $db->query("SELECT " . $auth->getParam('db_primary_key') . " FROM " . $auth->getParam('db_table') . " WHERE " . $auth->getParam('db_primary_key') . " > '" . $db->escapeString(getFormData('admin_id')) . "' ORDER BY " . $auth->getParam('db_primary_key') . " ASC LIMIT 1");
@@ -208,4 +209,6 @@
  *****************************************************************************/
 
+$nav->set('body_id', 'admins');
+
 include 'header.ihtml';
 $app->carryQuery($locally_carried_queries);
@@ -230,11 +233,15 @@
     }
 
-    $fv->numericRange('admin_id', 0, 32767, _("<strong>Admin id</strong> must be a valid number between 0 and 32767."));
+    $fv->numericRange('admin_id', 0, 32767, _("<strong>Admin ID</strong> must be a valid number between 0 and 32767."));
 
     $fv->isEmpty('username', _("<strong>Username</strong> cannot be blank."));
     $fv->stringLength('username', 0, 255, _("<strong>Username</strong> must contain less than 256 characters."));
 
-    $fv->isEmpty('userpass', _("<strong>Passwords</strong> cannot be blank."));
-    $fv->stringLength('userpass', 8, 36, _("<strong>Passwords</strong> must be between 8 and 36 characters long."));
+    if ('insert' == getFormData('op')) {
+        $fv->isEmpty('userpass', _("<strong>Password</strong> cannot be blank."));
+    }
+    if ('update' == getFormData('op') && strlen(getFormData('userpass')) > 0) {
+        $fv->stringLength('userpass', 8, 100, _("<strong>Password</strong> must be between 8 and 100 characters long."));
+    }
 
     $fv->stringLength('first_name', 0, 255, _("<strong>First name</strong> must contain less than 256 characters."));
@@ -266,8 +273,9 @@
         'modified_datetime' => '',
         'new_op' => 'insert',
+        'user_type' => '',
         'submit_buttons' => array(
-            array('name' => 'submit', 'value' => _("Add Administrator"), 'class' => 'small button', 'accesskey' => 's'),
-            array('name' => 'repeat', 'value' => _("Add &amp; repeat"), 'class' => 'small button secondary', 'accesskey' => 'r'),
-            array('name' => 'cancel', 'value' => _("Cancel"), 'class' => 'small button secondary', 'accesskey' => 'c'),
+            array('name' => 'btn_submit', 'value' => _("Add Administrator"), 'accesskey' => 's'),
+            array('name' => 'btn_repeat', 'class' => 'secondary', 'value' => _("Add &amp; repeat"), 'accesskey' => 'r'),
+            array('name' => 'btn_cancel', 'class' => 'secondary', 'value' => _("Cancel"), 'accesskey' => 'c'),
         ),
     );
@@ -298,5 +306,5 @@
     if (!$frm = mysql_fetch_assoc($qid)) {
         $app->logMsg('Could not find record with admin_id: ' . $id, LOG_WARNING, __FILE__, __LINE__);
-        $app->raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
+        $app->raiseMsg(sprintf(_("The requested user %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
         $app->dieBoomerangURL('admins', $locally_carried_queries);
     }
@@ -310,5 +318,5 @@
         'old_username' => $frm['username'],
         'username' => '',
-//         'userpass' => '****************',
+        'userpass' => '',
         'first_name' => '',
         'last_name' => '',
@@ -317,5 +325,5 @@
         'last_login_datetime' => '',
         'last_access_datetime' => '',
-        'last_login_ip' => '0.0.0.0',
+        'last_login_ip' => '',
         'added_by_user_id' => '',
         'modified_by_user_id' => '',
@@ -325,10 +333,10 @@
         'old_username' => $frm['username'],
         'submit_buttons' => array(
-            array('name' => 'submit', 'value' => _("Save changes"), 'class' => 'small button', 'accesskey' => 's'),
-            array('name' => 'repeat', 'value' => _("Save & edit next"), 'class' => 'small button secondary', 'accesskey' => 'e'),
-            array('name' => 'reset', 'value' => _("Reset"), 'class' => 'small button secondary', 'accesskey' => 'r'),
-            array('name' => 'cancel', 'value' => _("Cancel"), 'class' => 'small button secondary', 'accesskey' => 'c'),
+            array('name' => 'btn_submit', 'value' => _("Save changes"), 'accesskey' => 's'),
+            array('name' => 'btn_repeat', 'class' => 'secondary', 'value' => _("Save & edit next"), 'accesskey' => 'e'),
+            array('name' => 'btn_reset', 'class' => 'secondary', 'value' => _("Reset"), 'accesskey' => 'r'),
+            array('name' => 'btn_cancel', 'class' => 'secondary', 'value' => _("Cancel"), 'accesskey' => 'c'),
         ),
-    ), $frm, array('userpass' => 'â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢'));
+    ), $frm);
 
     return $frm;
@@ -360,5 +368,5 @@
     if (! list($name) = mysql_fetch_row($qid)) {
         $app->logMsg('Could not find record with admin_id: ' . $id, LOG_WARNING, __FILE__, __LINE__);
-        $app->raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
+        $app->raiseMsg(sprintf(_("The requested user %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
         $app->dieBoomerangURL('admins', $locally_carried_queries);
     }
@@ -368,5 +376,5 @@
     list($num_admins) = mysql_fetch_row($qid);
     if ($num_admins <= 1) {
-        // There must always be at least one admnistrator!
+        // There must always be at least one administrator!
         $app->raiseMsg(_("You cannot delete the only user in the database. There must be at least one to log in and create other users."), MSG_NOTICE, __FILE__, __LINE__);
     } else if ($auth->get('user_id') == $id) {
@@ -495,4 +503,9 @@
     }
 
+    if (getFormData('filter_user_type', false)) {
+        // Limit by filter.
+        $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . " " . $auth->getParam('db_table') . ".user_type = '" . $db->escapeString(getFormData('filter_user_type')) . "'";
+    }
+
     // Count the total number of records so we can do something about the page numbers.
     $qid = $db->query("
@@ -522,5 +535,5 @@
     ";
 
-    // Use a cash hash to determine if the result-set has changed.
+    // Use a cache hash to determine if the result-set has changed.
     // A unique key for this query, with the total_items in case db records
     // were added since the last cache. This identifies a unique set of
@@ -536,10 +549,10 @@
     // First try to return from the cache.
     if ($cache->exists('list')) {
-        $list = $cache->get('list');
-        return $list;
+        return $cache->get('list');
     }
 
     // The list was not cached, so issue the real query.
     $qid = $db->query($sql);
+    $list = array();
     while ($row = mysql_fetch_assoc($qid)) {
         $list[] = $row;
Index: /trunk/services/templates/admin_form.ihtml
===================================================================
--- /trunk/services/templates/admin_form.ihtml	(revision 675)
+++ /trunk/services/templates/admin_form.ihtml	(revision 676)
@@ -34,5 +34,8 @@
             <div class="medium-5 large-3 columns end">
                 <label for="userpass" class="<?php $fv->err('userpass'); ?>"><?php echo _("Password"); ?></label>
-                <input type="password" class="sc-small" size="50" name="userpass" value="<?php echo oTxt($frm['userpass']); ?>" />
+                <input type="password" class="sc-small" size="50" name="userpass" value="" />
+                <?php if ('add' != getFormData('op') && 'insert' != getFormData('op')) { ?>
+                    <div class="sc-help"><?php echo _("Leave blank unless setting a new password."); ?></div>
+                <?php } ?>
             </div>
         </div>
