// cjh: put this in for 2.0 beta - needs some modifications/updating

########################################################
### Choose from a given list of allowed IMAP Servers ###
########################################################

/* Changes login.php3-login.inc
 * This adds the possibilty to choose a an IMAP server from
 * a given list of allowed servers in a select box.
 * The following variables are added to the config file:
 *  - $default->get_server_list
 *  - $default->server_sort
 *  - $default->default_server	(Array)
 *  - $default->hostname_cmd
 *
 * e.g.
 * $default->get_server_list           = true;
   $default->imap_servers              = array( "Mail1" => \
	"mail1.uibk.ac.at", "Mail2" => "mail2.uibk.ac.at");
   $default->server_sort               = true;
   $default->hostname_cmd              = "/bin/hostname";
 *
 *
 * The following code is added (ca.) at line 50 -
 * replacing the texbox where the user would normally enter the server
*/


<?php

if ($default->user_change_server) {
	/* the user is allowed to choose the server */

echo "<tr>\n";
  echo "   <td align=right>Server</td>\n";
  echo "   <td>\n";

	/* use select box to present a list of allowed servers */
   if ( $default->get_server_list ) {
	/* we do use more than one IMP "server" as our user base
         * is "slightly" too big for one server - we do have
         * 20.000 users. But I do want the code and configuration
         * to be identical on all machines. Therefore I added an option
         * that, depending on the hostname of the web server, the
         * according preferred IMAP server can be choosen and will
         * therefore appear at the top of the list.
         * However, I'm not sure if you do need this; I just included
         * it for completeness. However, you'll probably want to remove
         * this part ...
         */
      if ( $default->server_sort ) {
         $this_host = exec("$default->hostname_cmd");
         $default_imap_server = $default->default_server[$this_host];
      }

      echo "   <select name=\"server\">\n";

	/* get the array and produce the select list */
      while (list( $s_name, $s_hostname ) = each( $default->imap_servers
)) {
        $ms_name  = $s_name;
        if ( $default->server_sort ) {
                if ( $s_name == $default_imap_server ) {
                        echo "   <option value=\"$s_hostname\" \
				SELECTED>$ms_name</option>\n";
                } else {
                        echo "   <option \
					value=\"$s_hostname\">$ms_name</option>\n";
                }
        }
      }
      echo "   </select>\n";
      echo "   <input type=\"hidden\" name=\"port\" value=\"143\">\n";
	/* the text box from the old code if no select box should be used */
   } else {
      echo "<input type=\"text\" name=\"server\" \
		value=\"$default->server\">";
      echo "Port <input type=\"text\" size=4 name=\"port\" \
		value=\"$default->port\">\n";
   }
echo "   </td>\n";
echo "</tr>\n";

}


?>
