Index: branches/LCSv2/controllers/default.py.bak
===================================================================
--- branches/LCSv2/controllers/default.py.bak	(revision 622)
+++ branches/LCSv2/controllers/default.py.bak	(revision 626)
@@ -3,8 +3,14 @@
 hwys = ['','1','5', '22', '55', '57', '73', '74', '91', '133', '142', '241', '261', '405', '605']
 hwyDirections = ['','NB', 'SB', 'NB/SB','EB','WB','EB/WB']
+# Names to appeaer in the username dropdown box
+users = []
 # Show the login page
 def index():
-    form = FORM(LABEL('Username:',_for='username', _class="label username-label"),
-                INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(),
+    userfile = open('student_names.txt','r')
+    users = [line.strip() for line in userfile.readlines()]
+    users.insert(0,'')
+    form = FORM(LABEL('User:',_for='username', _class="label username-label"),
+                #INPUT(_name='username', _size='15', _style="font-size: 18px;"), BR(),
+                SELECT(users,_name='username',requires=IS_LENGTH(minsize=1,error_message='Must select a user from the list.')),BR(),
                 INPUT(_type='submit',_value="Log in", _class=" btn btn-primary", _style="margin-top: 3%;"))
     if form.process().accepted:
@@ -92,5 +98,5 @@
     count = len(hwy)
     # Show the results in table format.  Get the radio call number from supervisor name lookup
-    header = THEAD(TR(TH(''), TH('DTM',BR(),'Area'), TH('Closure ID/',BR(),'Log No.'),TH('Route & Dir/',BR(),'Type of Closure'),TH('Start Date/',BR(),'End Date/',BR(),'Est. Delay'),TH('Facility'),TH('Limits'),TH('Work'), TH('TMP:',BR(),'Cozeep/',BR(),'Detour'),TH('Requestor/',BR(),'Radio Call No.')))
+    header = THEAD(TR(TH(''), TH('DTM',BR(),'Area'), TH('Closure ID/',BR(),'Log No.'),TH('Route & Dir/',BR(),'Type of Closure'),TH('Start Date/',BR(),'End Date/',BR(),'Est. Delay'),TH('Facility/Lanes'),TH('Limits'),TH('Work'), TH('TMP:',BR(),'Cozeep/',BR(),'Detour'),TH('Requestor/',BR(),'Radio Call No.')))
     multiform = []
     # Iterates over all search results
@@ -103,5 +109,6 @@
                           INPUT(_type='submit',_name='btn2',_value='Show Status Form',_class="submit-button" ),
                           INPUT(_type='hidden',_name='row',_value=row.closureid))),
-                          TD(row.closureid[0]),TD(row.closureid,HR(),row.lognum), TD(row.route,' ',row.direction,HR(),row.closuretype), TD(row.startdate,' ',formatTime(row.starttime),HR(),row.enddate,' ',formatTime(row.endtime),HR(),row.estdelay), TD(row.facility),TD(row.startlocation,HR(),row.endlocation), TD(row.worktype), TD(row.tmpcozeep,BR(),row.tmpdetour), TD(row.supervisor,HR(),db(db.supervisors.name == row.supervisor).select().first().radiocallnum) )) 
+                          TD(row.closureid[0]),TD(row.closureid,HR(),row.lognum), TD(row.route,' ',row.direction,HR(),row.closuretype), TD(row.startdate,' ',formatTime(row.starttime),HR(),row.enddate,' ',formatTime(row.endtime),HR(),row.estdelay), TD(row.facility,HR(),row.closedlanes),
+TD(row.startlocation,HR(),row.endlocation), TD(row.worktype), TD(row.tmpcozeep,BR(),row.tmpdetour), TD(row.supervisor,HR(),db(db.supervisors.name == row.supervisor).select().first().radiocallnum) )) 
 
     session.chosenid = request.vars.row #Pass the hidden field containing the closure ID
@@ -207,7 +214,9 @@
         supervisors.append(row.radiocallnum + ' ' + row.name)
     crew = ['']  # List of names for the dropdown box
+    crewlookup = []
     # Obtain all the crew names from the database
     for row in db().select(db.crew.ALL):
         crew.append(row.radiocallnum + ' ' + row.name)
+        crewlookup.append(row.radiocallnum + ' ' + row.name)
     # Build the list of street locations and a hidden cross street lookup table
     streets = ['']
@@ -248,5 +257,5 @@
                     TD(INPUT(_type='checkbox',_name='cozeep'),'CoZeep MaZeep/CHP',BR(), 
                        INPUT(_type='checkbox', _name='detour'),'Detour Available')),
