<html><head><title>tHc private server booking overview</title>
    <link rel="stylesheet" href="overview.css">
    <script type="text/javascript" src="domLib.js"></script>
     <script type="text/javascript" src="domTT.js"></script>
    <script type="text/javascript" src="domTT_drag.js"></script>
</head>

<body>

<div id="entete"></div>
<div id="menu">
<div class="element_menu">
  <ul>
    <li><a href="http://www.thcteam.org">Accueil</a></li>

    <li><a href="http://forum.thcteam.org">Forum</a></li>
    <li><a href="http://wiki.thcteam.org">Wiki</a></li>
    <li><a href="http://www.thcteam.org/map.php">Download maps</a></li>
    <li><a href="http://thcteam.org/reservation/overview.py">Réservations</a></li>
  </ul>
</div>
</div>

<div id="liens">
  <ul>

   <li><a href="login.py">Login</a></li>
   <li><a href="form.py">Form</a></li>
   <li><a href="overview.py">Overview</a></li>
  </ul>
</div>

<%
import cgi, os, MySQLdb
from datetime import datetime, timedelta
import reservation
from reservation import ReservationHolder, Reservation, SERVERS #, Authenticator
from reservation_session import getSession
from reservation_rcon import getCvar


session = getSession(req)
user = session.getUser()

year = form.getfirst('year')
month = form.getfirst('month')
server = form.getfirst('server')

if year and month:
    year = MySQLdb.escape_string(year)
    month = MySQLdb.escape_string(month)
    year = int(year)
    month = int(month)

else:
    now = datetime.now()
    year = now.year
    month = now.month

if server:
    server = server = MySQLdb.escape_string(server)
if server not in SERVERS:
    server = 'A'

#Ecriture de la liste des serveurs
servers = []
for i in SERVERS:
    if i == server:
        servers.append("""<option selected value="%s">%s</option>"""%(i, i))
    else:
        servers.append("""<option value="%s">%s</option>"""%(i, i))
servers.sort()
servers = "\n".join(servers)

def showBookedMonths(minDate, server):
    rh=ReservationHolder()
    ress = rh.searchReservation({'from':minDate, 'server':server}, sort='startdate')
    rh.close()
    ress = map(lambda x:x.startdate.strftime("%Y-%m"),ress)
    chaine = ""
    dates = []
    for date in ress:
        (an, mois) = date.split('-')
        chaine = "<a href='overview.py?server="+server+"&year="+an+"&month="+mois+"'>"+date+"</a>"
        if chaine not in dates:
            dates.append(chaine)
    
    return dates
#
%>
<table id="login"><tr><td align="right">
<%
if user:
%>
<%=user.username%> <a href="logout.py">Logout</a>

<%
else:
%>
<a href="login.py?returnURL=overview.py">Login</a>

<%
#
%>
</td></tr></table>
<div id="overview">
    <form action="" method="GET">
        <table><tr><td>
            <fieldset title="Display">
                Server to display:
             <select name="server">
                 <%= servers %>
             </select><br />
             Month to display:
             <input type="text" name="year" size="4" value="<%=year%>"/>-<input type="text" name="month" size="2" value="<%=month%>"/><br />
             <input type="submit" value="Display"/>
             </fieldset>
             </td>
             <td>
             Months containing reservations:<br/><%= ', '.join(showBookedMonths(datetime.now(), server)) %>
        </td>
        </tr></table>
    </form>

<%
if user and user.isAdmin():
    currentPwd=getCvar("g_password",SERVERS[server][0])
    #
%>
<p>Mot de passe actuel: <%=currentPwd%></p>

<%

if month == 1:
   pmonth = 12
   pyear = year - 1
   nmonth = 2
   nyear = year
elif month == 12:
   pmonth = 11
   pyear = year
   nmonth = 1
   nyear = year + 1
else:
  pmonth = month - 1
  pyear = year
  nmonth = month + 1
  nyear = year 
#end
%>

<a href="overview.py?server=<%=server%>&year=<%=pyear%>&month=<%=pmonth%>">&lt;&lt;Previous month</a>&nbsp;&nbsp;&nbsp;<a href="overview.py?server=<%=server%>&year=<%=nyear%>&month=<%=nmonth%>">Next month&gt;&gt;</a>

<%
#from reservation import ReservationHolder, Reservation, Authenticator #W:Ms au debut, e les utilise pr afficher les mois reserves

rh = ReservationHolder()

