Our users would like to be able to switch back and forth between calendars from the main calendar view (default.html template) rather than having to go to Admin then Change Calendars then View Calendar. What would be great would be a selectbox (drop down box) in the main calendar view that would list all of the calendars available to a particular user and would send them to that calendar on selection. Thanks for any ideas - Keith
code:<!-- ADDED for link to each calendar --> <TABLE BORDER="0" CLASS="thinborder" WIDTH="100" BGCOLOR="<%=$COMMAND_BGCOLOR%>"> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { #do whatever you wanted to do with each calendar here. #you can use $calendar->{key}, $calendar->{name}, and $calendar->{description} to access their names, keys, and descriptions. %> <TR><TD BGCOLOR="<%=(($in{'calendar'} eq $cal->{key})?$_COMMAND_OPTION_SELECTED_BGCOLOR:$_COMMAND_OPTION_BGCOLOR)%>"><B><a href="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>" CLASS="commandtext"><%= $cal->{name} %></A></B></TD></TR> <% } %> </TABLE> <BR><!-- END Added -->
<!-- ADDED for link to each calendar --> <TABLE BORDER="0" CLASS="thinborder" WIDTH="100" BGCOLOR="<%=$COMMAND_BGCOLOR%>"> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { #do whatever you wanted to do with each calendar here. #you can use $calendar->{key}, $calendar->{name}, and $calendar->{description} to access their names, keys, and descriptions. %> <TR><TD BGCOLOR="<%=(($in{'calendar'} eq $cal->{key})?$_COMMAND_OPTION_SELECTED_BGCOLOR:$_COMMAND_OPTION_BGCOLOR)%>"><B><a href="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>" CLASS="commandtext"><%= $cal->{name} %></A></B></TD></TR> <% } %> </TABLE> <BR><!-- END Added -->
<% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { #do whatever you wanted to do with each calendar here. #you can use $calendar->{key}, $calendar->{name}, and $calendar->{description} to access their names, keys, and descriptions. %>
<TR><TD BGCOLOR="<%=(($in{'calendar'} eq $cal->{key})?$_COMMAND_OPTION_SELECTED_BGCOLOR:$_COMMAND_OPTION_BGCOLOR)%>"><B><a href="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>" CLASS="commandtext"><%= $cal->{name} %></A></B></TD></TR>
<% } %> </TABLE> <BR><!-- END Added -->
You can modify the code as you see fit to acheive whatever results you like.
Dan O.
------------------
[This message has been edited by DanO (edited August 16, 2002).]
Thanks!
David M.
quote:How do I modify the code so that the link goes to week view?
add "&view=Week" (without the quotes) to the link URL.
Add this at the top of the body:
code:<script language="JavaScript"><!-- //Hide the script from browsers with JS disabled.function openWindow(url, name, width, height) { mywin = window.open(url, name, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0')}// --></script>
<script language="JavaScript"><!-- //Hide the script from browsers with JS disabled.function openWindow(url, name, width, height) { mywin = window.open(url, name, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0')}// --></script>
function openWindow(url, name, width, height) { mywin = window.open(url, name, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0')}// --></script>
Then add this where you want the bar:
code:<!-- ADDED for link to each calendar --> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <form method="POST" style="font-family: Arial; font-size: 8pt" name="calendar_change"> <SELECT NAME="cal_select" size="1" onChange="window.open(this.options[this.selectedIndex].value,'_top')"> <option selected>Choose a Calendar</option> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { %> <option value="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>"</option> <% } %> </select> </form> <BR><!-- END Added -->
<!-- ADDED for link to each calendar --> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <form method="POST" style="font-family: Arial; font-size: 8pt" name="calendar_change"> <SELECT NAME="cal_select" size="1" onChange="window.open(this.options[this.selectedIndex].value,'_top')"> <option selected>Choose a Calendar</option> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { %> <option value="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>"</option> <% } %> </select> </form> <BR><!-- END Added -->
Like I said, didn't test this, so there may be a syntax error or something, but it should give you the idea, anyway.
code:<!-- ADDED for link to each calendar --> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <form method="POST" style="font-family: Arial; font-size: 8pt" name="calendar_change"> <SELECT NAME="cal_select" size="1" onChange="window.open(this.options[this.selectedIndex].value,'_top')"> <option selected>Choose a Calendar</option> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { %> <option value="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>"><%= $cal->{name} %></option> <% } %> </select> </form> <BR><!-- END Added -->
<!-- ADDED for link to each calendar --> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <form method="POST" style="font-family: Arial; font-size: 8pt" name="calendar_change"> <SELECT NAME="cal_select" size="1" onChange="window.open(this.options[this.selectedIndex].value,'_top')"> <option selected>Choose a Calendar</option> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { %> <option value="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>"><%= $cal->{name} %></option> <% } %> </select> </form> <BR><!-- END Added -->
Thanks in advance for any help! Keith
Just after the foreach statement (and corresponding curly brace "{" )add the following line:
next unless ($user->hasPermission($cal->{'key'},"VIEW"));
That should skip calendars the user doesn't have permissions to view.
<% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { next unless ($user->hasPermission($cal->{'key'},"VIEW")); %> <option value="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>"><%= $cal->{name} %></option>
Thanks again for the help and any other insight you can offer - Keith
It looks correct to me. Even if it was incorrect it shouldn't effect the rest of the calendar, just the dropdown menu.
Maybe look at the calendar's source code to see what the resulting HTML code is for the page.
That's funny, I thought I copied that directly from a template? Actually I see now some templates use "User" while others use "user". I don't know what the difference is.
Glad to hear you figured it out.
[This message has been edited by DanO (edited October 21, 2002).]
quote:Actually I see now some templates use "User" while others use "user". I don't know what the difference is.
It appears that $User->hasPermission is used in calendar templates and corresponding scripts where $user->hasPermission is used in administration templates and scripts.
Matt should really standardize that? JMO
[This message has been edited by DanO (edited December 03, 2002).]
That's what the following line is suppose to do, sort the list by calendar name:
<% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars)
If you want to sort it by calendar key replacing the above with the following should do it:
<% foreach $cal ( sort {$a->{key} cmp $b->{key}} @$calendars)
BTW. There is a difference between upper case letters and lower case, lower will display first.