Hi DanO and all,
Using the code on the permissions.html page, I was able to successfully create a dynamically generated list menu, populated wtih the usernames. I documented the changes I made for my own records, and wanted to share the "how to" with the forum in the hopes it'll help somebody some day. Thanks for pointing me in the right direction.
If you see anything TERRIBLY wrong with the changes I made, please let me know; I've been testing for a couple of days with no ill effects.
Here's what I did:
Find login.html, and make a backup copy before you start playing with the code.
Replace this:
<% $screenTitle = "Login"; %>
With This:
<% $screenTitle = "Login";
$user = $main::User;
$user_db = new DBFile($main::users_db);
$users = $user_db->getRecords( {} );
$calendars = &main::GetAllCalendars();
%>
Next, replace this:
<BODY BGCOLOR="<%=$AdminConfig->get("page-background-color")%>" onLoad="document.forms[0].username.focus()">
<!--#include file="_header.html"-->
With this:
<BODY BGCOLOR="<%=$AdminConfig->get("page-background-color")%>">
<!--#include file="_header.html"-->
<!--#include file="_command_list.html" -->
Replace this:
<FORM ACTION="<%= $CGI_URL %>" METHOD="POST">
<INPUT TYPE="hidden" NAME="fromTemplate" VALUE="<%=$thisTemplate%>">
<INPUT TYPE="hidden" NAME="template" VALUE="select_calendar.html">
<INPUT TYPE="hidden" NAME="command" VALUE="login">
With this (you're just adding a 4th hidden field):
<FORM ACTION="<%= $CGI_URL %>" METHOD="POST">
<INPUT TYPE="hidden" NAME="fromTemplate" VALUE="<%=$thisTemplate%>">
<INPUT TYPE="hidden" NAME="template" VALUE="select_calendar.html">
<INPUT TYPE="hidden" NAME="command" VALUE="login">
<INPUT TYPE="hidden" NAME="username" VALUE="<%= $selected_user %>">
Replace the following table row:
<TR>
<TD ALIGN="right"><B>Username:</B></TD>
<TD><INPUT TYPE="text" NAME="username" SIZE="15" VALUE="<%= $main::in{username} %>"></TD>
</TR>
With this one:
<TR>
<TD ALIGN="right"><b>Username:</b></TD>
<TD><SELECT NAME="username">
<% $ol = new HTML:
ptionList();
foreach (sort {$a->{'username'} cmp $b->{'username'}} @$users) {
$ol->addOption($_->{'username'},$_->{'username'});
$ol->setSelectedValue($selected_user);
} %>
<%= $ol->toString() %>
</SELECT>
</TD>
</TR>
A couple of other considerations:
*****************
You may want to change some of the files to reflect username instead of name. For example, one of the accounts has a username of "American Cancer Society" and a name of "Susan Jones" (because Susan is their representative who will enter events into the calendar.) Susan goes to calendar admin, selects "American Cancer Society" from the list menu and enters her password to log in. The screens that follow will all contain messages like "Susan Jones successfully logged in". If you want the screen to say "American Cancer Society" successfully logged in, you will need to edit those files accordingly. (In this case, I may not change this, since if Susan Jones is no longer the agent for that account, we are more likely to be notified if the new agent, John Smith, has to look at a window welcoming Susan Jones! ;-)
*******************
The method above will list ALL the usernames, including Administrator, in the list menu. For this incidence of calendarscript, I wanted to include all the names EXCEPT Administrator, but then there was no way for the Administrator to log in.
So...I made the changes listed above and saved the page as both login.html and login2.html, with the first file being the "public" administration page (the one the organizations will see) and the second file being the one the administrator(s) will use.) Then, I opened login.html, the public administration page, and changed it thusly (the change is the "next if" statement):
<TD><SELECT NAME="username">
<% $ol = new HTML:
ptionList();
foreach (sort {$a->{'name'} cmp $b->{'name'}} @$users) {
next if ($_->{'username'} eq "Administrator"); $ol->addOption($_->{'username'},$_->{'name'});
$ol->setSelectedValue($selected_user);
} %>
<%= $ol->toString() %>
</SELECT>
</TD>
After this change, the page the organizations view will not list Administrator as username in the list menu.
But how will the Administrator log in? Locate calendar_admin.pl and save it as calendar_admin2.pl. Open calendar_admin2.pl and change the 4 references to login.html to login2.html, as shown in the code below.
Give the public a link to calendar_admin.pl. Give administrators a link to calendar_admin2.pl
Change this (approximately line 352):
$in{template} | |= "login.html";
$in{template} =~ s|[^\w\d\._]| |g;
$in{command} =~ s|[^\w\d\._]| |g;
to this:
$in{template} | |= "login2.html";
$in{template} =~ s|[^\w\d\._]| |g;
$in{command} =~ s|[^\w\d\._]| |g;
Change this (approximately line 429):
elsif ($in{template} eq "login.html") {
$in{template} = "main.html";
}
if ($force_login) {
$in{template} = "login.html";
undef $Template::Session;
&showScreen();
}
to this:
elsif ($in{template} eq "login2.html") {
$in{template} = "main.html";
}
if ($force_login) {
$in{template} = "login2.html";
undef $Template::Session;
&showScreen();
}
Change this (approximately line 487)
elsif ($in{'command'} eq "logout") {
unless(&handleCustomFunction("before_logout")) {
$Session->ExpireNow();
$Session->cleanupExpiredSessions();
undef $Session;
undef $Template::Session;
$in{template} = "login.html";
$Template::CALENDAR_LINK = $AdminConfig->get("calendar_url")."?calendar=$calendar";
&handleCustomFunction("after_logout");
}
}
To this:
elsif ($in{'command'} eq "logout") {
unless(&handleCustomFunction("before_logout")) {
$Session->ExpireNow();
$Session->cleanupExpiredSessions();
undef $Session;
undef $Template::Session;
$in{template} = "login2.html";
$Template::CALENDAR_LINK = $AdminConfig->get("calendar_url")."?calendar=$calendar";
&handleCustomFunction("after_logout");
}
}
if ($force_login) {
$in{template} = "login2.html";
undef $Template::Session;
&showScreen();
}
------------------
[This message has been edited by SarahM (edited December 08, 2004).]