fromdate = datetime(year, month, 1)
eyear = year
emonth = month+1
if month == 12:
    eyear = year + 1
    emonth = 1
todate = datetime(eyear, emonth, 1)
ress = rh.getReservationFromTo(fromdate, todate)
dd = {}
for res in ress:
    if res.server != server:
        continue
    try:
        sd = res.startdate.strftime("%d/%m/%Y")
    except:
        raise "%s"%res.__dict__
    if sd in dd.keys():
        dd[sd].append(res)
    else:
        dd[sd] = [res]
   

from copy import copy
day = copy(fromdate)
d = timedelta(1)
%>
<%
while day < todate:
    #start of block
%>
<%
    sds = day.strftime("%d/%m/%Y")
%>
<table>

    <!-- Schedule Header: hours -->   
	
    <tr style="height: 20px;">
        <td width="120px">
            <strong><%=day.strftime("%a %d/%m/%Y") %></strong>
        </td>
        <td>
            <div style="height: 12px; position: relative;">

                <!-- Render each even hour ( 8, 10, 12, 14 oclock... ) -->
                 <div id="barDivH_65_Thu 01/11/2007_00" class="calHour" style="left: 0px">00</div>

                 <div id="barDivH_65_Thu 01/11/2007_02" class="calHour" style="left: 60px">02</div>

                 <div id="barDivH_65_Thu 01/11/2007_04" class="calHour" style="left: 120px">04</div>
            
                <div id="barDivH_65_Thu 01/11/2007_06" class="calHour" style="left: 180px">06</div>
            
                <div id="barDivH_65_Thu 01/11/2007_08" class="calHour" style="left: 240px">08</div>
            
                <div id="barDivH_65_Thu 01/11/2007_10" class="calHour" style="left: 300px">10</div>
            
                <div id="barDivH_65_Thu 01/11/2007_12" class="calHour" style="left: 360px">12</div>
            
                <div id="barDivH_65_Thu 01/11/2007_14" class="calHour" style="left: 420px">14</div>
            
                <div id="barDivH_65_Thu 01/11/2007_16" class="calHour" style="left: 480px">16</div>
            
                <div id="barDivH_65_Thu 01/11/2007_18" class="calHour" style="left: 540px">18</div>
            
                <div id="barDivH_65_Thu 01/11/2007_20" class="calHour" style="left: 600px">20</div>
            
                <div id="barDivH_65_Thu 01/11/2007_22" class="calHour" style="left: 660px">22</div>
            
                <div id="barDivH_65_Thu 01/11/2007_24" class="calHour" style="left: 720px">24</div>
            
            
<%
    l = dd.get(sds,[])
    for res in l:
        #start of block
        stpx = (60*res.startdate.hour + res.startdate.minute)/2
        dur = res.enddate - res.startdate
        dpx = dur.seconds / 120 #/60/2 
%>
              <a href="edit.py?resId=<%=res.resID%>">  <div id="<%="%s - %s - %s - %s"%(res.startdate, res.enddate, res.login, res.comment) %>" class="barUnaval" style="cursor: pointer; width: <%=dpx%>px; left: <%=stpx%>;" onmouseover="domTT_activate(this, event, 'content', '<%="%s - %s<br>Booked by: %s<br>For: %s"%(res.startdate, res.enddate, res.login, res.comment) %>', 'delay', 100, 'maxWidth', 320, 'styleClass', 'tip' );"></div> </a>

<%
    #end of block
%>
            </div>

        </td>
    </tr>



</table>

<%
    day = day + d
%>

<%
#end of block
%>





<% rh.close()%>
</div>

<div id="pied">
   <p>Copyleft "tHcteam" 2007, aucun droits réservés. Thx to Whinze from wwF for the design</p>

<!-- phpmyvisites -->
<a href="http://www.phpmyvisites.net/" title="phpMyVisites | Open source web analytics" onclick="window.open(this.href);return(false);"><script type="text/j$
<!--
var a_vars = Array();
var pagename='';

var phpmyvisitesSite = 1;
var phpmyvisitesURL = "http://www.thcteam.org/phpmv2/phpmyvisites.php";
//-->
</script>

<script language="javascript" src="Site%20officiel%20des%20tHc_fichiers/phpmyvisites.js" type="text/javascript"></script>

<object><noscript><p>phpMyVisites | Open source web analytics
<img src="http://www.thcteam.org/phpmv2/phpmyvisites.php" alt="Statistics" style="border:0" />
</p></noscript></object></a>
<!-- /phpmyvisites -->
</div>

</body>
</html>
