def backupWeekOf(type, weekOf):
    startTime = datetime.datetime.combine(weekOf, datetime.time(8, 45))
    endTime = startTime + datetime.timedelta(minutes=db.getResourceDuration(type))

    weekstr = db.getResourceName(type) + " for the week of " + weekOf.strftime("%Y-%m-%d") + "\n\n"

    weekstr += ",M,T,W,Th,F\n"

    for i in range(0, db.getResourceSlotCount(type)):
        weekstr += backupTimeslot(type, weekOf.date(), startTime.time())
        startTime = startTime + datetime.timedelta(minutes=db.getResourceDuration(type) + 5)
        endTime = endTime + datetime.timedelta(minutes=db.getResourceDuration(type) + 5)

    return weekstr
    def index(self, date=None):
        date = normalizeDate(date)

        src = """
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
            <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
            <title>MBS Technology Signout</title>
            <link rel="stylesheet" href="/static/style.css" type="text/css" charset="utf-8" />
        </head>
        <body id="tab%(id)d">
            <div id="header">
                <img src="/static/signout-logo.png" id="logo"/>
                %(tabs)s
            </div>
            <a href="/%(slug)s/signout"><div id="signoutButton">
                <img src="/static/add.png" valign="top"/> Sign out %(slugN)s
            </div></a>
            <div id="schedule">""" % {
            "id": self.type,
            "name": db.getResourceName(self.type),
            "slug": db.getResourceSlug(self.type),
            "slugN": db.getResourceSlugN(self.type),
            "tabs": generateTabs(""),
            "date": date,
        }

        src += "".join(list(generateSchedulePage(date, self.type)))

        src += """
            </div>
        </body>
        </html>"""

        return src
    def choose(self, date=None, teacher=None, other=None, time=None, signout=None, day=None, logout=None):
        date = normalizeDate(date)
        
        if logout is not None:
            authLogout()
            print "logout"
            return """
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <script>window.location='/'</script></html>"""
        
        if (teacher == None) and not authGetLoggedIn():
            print "not logged in, missing data"
            return """
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <script>window.location='/'</script></html>"""
        
        if (teacher != None) and not authLogin(teacher):
            return """
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            Wrong password! Go back and try again...</html>"""
        
        if not authGetLoggedIn():
            print "still not logged in"
            return """
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <script>window.location='/'</script></html>"""
        
        teacher = authGetID()
        
        if signout is not None:
            db.setEntry(day,time,self.type,db.getTeacherId(teacher),signout)
            return """
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <script>window.location='?'</script></html>"""
        
        src = """
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
            <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
            <title>MBS Technology Signout</title>
            <link rel="stylesheet" href="/static/style.css" type="text/css" charset="utf-8" />
            <script src="/static/jquery.min.js"></script>
            <script>
            function signout(name, currentQ, leftQ, date, time)
            {
                var moreStr = "";
                
                if(currentQ != 0)
                    moreStr = "(" + leftQ + " more) ";
                
                res = prompt("You currently have " + currentQ +
                             " %(slugN)s signed out for " + time + " on " + date + ".\\n\\n" +
                             "You can sign out up to " + (currentQ + leftQ) + " %(slugN)s " + moreStr + "in that slot:\\n", currentQ);
                
                if(res == null)
                    return;
                
                if(isNaN(res))
                {
                    alert("'" + res + "' is not a number between 0 and (currentQ + leftQ). Please try again.");
                    signout(name, currentQ, leftQ, date, time);
                    return;
                }
                
                if(res > (currentQ + leftQ))
                {
                    alert("You requested " + (res - currentQ) + " additional %(slugN)s. However, there are only " + leftQ + " available. Please try again.");
                    signout(name, currentQ, leftQ, date, time);
                    return;
                }
                
                window.location = "?signout=" + res + ";day=" + date + ";time=" + time;
            }
            </script>
        </head>
        <body id="tab%(id)d">
            <div id="header">
                <img src="/static/signout-logo.png" id="logo"/>
                %(tabs)s
            </div>
            <div id="headerButton">
                <small><small><b>Signing out %(slugN)s as <i>%(name)s</i></b></small></small>
                <div id="headerButtonSub">
                    The number of remaining seats in each time slot is indicated below. Click on a time slot to change the number of seats <em>you</em> need. When you are done, click the button below to continue.
                    Each slot has <b>%(q)d</b> %(slugN)s available unless otherwise noted.
                </div>
            </div>
            <a href="?logout=1"><div id="signoutButton">
                <img src="/static/play.png" valign="top"/> Done
            </div></a>
            <div id="schedule">""" % {
                "id": self.type,
                "name": db.getResourceName(self.type),
                "slug": db.getResourceSlug(self.type),
                "slugN": db.getResourceSlugN(self.type),
                "q": db.getResourceQuantity(self.type),
                "tabs": generateTabs("/signout/choose"),
                "name": teacher }

        src += "".join(list(generateSignoutSchedulePage(date,self.type)))

        src += """
            </div>
        </body>
        </html>"""
        
        return src
    def index(self, date=None):
        date = normalizeDate(date)
        
        src = """
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
            <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
            <title>MBS Technology Signout</title>
            <link rel="stylesheet" href="/static/style.css" type="text/css" charset="utf-8" />
            <style type="text/css">
            #header
            {
                border-bottom: 1px solid #666;
            }

            #logo
            {
                padding: 20px 15px 20px 15px;
            }
            
            #signinForm
            {
                text-align: left;
            }
            
            td
            {
                border: 0px;
            }
            </style>
            <script src="/static/jquery.min.js"></script>
            <script src="/static/jquery.md5.js"></script>
            <script>
            function checkSubmit()
            {
                var signout = $("#signoutButton");
                var teacher = $("#teacher")[0].value;

                for (var i = 0, l = $("#teacher")[0].length; i < l; ++i)
                {
                    if ((o = $("#teacher")[0].options[i]).selected)
                        teacher = o.text;
                }

                if(teacher != "")
                    document.signinForm.submit();
                else
                    alert("Please specify who you are...");
            }
            </script>
        </head>
        <body>
            <div id="header">
                <img src="/static/signout-logo.png" id="logo"/>
            </div>
            <form id="signinForm" name="signinForm" action="choose" method="post">
                <div class="headerButtonSmall" style="text-align: left;">
                    <div style="font-size: 1.5em; text-align: center;">
                        Signing out %(slugN)s
                    </div>
                    <br/>
                    <table border="0px" cellpadding="6px" width="100%%">
                    <tr>
                        <td style="text-align: right;" width="45%%"><b>Select your name:</b></td>
                        <td width="55%%">%(teachers)s</td>
                    </tr>
                    </table>
                </div>
            </form>
            <a href="javascript:checkSubmit()"><div id="signoutButton">
                <img src="/static/play.png" valign="top"/> Continue to time slot selection
            </div></a>
        </body>
        </html>
            """ % {
                "id": self.type,
                "name": db.getResourceName(self.type),
                "slug": db.getResourceSlug(self.type),
                "slugN": db.getResourceSlugN(self.type),
                "q": db.getResourceQuantity(self.type),
                "teachers": "".join(list(generateTeachersDropdown())) }
        return src