-                 TR(TD(DIV(LABEL("Lanes closed"),DIV(_id='boxes'),_id='lanechooser',_style='display:none')),
+                 TR(TD(DIV(LABEL("Lanes closed"),DIV(INPUT(_type='checkbox', _name='lanes', _id='lanes', _value=' '), _id='boxes'),_id='lanechooser',_style='display:none')),
                     TD(INPUT(_type='hidden', _name='lanecount', _id='lanecount', _value='4')),
                     TD(),
@@ -256,6 +265,6 @@
             TD(LABEL('Field Rep'))
             ), 
-          TR(TD(SELECT(supervisors,_name='supervisor', requires=IS_LENGTH(minsize=1,error_message='supervisor cannot be empty'))),
-             TD(SELECT(crew,_name='fieldrep')),
+          TR(TD(SELECT(supervisors,_name='supervisor', _id='supervisorcombo', _onchange='supervisorchanged()', requires=IS_LENGTH(minsize=1,error_message='supervisor cannot be empty'))),
+             TD(SELECT(crew,_name='fieldrep',_id='fieldrep')),
              TD(XML("&nbsp;&nbsp;&nbsp;&nbsp;")),
              TD('Is this an existing incident?',
@@ -272,5 +281,6 @@
                   TR(TD(INPUT(_name='meeting', _size='25')),TD(INPUT(_name='reason',_size='25')),TD(INPUT(_name='remarks',_size='25'))) ), BR(), 
             INPUT(_type='submit',_value='Submit Closure', _class="btn btn-primary btn-default", _style="margin:  2% 45% 2% 40%;"),
-            XML('\n'),SELECT(streetlookup,_name='stlookup', _id='stlookup', _class='hideme')) 
+            XML('\n'),SELECT(streetlookup,_name='stlookup', _id='stlookup', _class='hideme'), 
+SELECT(crewlookup,_name='crewlookup', _id='crewlookup', _class='hideme')) 
 
     if form.process(onvalidation=validate_existing_id).accepted:
@@ -282,7 +292,20 @@
         supervisor_name = form.vars.supervisor[3:]
         fieldrep_name = form.vars.fieldrep[5:]
+        selectedlanes = buildLanesClosedString(form.vars.lanes,form.vars.lanecount)
         # Insert the record into the database
-        newrec = db.closures.insert(closureid=newID, lognum=newLognum, route=form.vars.route, direction=form.vars.direction, facility=form.vars.facility, startcounty=form.vars.startcounty, endcounty=form.vars.endcounty, startlocation=form.vars.startlocation, endlocation=form.vars.endlocation, startdate=form.vars.startdate, enddate=form.vars.enddate, starttime=form.vars.starttime+form.vars.starttimemin, endtime=form.vars.endtime+form.vars.endtimemin, closuretype=form.vars.closuretype, worktype=form.vars.worktype, estdelay=form.vars.estdelay, tmpcozeep=getCheckbox(form.vars.cozeep), tmpdetour=getCheckbox(form.vars.detour), supervisor=supervisor_name, fieldrep=fieldrep_name, s1097date='', s1098date='', s1022date='' )
-        session.flash = 'New lane closure added: ' + newID + ' ' + newLognum + ', ' + buildLanesClosedString(form.vars.lanes) + ':' + form.vars.lanecount
+        newrec = db.closures.insert(closureid=newID, lognum=newLognum, route=form.vars.route, direction=form.vars.direction, facility=form.vars.facility, startcounty=form.vars.startcounty, endcounty=form.vars.endcounty, startlocation=form.vars.startlocation, endlocation=form.vars.endlocation, startdate=form.vars.startdate, enddate=form.vars.enddate, starttime=form.vars.starttime+form.vars.starttimemin, endtime=form.vars.endtime+form.vars.endtimemin, closuretype=form.vars.closuretype, closedlanes=selectedlanes, worktype=form.vars.worktype, estdelay=form.vars.estdelay, tmpcozeep=getCheckbox(form.vars.cozeep), tmpdetour=getCheckbox(form.vars.detour), supervisor=supervisor_name, fieldrep=fieldrep_name, s1097date='', s1098date='', s1022date='' )
+        session.flash = 'New lane closure added: ' + newID + ' ' + newLognum + ': ' + selectedlanes
+        redirect(URL('search.html'))
+    return dict(form=form)
+
+# An unlinked page to allow admin to reset the database to simulation start state
+def resetdb():
+    form = FORM("Press this button to reset the closure database to its original state at the start of a simulation.",BR(),
+                "Warning: this will delete all the current closures.",BR(),
+                INPUT(_value="Reset Database", _type='submit', _class="btn btn-primary btn-default"))
+    if form.process().accepted:
+        db(db.closures.id > 0).delete()   # remove all current records
+        with open('db_closures_start.csv', 'rb') as dumpfile:
+            db.closures.import_from_csv_file(dumpfile)  # import from starting state
         redirect(URL('search.html'))
     return dict(form=form)
@@ -296,6 +319,7 @@
 # Calculate the closure id to assign to the new closure
 def calcNextClosureID(routeNum):
-    # Retrieve any existing closures on this route
-    item = db(db.closures.closureid.startswith('T'+routeNum)).select().last() # Might need to sort these
+    # Retrieve the last existing closure on this route
+    #item = db(db.closures.closureid.startswith('T'+routeNum)).select().last() # defective
+    item = db(db.closures.route == routeNum).select().last() 
     if (item != None):
         currID = item.closureid
@@ -328,9 +352,10 @@
 # E.g.  #1 #3 of 4
 # Note: ckBoxGroup parameter contains only checked items
-def buildLanesClosedString(ckBoxGroup):
-    result = ">"
+def buildLanesClosedString(ckBoxGroup,lanecount):
+    result = ""
     if ckBoxGroup is not None:
         # Append each checked value to a string
         for item in ckBoxGroup:
-            result = result + item + " "
+            result = result + "#"+item + " "
+        result = result + "of " + lanecount
     return result
