예제 #1
0
    def findAllLabs(self, accessLevel="", oper="="):

        db = self.db
        cursor = self.cursor

        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        labs = {}  # labID, labName

        if accessLevel != "":
            cursor.execute(
                "SELECT labID, lab_name FROM LabInfo_tbl l, UserCategories_tbl c WHERE c.categoryID "
                + oper + ` category_Name_ID_Map[accessLevel] ` +
                " AND l.default_access_level=c.categoryID AND l.status='ACTIVE' ORDER BY lab_name"
            )
        else:
            cursor.execute(
                "SELECT labID, lab_name FROM LabInfo_tbl WHERE status='ACTIVE'"
            )

        results = cursor.fetchall()

        for result in results:
            labID = int(result[0])
            labName = result[1]

            labs[labID] = labName

        return labs
예제 #2
0
    def findLabByID(self, labID):

        db = self.db
        cursor = self.cursor

        ucMapper = UserCategoryMapper(db, cursor)
        category_ID_Name_Map = ucMapper.mapCategoryIDToName()

        cursor.execute(
            "SELECT lab_name, description, default_access_level, location, lab_head, labCode FROM LabInfo_tbl WHERE labID="
            + ` labID ` + " AND status='ACTIVE'")
        result = cursor.fetchone()

        if result:
            labName = result[0]
            labDescr = result[1]
            accessLevel = int(result[2])
            address = result[3]
            labHead = result[4]
            labCode = result[5].upper()

            newLab = Laboratory(labID, labName, labDescr,
                                category_ID_Name_Map[accessLevel], address,
                                labHead, labCode)

            return newLab
예제 #3
0
	def setUserPropertyValue(self, uid, propName, propValue):

		db = self.db
		cursor = self.cursor
		
		#print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
		#print					# DITTO
		
		ucMapper = UserCategoryMapper(db, cursor)
		category_Name_ID_Map = ucMapper.mapCategoryNameToID()

		if propName == "password":
			cursor.execute("UPDATE Users_tbl SET " + propName + " = MD5(" + `propValue` + ") WHERE userID=" + `uid`)
			
		elif propName == "username":
			
			# Watch out again for duplicate username entries
			
			if not self.existsUsername(propValue, 'ACTIVE') and not self.existsUsername(propValue, 'DEP'):
				cursor.execute("UPDATE Users_tbl SET " + propName + " = " + `propValue` + " WHERE userID=" + `uid`)

			elif not self.existsUsername(propValue, 'ACTIVE') and self.existsUsername(propValue, 'DEP'):
				raise DeletedUserException("The username provided exists in the system but is inactive")

			else:
				raise DuplicateUsernameException("The username provided already exists in the system")
				
		elif propName == "category":
			cursor.execute("UPDATE Users_tbl SET " + propName + " = " + `category_Name_ID_Map[propValue]` + " WHERE userID=" + `uid`)

		else:
			cursor.execute("UPDATE Users_tbl SET " + propName + " = " + `propValue` + " WHERE userID=" + `uid`)
예제 #4
0
    def addLab(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        lHandler = LabHandler(db, cursor)
        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        # print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        # print					# DITTO
        # print `form`

        # Get form values
        labName = form.getvalue("labName")
        labHeadTitle = form.getvalue("titles")
        labHeadName = form.getvalue("labHead")
        labHead = labHeadTitle + " " + labHeadName
        labCode = form.getvalue("labCode").upper()
        labDescr = form.getvalue("labDescription")
        labAddress = form.getvalue("labAddress")
        labAccess = form.getvalue("system_access_level")
        defaultLabAccessLevel = category_Name_ID_Map[labAccess]  # map to database ID

        try:
            newLabID = lHandler.insertLab(labName, labDescr, labAddress, defaultLabAccessLevel, labHead, labCode)
            # print `newLabID`
            newLab = Laboratory(newLabID, labName, labDescr, labAccess, labAddress, labHead, labCode)
            self.printLabInfo("view", newLab)

        except DuplicateLabCodeException:

            d = DuplicateLabCodeException()
            utils.redirect(
                hostname
                + "User.php?View=3&labName="
                + labName
                + "&title="
                + labHeadTitle
                + "&labHead="
                + labHeadName
                + "&labCode="
                + labCode
                + "&labDescr="
                + labDescr
                + "&locn="
                + labAddress
                + "&access="
                + labAccess
                + "&ErrCode="
                + ` d.err_code() `
            )
예제 #5
0
	def findAllMembersInCategory(self, category, active, oper = '=', labID = 0):
		
		db = self.db
		cursor = self.cursor
		
		#print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
		#print					# DITTO
		
		ucMapper = UserCategoryMapper(db, cursor)		# for category name/id mapping
		category_Name_ID_Map = ucMapper.mapCategoryNameToID()

		members = []	# list of User **objects**
		
		# When we include 'status=ACTIVE' restriction in the query, a DEP owner of an active project is not shown in project view.  However, we should not add DEP members to a project.
		# Therefore, the calling function should specify whether it wants to restrict query by status.
		# If 'active' parameter is True, add 'status=ACTIVE' clause
		# In any case, **remember to fill in 'category' column for DEP users before the launch**
		
		if labID == 0:
			if active:
				cursor.execute("SELECT userID, firstname, lastname, description FROM Users_tbl u, UserCategories_tbl c WHERE c.categoryID " + oper + " " + `category_Name_ID_Map[category]` + " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>'' AND u.status='ACTIVE'")
			else:
				cursor.execute("SELECT userID, firstname, lastname, description FROM Users_tbl u, UserCategories_tbl c WHERE c.categoryID " + oper + " " + `category_Name_ID_Map[category]` + " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>''")
		else:
			if active:
				cursor.execute("SELECT u.userID, u.firstname, u.lastname, u.description, l.lab_name FROM Users_tbl u, UserCategories_tbl c, LabInfo_tbl l WHERE c.categoryID " + oper + " " + `category_Name_ID_Map[category]` + " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.labID=" + `labID` + " AND l.labID=u.labID AND u.status='ACTIVE'")
			else:
				cursor.execute("SELECT u.userID, u.firstname, u.lastname, u.description, l.lab_name FROM Users_tbl u, UserCategories_tbl c, LabInfo_tbl l WHERE c.categoryID " + oper + " " + `category_Name_ID_Map[category]` + " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>'' AND u.labID=" + `labID` + " AND l.labID=u.labID")
			
		results = cursor.fetchall()
		
		for result in results:
		
			userID = int(result[0])
			firstName = result[1]
			lastName = result[2]
			description = result[3]
			
			tmpLab = Laboratory(labID)
			
			if len(result) == 5:
				labName = result[4]
				tmpLab.setName(labName)
				
			# create a User object
			tmpUser = User(userID, "", firstName, lastName, description, tmpLab, category, "", "")
			members.append(tmpUser)
		

		return members
예제 #6
0
    def setUserPropertyValue(self, uid, propName, propValue):

        db = self.db
        cursor = self.cursor

        #print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        #print					# DITTO

        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        if propName == "password":
            cursor.execute("UPDATE Users_tbl SET " + propName + " = MD5(" +
                           ` propValue ` + ") WHERE userID=" + ` uid `)

        elif propName == "username":

            # Watch out again for duplicate username entries

            if not self.existsUsername(propValue,
                                       'ACTIVE') and not self.existsUsername(
                                           propValue, 'DEP'):
                cursor.execute("UPDATE Users_tbl SET " + propName + " = " +
                               ` propValue ` + " WHERE userID=" + ` uid `)

            elif not self.existsUsername(propValue,
                                         'ACTIVE') and self.existsUsername(
                                             propValue, 'DEP'):
                raise DeletedUserException(
                    "The username provided exists in the system but is inactive"
                )

            else:
                raise DuplicateUsernameException(
                    "The username provided already exists in the system")

        elif propName == "category":
            cursor.execute("UPDATE Users_tbl SET " + propName + " = " +
                           ` category_Name_ID_Map[propValue] ` +
                           " WHERE userID=" + ` uid `)

        else:
            cursor.execute("UPDATE Users_tbl SET " + propName + " = " +
                           ` propValue ` + " WHERE userID=" + ` uid `)
예제 #7
0
    def addLab(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        lHandler = LabHandler(db, cursor)
        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        #print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        #print					# DITTO
        #print `form`

        # Get form values
        labName = form.getvalue("labName")
        labHeadTitle = form.getvalue("titles")
        labHeadName = form.getvalue("labHead")
        labHead = labHeadTitle + " " + labHeadName
        labCode = form.getvalue("labCode").upper()
        labDescr = form.getvalue("labDescription")
        labAddress = form.getvalue("labAddress")
        labAccess = form.getvalue("system_access_level")
        defaultLabAccessLevel = category_Name_ID_Map[
            labAccess]  # map to database ID

        try:
            newLabID = lHandler.insertLab(labName, labDescr, labAddress,
                                          defaultLabAccessLevel, labHead,
                                          labCode)
            #print `newLabID`
            newLab = Laboratory(newLabID, labName, labDescr, labAccess,
                                labAddress, labHead, labCode)
            self.printLabInfo('view', newLab)

        except DuplicateLabCodeException:

            d = DuplicateLabCodeException()
            utils.redirect(hostname + "User.php?View=3&labName=" + labName +
                           "&title=" + labHeadTitle + "&labHead=" +
                           labHeadName + "&labCode=" + labCode + "&labDescr=" +
                           labDescr + "&locn=" + labAddress + "&access=" +
                           labAccess + "&ErrCode=" + ` d.err_code() `)
예제 #8
0
    def modifyUser(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        uHandler = UserHandler(db, cursor)
        lHandler = LabHandler(db, cursor)
        pHandler = ProjectDatabaseHandler(db, cursor)

        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        # print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        # print					# DITTO
        # print `form`

        # Get form values
        userID = int(form.getvalue("userID"))
        newUser = uHandler.getUserByID(userID)

        """
		labID = int(form.getvalue("labID"))
		username = form.getvalue("username")
		
		firstName = form.getvalue("firstName")
		lastName = form.getvalue("lastName")
		description = firstName + " " + lastName
		
		email = form.getvalue("email")
		passwd = form.getvalue("password")
		"""

        readProjects = pHandler.findMemberProjects(userID, "Reader")
        newUser.setReadProjects(readProjects)

        writeProjects = pHandler.findMemberProjects(userID, "Writer")
        newUser.setWriteProjects(writeProjects)

        self.printUserInfo("edit", newUser)
예제 #9
0
    def modifyUser(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        uHandler = UserHandler(db, cursor)
        lHandler = LabHandler(db, cursor)
        pHandler = ProjectDatabaseHandler(db, cursor)

        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        #print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        #print					# DITTO
        #print `form`

        # Get form values
        userID = int(form.getvalue("userID"))
        newUser = uHandler.getUserByID(userID)
        '''
		labID = int(form.getvalue("labID"))
		username = form.getvalue("username")
		
		firstName = form.getvalue("firstName")
		lastName = form.getvalue("lastName")
		description = firstName + " " + lastName
		
		email = form.getvalue("email")
		passwd = form.getvalue("password")
		'''

        readProjects = pHandler.findMemberProjects(userID, 'Reader')
        newUser.setReadProjects(readProjects)

        writeProjects = pHandler.findMemberProjects(userID, 'Writer')
        newUser.setWriteProjects(writeProjects)

        self.printUserInfo('edit', newUser)
예제 #10
0
	def findLabByID(self, labID):
		
		db = self.db
		cursor = self.cursor
		
		ucMapper = UserCategoryMapper(db, cursor)
		category_ID_Name_Map = ucMapper.mapCategoryIDToName()
		
		cursor.execute("SELECT lab_name, description, default_access_level, location, lab_head, labCode FROM LabInfo_tbl WHERE labID=" + `labID` + " AND status='ACTIVE'")
		result = cursor.fetchone()

		if result:
			labName = result[0]
			labDescr = result[1]
			accessLevel = int(result[2])
			address = result[3]
			labHead = result[4]
			labCode = result[5].upper()

			newLab = Laboratory(labID, labName, labDescr, category_ID_Name_Map[accessLevel], address, labHead, labCode)

			return newLab
예제 #11
0
	def findAllLabs(self, accessLevel="", oper="="):
		
		db = self.db
		cursor = self.cursor
		
		ucMapper = UserCategoryMapper(db, cursor)
		category_Name_ID_Map = ucMapper.mapCategoryNameToID()
		
		labs = {}	# labID, labName
		
		if accessLevel != "":
			cursor.execute("SELECT labID, lab_name FROM LabInfo_tbl l, UserCategories_tbl c WHERE c.categoryID " + oper + `category_Name_ID_Map[accessLevel]` + " AND l.default_access_level=c.categoryID AND l.status='ACTIVE' ORDER BY lab_name")
		else:
			cursor.execute("SELECT labID, lab_name FROM LabInfo_tbl WHERE status='ACTIVE'")
			
		results = cursor.fetchall()
		
		for result in results:
			labID = int(result[0])
			labName = result[1]
			
			labs[labID] = labName
			
		return labs
예제 #12
0
	def printUserInfo(self, cmd, user, errCode=""):
		
		dbConn = DatabaseConn()
		hostname = dbConn.getHostname()		# to define form action URL
		
		db = dbConn.databaseConnect()
		cursor = db.cursor()
		
		uHandler = UserHandler(db, cursor)
		lHandler = LabHandler(db, cursor)
		pHandler = ProjectDatabaseHandler(db, cursor)
		
		ucMapper = UserCategoryMapper(db, cursor)
		category_ID_Name_Map = ucMapper.mapCategoryIDToName()
		category_Name_ID_Map = ucMapper.mapCategoryNameToID()

		currUser = Session.getUser()
		
		gOut = GeneralOutputClass()
					
		if cmd =='create':
			
			username = user.getUsername()
			firstname = user.getFirstName()
			lastname = user.getLastName()
			email = user.getEmail()
			passwd = user.getPassword()
			
			lab = user.getLab()
			uLabID = lab.getID()
			uLabName = lab.getName()
			
			labs = lHandler.findAllLabs()

			# changed Aug. 18/08 - new format
			#content = gOut.printHeader() + gOut.printMainMenu()
			content = gOut.printHeader()
			
			content += '''
				<FORM NAME="create_user_form" METHOD="POST" ACTION="%s" onSubmit="return verifyAddUser();">

					<!-- pass current user as hidden form field -->
					<INPUT type="hidden" ID="curr_username_hidden" NAME="curr_username"'''
					
			content += "value=\"" + currUser.getFullName() + "\">"
			
			content += '''
					<TABLE width="760px" cellpadding="5" cellspacing="5">

						<TH colspan="4" style="color:#0000FF; border-top:1px groove black; border-bottom: 1px groove black; padding-top: 10px; padding-top:5px;">
							ADD NEW USER
							<P style="color:#FF0000; font-weight:normal; font-size:8pt; margin-top:5px;">Fields in red marked with an asterisk (<span style="font-size:9pt; color:#FF0000;">*</span>) are mandatory</P>
						</TH>

						<TR>
							<TD style="width:150px; vertical-align:top; padding-top:10px; color:#FF0000;">
								Laboratory:&nbsp;<sup style="font-size:10pt; color:#FF0000;">*</sup>
							</TD>

							<TD style="vertical-align:top; padding-top:10px">
								<SELECT id="labList" name="labs">
									<OPTION>Select Lab</OPTION>
								'''
			# sort labs by name
			labSortedDict = {}		# will store (labName, labID) tuples 
			labNames = []			# just hold lab names
			
			for labID in labs.keys():
				labName = labs[labID]
				labNames.append(labName)
				labSortedDict[labName] = labID
				
			labNames.sort()

			#for labID in labs.keys():
			for labName in labNames:
				labID = labSortedDict[labName]
				labName = labs[labID]
				content += "<OPTION ID=\"" + `labID` + "\" NAME=\"lab_optn\" VALUE=\"" + `labID` + "\""
				
				if labID == uLabID:
					content += " SELECTED>" + labName
				else:
					content += ">" + labName
					
				content += "</OPTION>"
					
			content += '''
								</SELECT>
								<BR/>
								<P id="lab_warning" style="color:#FF0000; display:none">Please select a laboratory name from the dropdown list above.</P>
							</TD>
						</TR>

						<TR>
							<TD class="createViewColName" style="color:#FF0000;">
								Username:&nbsp;<sup style="font-size:10pt; color:#FF0000;">*</sup>
							</TD>

							<TD class="createViewColValue">
								<INPUT TYPE="TEXT" SIZE="35px" id="user_name" NAME="username" VALUE="%s"/>
								<BR/>
								<!-- Warning anchor -->
								<a name="w1" style="text-decoration:none; font-weight:normal; font-size:8pt">
								
								<P id="dup_uname_warning" style="color:#FF0000; display:inline">This username already exists.  Please specify a different username.</P>
								</a>
							</TD>

							<TD style="font-size:8pt">
								Alphanumeric string up to 10 characters used to log into the system.
							</TD>
						</TR>

						<TR>
							<TD class="createViewColName" style="color:#FF0000;">
								Password:&nbsp;<sup style="font-size:10pt; color:#FF0000;">*</sup>
							</TD>

							<TD class="createViewColValue">
								<INPUT TYPE="PASSWORD" SIZE="35px" id="passwd" NAME="password" VALUE="%s"/>
							</TD>
						</TR>

						<TR>
							<TD class="createViewColName" style="color:#FF0000;">
								First name:&nbsp;<sup style="font-size:10pt; color:#FF0000;">*</sup>
							</TD>

							<TD class="createViewColValue">
								<INPUT TYPE="TEXT" SIZE="35px" id="first_name" NAME="firstName" VALUE="%s"/>
							</TD>
						</TR>

						<TR>
							<TD class="createViewColName" style="color:#FF0000;">
								Last name:&nbsp;<sup style="font-size:10pt; color:#FF0000;">*</sup>
							</TD>

							<TD class="createViewColName">
								<INPUT TYPE="TEXT" SIZE="35px" id="last_name" NAME="lastName" VALUE="%s"/>
							</TD>
						</TR>

						<TR>
							<TD class="createViewColName">
								Email:
							</TD>

							<TD class="createViewColValue">
								<INPUT TYPE="TEXT" SIZE="35px" id="e_mail" NAME="email" VALUE="%s"/>
							</TD>
						</TR>

						<TR>
							<TD>
								Access Level:
							</TD>

							<TD class="createViewColName"  colspan="3">
								<INPUT TYPE="RADIO" name="system_access_level" value="Reader" style="margin-top:8px; font-size:9pt" checked>Reader<BR/>
								<INPUT TYPE="RADIO" name="system_access_level" value="Writer" style="margin-top:8px; font-size:9pt">Writer<BR/>
								<INPUT TYPE="RADIO" name="system_access_level" value="Creator" style="margin-top:8px; font-size:9pt">Creator<BR/>
								<INPUT TYPE="RADIO" name="system_access_level" value="Admin" style="margin-top:8px; font-size:9pt">Admin<BR/>
							</TD>
						</TR>				

						<TR id="project_access">
							<TD colspan="4">
								<TABLE width="100%%">
									<TR>
										<TD colspan="4" style="border-top:1px groove black; border-bottom:1px groove black; padding-top:8px; font-size:8pt; font-weight:bold">
											Grant project access permissions to this user:
										</TD>
									</TR>

									<TR>
										<TD style="width:210px">
											<SELECT id="packetList" name="packets" multiple size="15">
											'''
			# PRINT PROJECT LIST
			projects = pHandler.findAllProjects()
			
			for project in projects:
				projectNumber = project.getNumber()	
				projectName = project.getName()
				
				tmpProject = `projectNumber` + ": " + projectName
				
				content += "<OPTION value=\"" + `projectNumber` + "\">" + tmpProject + "</OPTION>"
				
			content += '''
											</SELECT>
											<BR/>
											<INPUT TYPE="checkbox" style="margin-top:10px; font-size:8pt;" onClick="selectAll(this.id, 'packetList')" id="add_all_chkbx"> Select All</INPUT>
										</TD>

										<TD style="vertical-align:top" colspan="3">
											<span style="font-size:8pt; font-weight:bold">User's access level to selected projects:<BR/></span>
											<input type="radio" id="access_level_radio_read" name="access_levels" value="read" style="margin-top:8px; font-size:9pt" checked>Read-Only &nbsp;&nbsp;&nbsp;<BR/>
											<input type="radio" id="access_level_radio_write" name="access_levels" value="write" style="margin-top:5px; font-size:9pt">Write &nbsp;&nbsp;&nbsp;<BR/>
											<input style="margin-top:8px" onclick="addProjects('packetList', getSelectedRole('1'))" value="Go" type="button"></INPUT>

											<P style="font-size:8pt; border-top:1px groove black; padding-top:10px; padding-bottom:5px; margin-top:10px">
											Access levels: <BR/>
											<span style="font-size: 8pt; margin-left: 9px; font-weight:bold; ">&#45; Read-Only:</span>  May view reagents in a project but may NOT modify them or add new reagents<BR/>

											<span style="font-size: 8pt; margin-left: 9px; font-weight:bold;">&#45; Write:</span>  May create and modify reagents in a project but may NOT change project details or add/remove members to/from the project<BR/>
											</P>
										</TD>
									</TR>

									<TR>
										<TD colspan="4" style="border-top:1px groove black; border-bottom:1px groove black; font-size:8pt; font-weight:bold">
											User's current project access privileges:
										</TD>
									</TR>

									<TR>
										<TD style="border-right:1px solid black; font-size:8pt">
											<B>Read-Only</B><BR/>
											<SELECT id="user_projects_readonly" name="userProjectsReadonly" style="margin-top:5px" multiple size="12">
											'''
			# August 10/07: Default reader access to all on public projects
			publicProjects = pHandler.findAllProjects('FALSE')

			for proj in publicProjects: 
				pID = proj.getNumber()
				pName = proj.getName();
				
				# concatenate project ID and name in the form '1:parent'
				tmpDescr = `pID` + ": " + pName
				
				content += "<OPTION VALUE=\"" + `pID` + "\">" + tmpDescr + "</OPTION>"

			content += '''
											</SELECT><BR/>
											<INPUT style="margin-top:10px;" TYPE="checkbox" onClick="selectAll(this.id, 'user_projects_readonly')" id="select_all_reader_chkbx"> Select All</INPUT>
										</TD>

										<TD style="text-align:center; width:100px; border-right: 1px solid black; padding-left:20px; padding-right:20px;">
											<input onclick="addProjects('user_projects_readonly', 'write')" value="   Make Writeable >>" type="button"></INPUT><BR/>
											<input style="margin-top:30px;" onclick="addProjects('user_projects_write', 'read')" value="<< Make Read-Only" type="button"></INPUT><BR/>
											<input style="margin-top:30px;" onclick="addProjects('user_projects_write'); addProjects('user_projects_readonly')" value="Remove Selected" type="button"></INPUT>
										</TD>

										<TD style="padding-left:50px; font-size:8pt">
											<B>Write</B><BR/>
											<SELECT id="user_projects_write" name="userProjectsWrite" style="margin-top:5px" multiple size="12"></SELECT><BR/>
											<INPUT style="margin-top:10px;" TYPE="checkbox" onClick="selectAll(this.id, 'user_projects_write')" id="select_all_writer_chkbx"> Select All</INPUT>
										</TD>
									</TR>
								</TABLE>
							</TD>
						</TR>

						<TR>
							<TD colspan="4" style="border-top:1px groove black; border-bottom:1px groove black">
								<INPUT TYPE="SUBMIT" id="addUser" NAME="add_user" VALUE="Add User" onClick="selectAllElements('user_projects_readonly'); selectAllElements('user_projects_write');">
							</TD>
						</TR>
					</TABLE>
				</FORM>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				
				</div>
				'''
				
			content += gOut.printFooter()
			
			page_content = content % (hostname + "cgi/user_request_handler.py", username, passwd, firstname, lastname, email)
			
			print "Content-type:text/html"		# THIS IS PERMANENT; DO NOT REMOVE
			print					# DITTO
			print page_content

		elif cmd == 'view':

			userID = user.getUserID()
			username = user.getUsername()
			firstname = user.getFirstName()
			lastname = user.getLastName()
			email = user.getEmail()
			userCat = user.getCategory()
			lab = user.getLab()
			labID = lab.getID()
			labName = lab.getName()
			
			# Only allow modification by admin
			modify_disabled = True
			
			if (currUser.getCategory() == 'Admin'):
				modify_disabled = False
			
			content = gOut.printHeader()
			#content += gOut.printMainMenu()
			
			content += '''
				<FORM name="user_form" method="POST" action="%s">
							
					<!-- pass current user as hidden form field -->
					<INPUT type="hidden" ID="curr_username_hidden" NAME="curr_username"'''
					
			content += "value=\"" + currUser.getFullName() + "\">"
			
			content += '''
					<TABLE width="767px" style="margin-left:2px" cellpadding="5px" cellspacing="5px" class="detailedView_tbl" border="1" frame="box" rules="none">
						<TR>
							<TD colspan="6" class="detailedView_heading" style="padding-left:265px">
								USER DETAILS PAGE
								'''
			content += "<INPUT TYPE=\"submit\" style=\"margin-left:50px;\" name=\"modify_user\" value=\"Change User Details\""
			
			if modify_disabled:
				content += " disabled>"
			else:
				content += ">"
						
			content += "<INPUT TYPE=\"submit\" style=\"margin-left:2px;\" name=\"delete_user\" value=\"Delete User\" onClick=\"return verifyDeleteUser();\""
			
			if modify_disabled:
				content += " disabled>"
			else:
				content += ">"

				
			content += '''
							</TD>

						</TR>

						<TR>
							<TD class="projectDetailedViewName" width="50px">
								Username:
							</TD>

							<TD class="detailedView_value" colspan="2" style="width:400px">
								%s
								<INPUT TYPE="hidden" name="username" value="%s">

								<!-- user ID a hidden value -->
								<INPUT TYPE="hidden" name="userID" value="%d">
							</TD>
						</TR>

						<TR>
							<TD class="projectDetailedViewName" width="50px">
								First Name:
							</TD>

							<TD class="detailedView_value" colspan="2" style="width:400px">
								%s
								<INPUT TYPE="hidden" name="firstName" value="%s">
							</TD>
						</TR>

						<TR>
							<TD class="projectDetailedViewName" width="50px">
								Last Name:
							</TD>

							<TD class="detailedView_value" colspan="2" style="width:400px">
								%s
								<INPUT TYPE="hidden" name="lastName" value="%s">
							</TD>
						</TR>
						
						<TR>
							<TD class="projectDetailedViewName" width="50px">
								Laboratory:
							</TD>

							<TD class="detailedView_value" colspan="2" style="width:400px">
							'''
			if modify_disabled:
				content += labName
			else:
				content += "<span class=\"linkShow\" onClick=\"redirectToLabView(" + `labID` + ");\">" + labName + "</span>"
			
			content += '''
								<INPUT TYPE="hidden" name="labID" value="%d">
								<INPUT type="hidden" id="view_lab_hidden" name="view_lab">
							</TD>
						</TR>
						
						<TR>
							<TD class="projectDetailedViewName" width="50px">
								Email:
							</TD>

							<TD class="detailedView_value" colspan="2" style="width:400px">
								%s
								<INPUT TYPE="hidden" name="email" value="%s">
							</TD>
						</TR>
						
						<TR>
							<TD class="projectDetailedViewName" width="50px">
								Access Level:
							</TD>

							<TD class="detailedView_value" colspan="2" style="width:400px">
								%s
								<INPUT TYPE="hidden" name="system_access_level" value="%d">
							</TD>
						</TR>
						
						
						<TR>
							<TD class="projectDetailedViewName" width="50px">
								Projects:
							</TD>
							
						</TR>
						
						<TR>
							<TD style="font-weight:bold; font-size:8pt; width:250px" colspan="2">
								Read-Only:
							</TD>
							
							<TD style="font-weight:bold; font-size:8pt">
								Write:
							</TD>
						</TR>

						<TR>
							<TD style="vertical-align:top;" colspan="2">
								<UL>
								'''
			# show projects for the user
			publicProj = pHandler.findAllProjects("FALSE")
			readOnlyProj = pHandler.findMemberProjects(userID, 'Reader')
			readProj = utils.merge(publicProj, readOnlyProj)
			writeProj = pHandler.findMemberProjects(userID, 'Writer')
			
			# sort read projects
			readKeys = []
			readSorted = {}
			
			for r in readProj:
				rProjectID = r.getNumber()
				readKeys.append(rProjectID)
				readSorted[rProjectID] = r
			
			readKeys = utils.unique(readKeys)
			readKeys.sort()
			
			#for r in readProj:
			for rProjectID in readKeys:
				#rProjectID = r.getNumber()
				r = readSorted[rProjectID]
				rProjectName = r.getName()
				rProjectOwner = r.getOwner()

				try:
					rOwnerName = rProjectOwner.getLastName()
				except AttributeError:
					rOwnerName = ""

				#content += "<LI>" + `rProjectID` + ": " + rOwnerName + ": " + rProjectName
				
				content += "<LI>"
				content += "<span class=\"linkShow\" onClick=\"redirectToProjectDetailedView(" + `rProjectID` + ");\">" + `rProjectID` + ": " + rOwnerName + ": " + rProjectName + "</span>"
				content += "</LI>"

					
			content += '''
								</UL>
							</TD>
							
							<TD style="vertical-align:top;">
								<UL>
								'''
			# sort write projects
			writeKeys = []
			writeSorted = {}
			
			for w in writeProj:
				wProjectID = w.getNumber()
				writeKeys.append(wProjectID)
				writeSorted[wProjectID] = w
				
			writeKeys = utils.unique(writeKeys)
			writeKeys.sort()
			
			#for w in writeProj:
			for wProjectID in writeKeys:
				#wProjectID = w.getNumber()
				w = writeSorted[wProjectID]
				wProjectName = w.getName()
				wProjectOwner = w.getOwner()
				wOwnerName = wProjectOwner.getLastName()
										
				#content += "<LI>" + `wProjectID` + ": " + wProjectName
			
				content += "<LI>"
				content += "<span class=\"linkShow\" onClick=\"redirectToProjectDetailedView(" + `wProjectID` + ");\">" + `wProjectID` + ": " + wOwnerName + ": " + wProjectName + "</span>"
				content += "</LI>"

			content += '''
								</UL>
							</TD>
						</TR>
					</TABLE>
				</FORM>
				
				<FORM id="viewProjectForm" method="POST" action="%s">
					<INPUT type="hidden" id="view_packet_hidden" name="view_packet">
					<INPUT type="hidden" ID="curr_userid_hidden" NAME="curr_user_id" value="%d">
				</FORM>
				
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				<blockquote>&nbsp;</blockquote>
				
			</div>
			'''

			content += gOut.printFooter()
		
			page_content = content % (hostname + "cgi/user_request_handler.py", username, username, userID, firstname, firstname, lastname, lastname, labID, email, email, userCat, category_Name_ID_Map[userCat], hostname + "cgi/project_request_handler.py", currUser.getUserID())

			print "Content-type:text/html"		# 
			print					# DITTO
			print page_content

		elif cmd == 'edit':
					
			userID = user.getUserID()
			username = user.getUsername()
			firstname = user.getFirstName()
			lastname = user.getLastName()
			email = user.getEmail()
			passwd = user.getPassword()
			userCat = user.getCategory()
			
			lab = user.getLab()
			uLabID = lab.getID()
			labName = lab.getName()
			
			labs = lHandler.findAllLabs()
		
			if errCode == "Dup_un":
				un_warn_display = "inline"
			else:
				un_warn_display = "none"
			
			
			content = gOut.printHeader()
			#content += gOut.printMainMenu()
			
			content += '''
				<FORM name="user_form" method="POST" action="%s" onSubmit="return verifyWriteProjects();">
					
					<!-- pass current user as hidden form field -->
					<INPUT type="hidden" ID="curr_username_hidden" NAME="curr_username"'''
					
			content += "value=\"" + currUser.getFullName() + "\">"

			content += '''
					<TABLE width="760px" cellpadding="5px" cellspacing="5px" style="border:1px solid black" frame="box" rules="rows">
					<TR>
						<TD colspan="3" style="padding-left:200px; text-align:center">
							<span style="color:#0000FF; font-weight:bold">CHANGE USER INFORMATION</span>
							<INPUT TYPE="submit" style="margin-left:50px;" name="save_user" value="Save" onClick="selectAllElements('user_projects_readonly'); selectAllElements('user_projects_write');">
							<INPUT TYPE="submit" style="margin-left:20px;" name="cancel_user" value="Cancel">
						</TD>
					</TR>
					
					<TR>
						<TD class="projectDetailedViewName">
							Username:
						</TD>

						<TD class="detailedView_value" style="width:400px">
							<INPUT TYPE="text" size="50px" name="username" value="%s">
							<BR/>
							
							<!-- Warning anchor -->
							<a name="w1" style="text-decoration:none; font-weight:normal; font-size:8pt">
							<P id="dup_uname_warning" style="color:#FF0000; display:%s">This username already exists.  Please specify a different username.</P>
							</a>
							
							<!-- user ID hidden value -->
							<INPUT TYPE="hidden" name="userID" value="%d">
						</TD>
					</TR>


					<TR>
						<TD class="projectDetailedViewName">
							Laboratory:
						</TD>

						<TD style="vertical-align:top; padding-top:10px">
							<SELECT id="labList" name="labs">
							'''
			# sort labs by name
			labSortedDict = {}		# will store (labName, labID) tuples 
			labNames = []			# just hold lab names
			
			for labID in labs.keys():
				labName = labs[labID]
				labNames.append(labName)
				labSortedDict[labName] = labID
				
			labNames.sort()
			
			#for labID in labs.keys():
			for labName in labNames:
				labID = labSortedDict[labName]
				labName = labs[labID]
				content += "<OPTION ID=\"" + `labID` + "\" NAME=\"lab_optn\" VALUE=\"" + `labID` + "\""
				
				if labID == uLabID:
					content += " SELECTED>" + labName
				else:
					content += ">" + labName
					
				content += "</OPTION>"
					
			content += '''
							</SELECT>
						</TD>
					</TR>
					
					<TR>
						<TD class="projectDetailedViewName">
							First Name:
						</TD>

						<TD class="detailedView_value" colspan="2">
							<INPUT TYPE="text" size="50px" name="firstName" value="%s">
						</TD>
					</TR>

					<TR>
						<TD class="projectDetailedViewName">
							Last Name:
						</TD>

						<TD class="detailedView_value" colspan="2">
							<INPUT TYPE="text" size="50px" name="lastName" value="%s">
						</TD>
					</TR>
										
					<TR>
						<TD class="projectDetailedViewName">
							Email:
						</TD>

						<TD class="detailedView_value" colspan="2">
							<INPUT TYPE="text" size="50px" name="email" value="%s">
						</TD>
					</TR>
					
					<TR>
						<TD class="projectDetailedViewName">
							Access Level:
						</TD>
						
						<TD class="detailedView_value" colspan="2">
							<SELECT ID="user_category" NAME="system_access_level">
						'''
			ucHandler = UserCategoryHandler(db, cursor)
			categories = ucHandler.findAllCategories()
			
			for cID in categories.keys():
				
				if categories[cID] == userCat:
					content += "<OPTION VALUE=\"" + `cID` + "\" SELECTED>" + categories[cID] + "</OPTION>"
				else:
					content += "<OPTION VALUE=\"" + `cID` + "\">" + categories[cID] + "</OPTION>"

			# Don't allow addition of Writeable projects to Readers thru Modify view
			if userCat == 'Reader':
				write_disabled = True
			else:
				write_disabled = False
				
			content += '''
							</SELECT>
						</TD>
					</TR>
					
					<TR>
						<TD class="detailedView_value" colspan="3">
							Projects user has access to:
						</TD>
					</TR>

					<TR>
						<td colspan="3">
							<table width="700px">
								<tr>
									<TD colspan="2" style="font-size:8pt; vertical-align:top"">
										Read-Only
									</TD>
									
									<TD style="font-size:8pt; vertical-align:top">
									'''
			if not write_disabled:
				content += "Write"
			else:
				content += "&nbsp;"
			
			content += '''
									</TD>
								</TR>
								
								<TR>
									<TD style="">
										<SELECT id="user_projects_readonly" name="userProjectsReadonly" style="margin-top:5px" multiple size="12">
										'''
										
			# show projects for the user
			readProj = pHandler.findMemberProjects(userID, 'Reader')
			writeProj = pHandler.findMemberProjects(userID, 'Writer')
		
			for r in readProj:
				rProjectID = r.getNumber()
				rProjectName = r.getName()
				
				content += "<OPTION name=\"project_read\" value=\"" + `rProjectID` + "\">" + `rProjectID` + ": " + rProjectName + "</OPTION>"
					
			content += '''
										</SELECT>
										<BR/>
										
										<INPUT TYPE="checkbox" style="margin-top:10px;" onClick="selectAll(this.id, 'user_projects_readonly')" id="select_all_reader_chkbx"> Select All</INPUT>
						'''
			if not write_disabled:
				content += '''
									</TD>
			
									<TD style="text-align:center; padding-right:15px;">
			
										<input onclick="addProjects('user_projects_readonly', 'write')" value="   Make Writeable >>" type="button"></INPUT><BR/>
								
										<input style="margin-top:30px;" onclick="addProjects('user_projects_write', 'read')" value="<< Make Read-Only" type="button"></INPUT><BR/>
			
										&nbsp;<input type="button" style="margin-top:30px;" value="Remove" onclick="removeUserProjects();"></INPUT>
									</TD>
									'''
			
			else:
				content += '''
						&nbsp;<input type="button" value="Remove Selected" onclick="removeUserProjects();"></INPUT>
						'''
			if not write_disabled:
				content += '''	
									<TD style="font-size:8pt">
								
										<SELECT id="user_projects_write" name="userProjectsWrite" style="margin-top:5px" multiple size="12">
										'''
				for w in writeProj:
					wProjectID = w.getNumber()
					wProjectName = w.getName()
					
					content += "<OPTION name=\"project_write\" value=\"" + `wProjectID` + "\">" + `wProjectID` + ": " + wProjectName + "</OPTION>"
						
				content += '''
										</SELECT><BR/>
										
										<INPUT style="margin-top:10px;" TYPE="checkbox" onClick="selectAll(this.id, 'user_projects_write')" id="select_all_writer_chkbx"> Select All</INPUT>
									</TD>
									'''
				
			content += '''
								</TR>
							</table>
						</td>
					</tr>
						
					<TR>
						<TD class="detailedView_value" colspan="3">
							Add new projects:
						</TD>
					</TR>
					
					<TR>
						<TD colspan="3">
							<TABLE>
								<TR>
									<TD>
										<SELECT multiple ID="packetList">
							'''
			# Fetch the list of read and write projects for this user and extract their IDs
			readProjID = []	# list of numerical IDs of read projects
			
			for r in readProj:
				rNum = r.getNumber()
				readProjID.append(rNum)
							
			writeProjID = []
			
			for w in writeProjID:
				wNum = w.getNumber()
				writeProjID.append(wNum)
			
			allPackets = pHandler.findAllProjects()
			
			for p in allPackets:
				pID = p.getNumber()
				pName = p.getName()
				pOwner = p.getOwner()
			
				#print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
				#print					# DITTO
				#print `pOwner`

				# update March 11, 2011
				try:
					lastName = pOwner.getLastName()
				except AttributeError:
					lastName = ""

				#pDesc = `pID` + " : " + pOwner + " : " + pName
				pDesc = `pID` + " : " + lastName + " : " + pName
				
				if not pID in readProjID and not pID in writeProjID:
					content += "<OPTION VALUE=\"" + `pID` + "\">" + pDesc

			content += '''
										</SELECT>
										<BR>
										<INPUT TYPE="checkbox" style="margin-top:10px; font-size:8pt;" onClick="selectAll(this.id, 'packetList')" id="add_all_chkbx"> Select All</INPUT>
						'''

			if not write_disabled:
				content += '''	
									</TD>
								
									<TD style="vertical-align:top">
										<span style="font-size:8pt; font-weight:bold">User's access level to selected projects:<BR/></span>
										<input type="radio" id="access_level_radio_read" name="access_levels" value="read" style="margin-top:8px; font-size:9pt" checked>Read-Only &nbsp;&nbsp;&nbsp;<BR/>
										<input type="radio" id="access_level_radio_write" name="access_levels" value="write" style="margin-top:5px; font-size:9pt">Write &nbsp;&nbsp;&nbsp;<BR/>
										<input style="margin-top:8px" onclick="addProjects('packetList', getSelectedRole('1'))" value="Add project" type="button"></INPUT>
									</TD>
								</TABLE>
							</TD>
						</TR>
						'''
			else:
				content += '''
						<input style="margin-left:5px; margin-top:8px" onclick="addProjects('packetList', 'read')" value="Add project" type="button"></INPUT>
						'''

			content += '''
					</TR>
				</TABLE>
			</FORM>
			
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>
			<blockquote>&nbsp;</blockquote>	
			</div>
			'''
				
			content += gOut.printFooter()
		
			page_content = content % (hostname + "cgi/user_request_handler.py", username, un_warn_display, userID, firstname, lastname, email)
		
			print "Content-type:text/html"		# THIS IS PERMANENT; DO NOT REMOVE
			print					# DITTO
			print page_content
예제 #13
0
    def findAllMembersInCategory(self, category, active, oper='=', labID=0):

        db = self.db
        cursor = self.cursor

        #print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        #print					# DITTO

        ucMapper = UserCategoryMapper(db,
                                      cursor)  # for category name/id mapping
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        members = []  # list of User **objects**

        # When we include 'status=ACTIVE' restriction in the query, a DEP owner of an active project is not shown in project view.  However, we should not add DEP members to a project.
        # Therefore, the calling function should specify whether it wants to restrict query by status.
        # If 'active' parameter is True, add 'status=ACTIVE' clause
        # In any case, **remember to fill in 'category' column for DEP users before the launch**

        if labID == 0:
            if active:
                cursor.execute(
                    "SELECT userID, firstname, lastname, description FROM Users_tbl u, UserCategories_tbl c WHERE c.categoryID "
                    + oper + " " + ` category_Name_ID_Map[category] ` +
                    " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>'' AND u.status='ACTIVE'"
                )
            else:
                cursor.execute(
                    "SELECT userID, firstname, lastname, description FROM Users_tbl u, UserCategories_tbl c WHERE c.categoryID "
                    + oper + " " + ` category_Name_ID_Map[category] ` +
                    " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>''"
                )
        else:
            if active:
                cursor.execute(
                    "SELECT u.userID, u.firstname, u.lastname, u.description, l.lab_name FROM Users_tbl u, UserCategories_tbl c, LabInfo_tbl l WHERE c.categoryID "
                    + oper + " " + ` category_Name_ID_Map[category] ` +
                    " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.labID="
                    + ` labID ` + " AND l.labID=u.labID AND u.status='ACTIVE'")
            else:
                cursor.execute(
                    "SELECT u.userID, u.firstname, u.lastname, u.description, l.lab_name FROM Users_tbl u, UserCategories_tbl c, LabInfo_tbl l WHERE c.categoryID "
                    + oper + " " + ` category_Name_ID_Map[category] ` +
                    " AND c.categoryID=u.category AND u.firstname <> '' AND u.lastname <> '' AND u.description <>'' AND u.labID="
                    + ` labID ` + " AND l.labID=u.labID")

        results = cursor.fetchall()

        for result in results:

            userID = int(result[0])
            firstName = result[1]
            lastName = result[2]
            description = result[3]

            tmpLab = Laboratory(labID)

            if len(result) == 5:
                labName = result[4]
                tmpLab.setName(labName)

            # create a User object
            tmpUser = User(userID, "", firstName, lastName, description,
                           tmpLab, category, "", "")
            members.append(tmpUser)

        return members
예제 #14
0
    def saveLab(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        # print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        # print					# DITTO
        # print `form`

        # Handlers and mappers
        lHandler = LabHandler(db, cursor)
        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        # Get form values
        labID = int(form.getvalue("labID"))
        lab = Laboratory(
            labID
        )  # here need to use the default constructor and not findLabByID, because lab is being updated and need a fresh instance and set its attributes to new values

        newName = form.getvalue("labName")
        newLabHead = form.getvalue("labHead")
        newLabCode = form.getvalue("labCode").upper()
        newDescr = form.getvalue("description")
        newAddr = form.getvalue("address")
        newAccess = form.getvalue("system_access_level")
        newAccLev = category_Name_ID_Map[newAccess]

        # change database values
        try:
            lHandler.setLabName(labID, newName)
            lHandler.setLabHead(labID, newLabHead)
            lHandler.setLabCode(labID, newLabCode)
            lHandler.setLabDescription(labID, newDescr)
            lHandler.setLabAccessLevel(labID, newAccLev)
            lHandler.setLocation(labID, newAddr)

            #######################
            # update members!
            #######################

            newMembers = form.getlist("labMembers")
            lHandler.updateLabMembers(labID, newMembers)

            # change object values
            lab.setName(newName)
            lab.setLabHead(newLabHead)
            lab.setLabCode(newLabCode)
            lab.setDescription(newDescr)
            lab.setAddress(newAddr)
            lab.setDefaultAccessLevel(newAccess)

            # return to detailed view
            self.printLabInfo("view", lab)
            # utils.redirect(hostname + "User.php?View=5&Lab=" + `labID` + "&fd=" + filename)

        except DuplicateLabCodeException:

            newLab = Laboratory(labID, newName, newDescr, newAccess, newAddr, newLabHead, newLabCode)

            d = DuplicateLabCodeException()
            self.printLabInfo("edit", newLab, d.err_code())
예제 #15
0
    def saveUser(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        #print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        #print					# DITTO
        #print `form`

        uHandler = UserHandler(db, cursor)
        lHandler = LabHandler(db, cursor)
        pHandler = ProjectDatabaseHandler(db, cursor)

        ucMapper = UserCategoryMapper(db, cursor)
        category_ID_Name_Map = ucMapper.mapCategoryIDToName()

        newProps = {}

        # Get form values
        userID = int(form.getvalue("userID"))
        newUser = uHandler.getUserByID(userID)

        labID = int(form.getvalue("labs"))
        tmpLab = lHandler.findLabByID(labID)

        # rest of user properties
        username = form.getvalue("username")
        firstName = form.getvalue("firstName")
        lastName = form.getvalue("lastName")
        description = firstName + " " + lastName
        email = form.getvalue("email")
        category = category_ID_Name_Map[int(
            form.getvalue("system_access_level"))]

        newProps["labID"] = labID
        newProps["username"] = username
        newProps["firstname"] = firstName
        newProps["lastname"] = lastName
        newProps["description"] = description
        newProps["email"] = email
        newProps["category"] = category

        try:
            # Now do an update on database level AND on class level:
            uHandler.updateUserProperties(userID, newProps)  # database update

            # Interface level
            newUser.setUsername(username)
            newUser.setFirstName(firstName)
            newUser.setLastName(lastName)
            newUser.setDescription(description)
            newUser.setEmail(email)
            newUser.setLab(tmpLab)
            newUser.setCategory(category)

            # update list of user's projects
            if form.has_key("userProjectsReadonly"):
                # list of IDs
                readonlyProjects = utils.unique(
                    form.getlist("userProjectsReadonly"))
                pHandler.updateUserProjects(userID, readonlyProjects, 'Reader')
            else:
                # safe to assume should delete projects?
                pHandler.deleteMemberProjects(userID, 'Reader')

            if form.has_key("userProjectsWrite"):
                writeProjects = utils.unique(form.getlist("userProjectsWrite"))
                pHandler.updateUserProjects(userID, writeProjects, 'Writer')
            else:
                # safe to assume should delete projects?
                pHandler.deleteMemberProjects(userID, 'Writer')

            # think about this
            #newUser.setReadProjects(readProjects)
            #newUser.setWriteProjects(writeProjects)

            # return to detailed view
            self.printUserInfo('view', newUser)
            #utils.redirect(hostname + "User.php?View=3&fd=" + filename)

        except DuplicateUsernameException:

            # return to the view with input values and error message
            # Need to construct a dummy User instance to save form values for error output on the next page (otherwise they're lost as soon as Submit is pressed and creation view is exited)
            newLab = lHandler.findLabByID(labID)
            newUser = User(userID, username, firstName, lastName, description,
                           newLab, category, email, "")

            self.printUserInfo('edit', newUser, "Dup_un")
예제 #16
0
    def saveUser(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        # print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        # print					# DITTO
        # print `form`

        uHandler = UserHandler(db, cursor)
        lHandler = LabHandler(db, cursor)
        pHandler = ProjectDatabaseHandler(db, cursor)

        ucMapper = UserCategoryMapper(db, cursor)
        category_ID_Name_Map = ucMapper.mapCategoryIDToName()

        newProps = {}

        # Get form values
        userID = int(form.getvalue("userID"))
        newUser = uHandler.getUserByID(userID)

        labID = int(form.getvalue("labs"))
        tmpLab = lHandler.findLabByID(labID)

        # rest of user properties
        username = form.getvalue("username")
        firstName = form.getvalue("firstName")
        lastName = form.getvalue("lastName")
        description = firstName + " " + lastName
        email = form.getvalue("email")
        category = category_ID_Name_Map[int(form.getvalue("system_access_level"))]

        newProps["labID"] = labID
        newProps["username"] = username
        newProps["firstname"] = firstName
        newProps["lastname"] = lastName
        newProps["description"] = description
        newProps["email"] = email
        newProps["category"] = category

        try:
            # Now do an update on database level AND on class level:
            uHandler.updateUserProperties(userID, newProps)  # database update

            # Interface level
            newUser.setUsername(username)
            newUser.setFirstName(firstName)
            newUser.setLastName(lastName)
            newUser.setDescription(description)
            newUser.setEmail(email)
            newUser.setLab(tmpLab)
            newUser.setCategory(category)

            # update list of user's projects
            if form.has_key("userProjectsReadonly"):
                # list of IDs
                readonlyProjects = utils.unique(form.getlist("userProjectsReadonly"))
                pHandler.updateUserProjects(userID, readonlyProjects, "Reader")
            else:
                # safe to assume should delete projects?
                pHandler.deleteMemberProjects(userID, "Reader")

            if form.has_key("userProjectsWrite"):
                writeProjects = utils.unique(form.getlist("userProjectsWrite"))
                pHandler.updateUserProjects(userID, writeProjects, "Writer")
            else:
                # safe to assume should delete projects?
                pHandler.deleteMemberProjects(userID, "Writer")

                # think about this
                # newUser.setReadProjects(readProjects)
                # newUser.setWriteProjects(writeProjects)

                # return to detailed view
            self.printUserInfo("view", newUser)
            # utils.redirect(hostname + "User.php?View=3&fd=" + filename)

        except DuplicateUsernameException:

            # return to the view with input values and error message
            # Need to construct a dummy User instance to save form values for error output on the next page (otherwise they're lost as soon as Submit is pressed and creation view is exited)
            newLab = lHandler.findLabByID(labID)
            newUser = User(userID, username, firstName, lastName, description, newLab, category, email, "")

            self.printUserInfo("edit", newUser, "Dup_un")
예제 #17
0
    def saveLab(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        #print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        #print					# DITTO
        #print `form`

        # Handlers and mappers
        lHandler = LabHandler(db, cursor)
        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        # Get form values
        labID = int(form.getvalue("labID"))
        lab = Laboratory(
            labID
        )  # here need to use the default constructor and not findLabByID, because lab is being updated and need a fresh instance and set its attributes to new values

        newName = form.getvalue("labName")
        newLabHead = form.getvalue("labHead")
        newLabCode = form.getvalue("labCode").upper()
        newDescr = form.getvalue("description")
        newAddr = form.getvalue("address")
        newAccess = form.getvalue("system_access_level")
        newAccLev = category_Name_ID_Map[newAccess]

        # change database values
        try:
            lHandler.setLabName(labID, newName)
            lHandler.setLabHead(labID, newLabHead)
            lHandler.setLabCode(labID, newLabCode)
            lHandler.setLabDescription(labID, newDescr)
            lHandler.setLabAccessLevel(labID, newAccLev)
            lHandler.setLocation(labID, newAddr)

            #######################
            # update members!
            #######################

            newMembers = form.getlist("labMembers")
            lHandler.updateLabMembers(labID, newMembers)

            # change object values
            lab.setName(newName)
            lab.setLabHead(newLabHead)
            lab.setLabCode(newLabCode)
            lab.setDescription(newDescr)
            lab.setAddress(newAddr)
            lab.setDefaultAccessLevel(newAccess)

            # return to detailed view
            self.printLabInfo('view', lab)
            #utils.redirect(hostname + "User.php?View=5&Lab=" + `labID` + "&fd=" + filename)

        except DuplicateLabCodeException:

            newLab = Laboratory(labID, newName, newDescr, newAccess, newAddr,
                                newLabHead, newLabCode)

            d = DuplicateLabCodeException()
            self.printLabInfo('edit', newLab, d.err_code())
예제 #18
0
    def addUser(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname
        mail_server = self.__mail_server  # August 19, 2011

        mail_programmer = self.__mail_programmer  # July 30, 2010
        mail_biologist = self.__mail_biologist
        mail_admin = self.__mail_admin

        # print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        # print					# DITTO
        # print `form`

        uHandler = UserHandler(db, cursor)
        lHandler = LabHandler(db, cursor)
        pHandler = ProjectDatabaseHandler(db, cursor)

        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        # Get form values
        labID = int(form.getvalue("labs"))
        username = form.getvalue("username")

        firstName = form.getvalue("firstName")
        lastName = form.getvalue("lastName")
        description = firstName + " " + lastName

        to_email = form.getvalue("email")

        from_email = mail_admin

        # Change July 30, 2010 - random password generator
        # passwd = form.getvalue("password")

        chars = string.letters + string.digits
        passwd = ""

        for i in range(10):
            passwd += choice(chars)

            # System access level: Lab default or override?
            # if form.getvalue("privChoiceRadio") == 'override':
        accessLevel = category_Name_ID_Map[form.getvalue("system_access_level")]
        # else:
        # accessLevel = lHandler.findDefaultAccessLevel(labID)

        newProps = {}

        try:
            # Insert User information
            userID = uHandler.insertUser(
                username, firstName, lastName, description, accessLevel, to_email, passwd, labID
            )
            # newUser = uHandler.getUserByID(userID)
            tmpLab = lHandler.findLabByID(labID)
            # print tmpLab.getName()

            # Insert Project info
            # Sept. 11/07: Differentiate between user categories Reader and Writer - different field names
            if form.has_key("userProjectsReadonly"):
                # list of IDs
                readonlyProjects = utils.unique(form.getlist("userProjectsReadonly"))
                # print `readonlyProjects`
                pHandler.insertMemberProjects(userID, readonlyProjects, "Reader")

            elif form.has_key("userProjectsReadonlyWrite"):
                # list of IDs
                readonlyProjects = utils.unique(form.getlist("userProjectsReadonlyWrite"))
                # print `readonlyProjects`
                pHandler.insertMemberProjects(userID, readonlyProjects, "Reader")

                # Write projects exist only for Writers
            if form.has_key("userProjectsWrite"):
                writeProjects = utils.unique(form.getlist("userProjectsWrite"))
                pHandler.insertMemberProjects(userID, writeProjects, "Writer")

                # don't assign projects to a User instance - will retrieve them from db in output function
            newUser = User(
                userID,
                username,
                firstName,
                lastName,
                description,
                tmpLab,
                form.getvalue("system_access_level"),
                to_email,
                passwd,
                [],
                [],
            )

            email_subject = "OpenFreezer User Account"

            msg = email.MIMEMultipart.MIMEMultipart("alternative")

            msg["Subject"] = email_subject
            msg["To"] = to_email

            msgText = (
                "Hi "
                + firstName
                + ",<BR><BR>An OpenFreezer account has been created for you.&nbsp;&nbsp;Your access level is "
                + form.getvalue("system_access_level")
                + ", so you can "
            )

            if form.getvalue("system_access_level") == "Reader":
                msgText += "search for clones.&nbsp;&nbsp;If you wish to add/modify reagents or create projects, please contact the administrator to upgrade your access level.<BR>"

            elif form.getvalue("system_access_level") == "Writer":
                msgText += "search, add, and modify reagents.&nbsp;&nbsp;If you wish to create projects, please contact the administrator to upgrade your access level.<BR>"

            elif form.getvalue("system_access_level") == "Creator":
                msgText += "search for clones, add and modify reagents, as well as create your own projects.<BR>"

                #####################################################
                # CHANGE TEXT AS NEEDED
                #####################################################

            msgText += (
                "<BR>The URL to access the system is <a href='"
                + hostname
                + "'>"
                + hostname
                + "</a>.&nbsp;&nbsp;Your username is <b>"
                + username
                + "</b>, and your temporary password is <b>"
                + passwd
                + "</b>.&nbsp;&nbsp;Please <u>change the temporary password as soon as you log into the website</u> - you can do it through the 'Change your password' link under the 'User Management' menu section.<BR><BR>Please refer to http://openfreezer.org for additional support.<BR><BR>Sincerely,<BR>OpenFreezer  support team.<BR><BR><span style='font-family:Courier; font-size:10pt;'><HR>This is an automatically generated e-mail message.&nbsp;&nbsp;Please do not reply to this e-mail.&nbsp;&nbsp;All questions should be directed to your local administrator.</span>"
            )

            msgText = email.MIMEText.MIMEText(msgText, "html")
            msg.attach(msgText)

            server = smtplib.SMTP(mail_server)
            server.set_debuglevel(1)

            server.sendmail(from_email, [to_email], msg.as_string())
            server.quit()

            self.printUserInfo("view", newUser)

        except DeletedUserException:

            # Without asking too many questions, reactivate the deleted user and overwrite his/her attributes with the form input values
            userID = uHandler.findUserIDByUsername(username)

            newProps["firstname"] = firstName
            newProps["lastname"] = lastName
            newProps["description"] = description
            newProps["email"] = email
            newProps["status"] = "ACTIVE"
            newProps["password"] = passwd

            # Insert new database values and create new object
            uHandler.updateUserProperties(userID, newProps)  # database update
            newUser = uHandler.getUserByID(userID)

            # Insert Project info
            readProjects = []
            writeProjects = []

            if form.has_key("userProjectsReadonly"):
                # list of IDs
                readonlyProjects = form.getlist("userProjectsReadonly")

                for r in readonlyProjects:
                    pHandler.addProjectMember(r, userID, "Reader")

                    # tmpReadProject = pHandler.findPacket(r)
                    # readProjects.append(tmpReadProject)
                    # newUser.addProject(tmpReadProject, 'read')

            if form.has_key("userProjectsWrite"):
                writeProjects = form.getlist("userProjectsWrite")

                for w in writeProjects:
                    pHandler.addProjectMember(w, userID, "Writer")

                    # tmpWriteProject = pHandler.findPacket(w)
                    # writeProjects.append(tmpWriteProject)
                    # newUser.addProject(tmpWriteProject, 'write')

                    # newUser.setReadProjects(readProjects)
                    # newUser.setWriteProjects(writeProjects)

            self.printUserInfo("view", newUser)
            # utils.redirect(hostname + "User.php?View=3&fd=" + filename)

        except DuplicateUsernameException:

            # return to the view with input values and error message
            # Need to construct a dummy User instance to save form values for error output on the next page (otherwise they're lost as soon as Submit is pressed and creation view is exited)
            newLab = lHandler.findLabByID(labID)
            newUser = User(0, username, firstName, lastName, description, newLab, "", email, passwd)

            self.printUserInfo("create", newUser)
예제 #19
0
	def printSubmenuHeader(self, submenu_type):
		
		dbConn = DatabaseConn()
		hostname = dbConn.getHostname()		# to define form action URL
		
		db = dbConn.databaseConnect()
		cursor = db.cursor()

		uHandler = UserHandler(db, cursor)
		
		current_selection_names = []		# plain list of section names
		current_selection_links = {}		# dictionary, where section names are keys and their URLs are values
		
		if submenu_type == "Location":

			location_submenu_names = []
			location_submenu_links = {}
			
			location_submenu_names.append("Add container types")
			location_submenu_links["Add container types"] = "../Location.php?View=6&Sub=3"

			location_submenu_names.append("Add container sizes")
			location_submenu_links["Add container sizes"] = "../Location.php?View=6&Sub=1"

			location_submenu_names.append("Add containers")
			location_submenu_links["Add containers"] = "../Location.php?View=6&Sub=3"

			location_submenu_names.append("Search containers")
			location_submenu_links["Search containers"] = "../Location.php?View=2"

			current_selection_names = location_submenu_names
			current_selection_links = location_submenu_links

		elif submenu_type == "Reagent":

			reagent_submenu_names = []
			reagent_submenu_links = {}

			reagent_submenu_names.append("Add reagents")
			reagent_submenu_links["Add reagents"] = "../Reagent.php?View=2"

			reagent_submenu_names.append("Search reagents")
			reagent_submenu_links["Search reagents"] = "../search.php?View=1"

			# June 3/09
			reagent_submenu_names.append("Add reagent types")
			reagent_submenu_links["Add reagent types"] = "../Reagent.php?View=3"
			
			reagent_submenu_names.append("Search reagent types")
			reagent_submenu_links["Search reagent types"] = "../Reagent.php?View=5"
			
			current_selection_names = reagent_submenu_names
			current_selection_links = reagent_submenu_links

		elif submenu_type == "Chemical":
			
			chemical_submenu_names = []
			chemical_submenu_links = {}
			
			chemical_submenu_names.append("Add Chemicals")
			chemical_submenu_links["Add Chemicals"] = "../Chemical.php?View=2"
			
			chemical_submenu_names.append("Search Chemicals")
			chemical_submenu_links["Search Chemicals"] = "../Chemical.php?View=1"
			
			current_selection_names = chemical_submenu_names
			current_selection_links = chemical_submenu_links
			
		elif submenu_type == "Prediction":
			
			prediction_submenu_names = []
			prediction_submenu_links = {}
			
			prediction_submenu_names.append("Search predictions")
			prediction_submenu_links["Search predictions"] = "../Prediction.php?View=1"

			current_selection_names = prediction_submenu_names
			current_selection_links = prediction_submenu_links
	
		elif submenu_type == "Project":	

			project_submenu_names = []
			project_submenu_links = {}
			
			project_submenu_names.append("Add projects")
			project_submenu_links["Add projects"] = "../Project.php?View=1"

			project_submenu_names.append("Search projects")
			project_submenu_links["Search projects"] = "../Project.php?View=2"

			current_selection_names = project_submenu_names
			current_selection_links = project_submenu_links

		elif submenu_type == "User":

			user_submenu_names = []
			user_submenu_links = {}
			
			user_submenu_names.append("Add users")
			user_submenu_links["Add users"] = "../User.php?View=1"

			user_submenu_names.append("Search users")
			user_submenu_links["Search users"] = "../User.php?View=2"

			user_submenu_names.append("Change your password")
			user_submenu_links["Change your password"] = "******"

			user_submenu_names.append("Personal page")
			user_submenu_links["Personal page"] = "User.php?View=7"
			
			user_submenu_names.append("View your orders")
			user_submenu_links["View your orders"] = "../User.php?View=8"
			
			current_selection_names = user_submenu_names
			current_selection_links = user_submenu_links

		elif submenu_type == "Lab":

			lab_submenu_names = []
			lab_submenu_links = {}
			
			lab_submenu_names.append("Add laboratories")
			lab_submenu_links["Add laboratories"] = "../User.php?View=3"

			lab_submenu_names.append("Search laboratories")
			lab_submenu_links["Search laboratories"] = "../User.php?View=4"

			current_selection_names = lab_submenu_names
			current_selection_links = lab_submenu_links


		# There can be permission differentiations within a menu section as well (e.g. Projects - only Creators can create, buit Writers can view)
		currUser = Session.getUser()

		ucMapper = UserCategoryMapper(db, cursor)
		category_Name_ID_Map = ucMapper.mapCategoryNameToID()

		currUserCategory = category_Name_ID_Map[currUser.getCategory()]
		allowedSections = uHandler.getAllowedSections(currUserCategory)

		#print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
		#print					# DITTO
		#print `allowedSections`

		content = ""

		for name in current_selection_names:
		
			if name in allowedSections:
				
				if name == 'Personal page':
					content += "<LI class=\"submenu\">"
					
					content += "<IMG SRC=\"../pictures/star_bullet.gif\" WIDTH=\"10\" HEIGHT=\"10\" BORDER=\"0\" ALT=\"plus\" class=\"menu-leaf\">"

					content += "<span class=\"linkShow\" style=\"font-size:9pt\" onClick=\"redirectToCurrentUserDetailedView(" + `currUser.getUserID()` +  ");\">" + name + "</span>"

					content += "</LI>"

					content += "<form name=\"curr_user_form\" style=\"display:none\" method=\"post\" action=\"user_request_handler.py\">"
					
					content += "<INPUT type=\"hidden\" ID=\"curr_username_hidden\" NAME=\"curr_username\" VALUE=\"" + currUser.getFullName() + "\">"
					
					content += "<INPUT type=\"hidden\" id=\"curr_user_hidden\" name=\"view_user\">"
					content += "</FORM>"
				else:
					content += "<LI class=\"submenu\">"
	
					content += "<IMG SRC=\"../pictures/star_bullet.gif\" WIDTH=\"10\" HEIGHT=\"10\" BORDER=\"0\" ALT=\"plus\" class=\"menu-leaf\">"
	
					content += "<a class=\"submenu\" href=\"" + current_selection_links[name] + "\">" + name + "</a>"
					content += "</LI>"
				
		return content		
예제 #20
0
	def printMainMenu(self):

		dbConn = DatabaseConn()
		hostname = dbConn.getHostname()		# to define form action URL
		
		db = dbConn.databaseConnect()
		cursor = db.cursor()

		uHandler = UserHandler(db, cursor)
		
		# Aug. 20, 2010
		pageMapper = SystemModuleMapper(db, cursor)
		
		pageLinkMap = pageMapper.mapPageNameLink()
		
		# Array of section names
		currentSectionNames = []

		# Dictionary of links to names, with names as dictionary keys and links as values
		currentSectionLinks = {}

		# Added Nov. 10/06 by Marina - Classify each header as to what OF section it belongs
    		menuTypes = {}

		# June 04/07 - Differentiate between 'public' and 'private' pages
		publicSectionNames = []
    		publicSectionLinks = []

		publicSections = {}
		
		# Feb. 2, 2010: change menu layout (reflect HeaderFunctions.php code changes Jan. 12/10)
		submenu_links = {}
		submenu_types = {}
		menuitems = {}
		
		# Home
		currentSectionNames.append("Home")
		currentSectionLinks["Home"] = "../index.php"
		publicSections["Home"] = "index.php"

		# Reagent
		currentSectionNames.append("Reagent Tracker")
		currentSectionLinks["Reagent Tracker"] = "../Reagent.php?View=1"
		
		menuTypes["Reagent Tracker"] = "Reagent"
		publicSections["Reagent Tracker"] = "../Reagent.php?View=1"
		
		# Feb. 2, 2010
		tmp_list = []
		tmp_list.append("Reagents")
		tmp_list.append("Reagent Types")
		
		submenu_types["Reagent Tracker"] = tmp_list
		
		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		tmp_order_list[1] = "Search"
		tmp_order_list[2] = "Statistics"

		submenu_order = {}
		submenu_order["Reagents"] = tmp_order_list

		tmp_list = {}
		tmp_list["Add"] = "../Reagent.php?View=2"
		tmp_list["Search"] = "../search.php?View=1"
		tmp_list["Statistics"] = "../Reagent.php?View=4"
		
		submenu_links["Reagents"] = tmp_list
		
		tmp_list = {}
		tmp_list["Add"] = "Add reagents"
		tmp_list["Search"] = "Search reagents"
		tmp_list["Statistics"] = "Statistics"
	
		menuitems["Reagents"] = tmp_list
	
		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		tmp_order_list[1] = "Search"
	
		submenu_order["Reagent Types"] = tmp_order_list

		tmp_list = {}
		tmp_list["Add"] = "../Reagent.php?View=3"
		tmp_list["Search"] = "../Reagent.php?View=5"
		submenu_links["Reagent Types"] = tmp_list
		
		tmp_list = {}
		tmp_list["Add"] = "Add reagent types"
		tmp_list["Search"] = "Search reagent types"
		menuitems["Reagent Types"] = tmp_list
		
		# Locations
		currentSectionNames.append("Location Tracker")
		currentSectionLinks["Location Tracker"] = "../Location.php?View=1"
		
		menuTypes["Location Tracker"] = "Location"
		publicSections["Location Tracker"] = "../Location.php?View=1"

		# Feb. 2/10
		tmp_list = []
		tmp_list.append("Containers")
		tmp_list.append("Container Sizes")
		tmp_list.append("Container Types")
		submenu_types["Location Tracker"] = tmp_list
		
		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		tmp_order_list[1] = "Search"
	
		submenu_order["Container Types"] = tmp_order_list
	
		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		#tmp_order_list[1] = "Search"
	
		submenu_order["Container Sizes"] = tmp_order_list
	
		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		tmp_order_list[1] = "Search"
	
		submenu_order["Containers"] = tmp_order_list
	
		tmp_list = {}
		tmp_list["Add"] = "../Location.php?View=6&Sub=2"
		tmp_list["Search"] = "../Location.php?View=6&Sub=4"
		submenu_links["Container Types"] = tmp_list
	
		tmp_list = {}
		tmp_list["Add"] = "Add container types"
		tmp_list["Search"] = "Search container types"
		menuitems["Container Types"] = tmp_list
		
		tmp_list = {}
		tmp_list["Add"] = "../Location.php?View=6&Sub=1"
		tmp_list["Search"] = "../Location.php?View=6&Sub=5"
		submenu_links["Container Sizes"] = tmp_list
	
		tmp_list = {}
		tmp_list["Add"] = "Add container sizes"
		#tmp_list["Search"] = "Search container sizes"
		menuitems["Container Sizes"] = tmp_list
		
		tmp_list = {}
		tmp_list["Add"] = "../Location.php?View=6&Sub=3"
		tmp_list["Search"] = "../Location.php?View=2"
		submenu_links["Containers"] = tmp_list
		
		tmp_list = {}
		tmp_list["Add"] = "Add containers"
		tmp_list["Search"] = "Search containers"
		menuitems["Containers"] = tmp_list
		
		# Projects
		currentSectionNames.append("Project Management")
		currentSectionLinks["Project Management"] = "../Project.php?View=1"
		menuTypes["Project Management"] = "Project"
		
		# Feb. 2/10
		tmp_list = []
		tmp_list.append("Projects")
		submenu_types["Project Management"] = tmp_list

		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		tmp_order_list[1] = "Search"
	
		submenu_order["Projects"] = tmp_order_list
	
		tmp_list = {}
		tmp_list["Add"] = "../Project.php?View=1"
		tmp_list["Search"] = "../Project.php?View=2"
		submenu_links["Projects"] = tmp_list
	
		tmp_list = {}
		tmp_list["Add"] = "Add projects"
		tmp_list["Search"] = "Search projects"
		menuitems["Projects"] = tmp_list

		# Users and Labs
		currentSectionNames.append("User Management")
		currentSectionLinks["User Management"] = "../User.php"
		menuTypes["User Management"] = "User"

		currentSectionNames.append("Lab Management")
		currentSectionLinks["Lab Management"] = "../User.php"
		menuTypes["Lab Management"] = "Laboratories"

		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		tmp_order_list[1] = "Search"
	
		submenu_order["Laboratories"] = tmp_order_list
	
		# Jan. 7/09: Chemicals
		currentSectionNames.append("Chemical Tracker")
		currentSectionLinks["Chemical Tracker"] = "../Chemical.php?View=1"
		menuTypes["Chemical Tracker"] = "Chemical"
		
		# Feb. 2, 2010
		tmp_list = []
		tmp_list.append("Chemicals")
		submenu_types["Chemical Tracker"] = tmp_list
		
		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		tmp_order_list[1] = "Search"
	
		submenu_order["Chemicals"] = tmp_order_list
	
		tmp_list = {}
		tmp_list["Add"] = "../Chemical.php?View=2"
		tmp_list["Search"] = "../Chemical.php?View=1"
		submenu_links["Chemicals"] = tmp_list
		
		tmp_list = {}
		tmp_list["Add"] = "Add Chemicals"
		tmp_list["Search"] = "Search Chemicals"
		menuitems["Chemicals"] = tmp_list

		# Feb. 2/10
		tmp_list = []
		tmp_list.append("Users")
		submenu_types["User Management"] = tmp_list

		tmp_list = {}
		tmp_list["Add"] = "../User.php?View=1"
		tmp_list["Search"] = "../User.php?View=2"
		tmp_list["Change your password"] = "******"
		tmp_list["Personal page"] = "../User.php?View=7"
		tmp_list["View your orders"] = "../User.php?View=8"
		submenu_links["Users"] = tmp_list
	
		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		tmp_order_list[1] = "Search"
		tmp_order_list[2] = "Change your password"
		tmp_order_list[3] = "Personal page"
		tmp_order_list[4] = "View your orders"
		
		submenu_order["Users"] = tmp_order_list
	
		tmp_list = {}
		tmp_list["Add"] = "Add users"
		tmp_list["Search"] = "Search users"
		tmp_list["Change your password"] = "******"
		tmp_list["Personal page"] = "Personal page"
		tmp_list["View your orders"] = "View your orders"
		menuitems["Users"] = tmp_list
		
		tmp_list = []
		tmp_list.append("Laboratories")
		submenu_types["Lab Management"] = tmp_list
		
		tmp_list = {}
		tmp_list["Add"] = "../User.php?View=3"
		tmp_list["Search"] = "../User.php?View=4"
		submenu_links["Laboratories"] = tmp_list
		
		tmp_order_list = {}
		tmp_order_list[0] = "Add"
		tmp_order_list[1] = "Search"
		submenu_order["Laboratories"] = tmp_order_list
		
		tmp_list = {}
		
		tmp_list["Add"] = "Add laboratories"
		tmp_list["Search"] = "Search laboratories"
		menuitems["Laboratories"] = tmp_list

		currentSectionNames.append("Documentation")
		currentSectionLinks["Documentation"] = "../docs.php"
		publicSections["Documentation"] = "docs.php"

 		currentSectionNames.append("Terms and Conditions")
 		currentSectionLinks["Terms and Conditions"] = "../copyright.php"
		publicSections["Terms and Conditions"] = "copyright.php"

		currentSectionNames.append("Help and Support")
 		currentSectionLinks["Help and Support"] = "../bugreport.php"
		publicSections["Help and Support"] = "bugreport.php"

 		currentSectionNames.append("Contact Us")
 		currentSectionLinks["Contact Us"] = "../contacts.php"
		publicSections["Contact Us"] = "contacts.php"
		
		# Aug. 20/10: Quick links
		
		tmp_ql = []
		quickLinks = {}

		tmp_ql.append("Add reagents")
		tmp_ql.append("Search reagents")

		quickLinks["Reagent Tracker"] = tmp_ql
		
		tmp_ql = []
		
		tmp_ql.append("Add containers")
		tmp_ql.append("Search containers")
	
		quickLinks["Location Tracker"] = tmp_ql
		
		tmp_ql = []
		
		tmp_ql.append("Add projects")
		tmp_ql.append("Search projects")
		
		quickLinks["Project Management"] = tmp_ql
		
		tmp_ql = []
		
		tmp_ql.append("Change your password")
		tmp_ql.append("View your orders")
		
		quickLinks["User Management"] = tmp_ql
		
		content = '''
			<div class="sidemenu" ID="mainMenu">
				<div class="menu-content">
					<ul class="menulist">
						<!-- menu goes here -->
						'''
		
		# Output the menu link IFF the user is authorized to access that page
		currUser = Session.getUser()

		if currUser:
			ucMapper = UserCategoryMapper(db, cursor)
			category_Name_ID_Map = ucMapper.mapCategoryNameToID()
			currUserCategory = category_Name_ID_Map[currUser.getCategory()]
			
			#print "Content-type:text/html"
			#print
			allowedSections = uHandler.getAllowedSections(currUserCategory)
			#print `allowedSections`
			
			for name in currentSectionNames:
				
				if name in allowedSections:
					
					# added Jan. 7/09
					if name in menuTypes:
						#print "Content-type:text/html"
						#print
						#print name
						
						content += "<DIV style=\"border-top:3px double #FFF8DC; border-right:6px double #FFF8DC; border-bottom:3px double #FFF8DC; border-left:6px double #FFF8DC; margin-top:2px; width:162px; padding-top:5px; padding-bottom:0;\">"
						
						content += "<DIV style=\"background-image:url('../pictures/small_bg.png'); width:166px; height:30px;\">"
						
						content += "<select style=\"cursor:pointer; width:150px; background:#FFF8DC; font-weight:bold; color:#555; font-size:9pt; margin-top:3px; margin-left:2px;  font-family:Helvetica; border:0;\" onChange=\"openPage(this.options[this.options.selectedIndex]);\">"
						
						content += "<option selected style=\"cursor:pointer; font-weight:bold; color:#555; font-size:9pt; border:0; font-family:Helvetica;\" value=\"\">&nbsp;" + name + "</option>"
						
						for st_val in submenu_types[name]:
							numDisallowed = 0
							
							# Jan. 13, 2010: Don't print category heading if user has no access to any of its subitems
							for s_ord in submenu_order[st_val]:
								linkName = submenu_order[st_val][s_ord]
								linkURL = submenu_links[st_val][linkName]
								
								if not menuitems[st_val][linkName] in allowedSections:
									numDisallowed += 1
							
							if numDisallowed == len(submenu_links[st_val]):
								continue
							
							#print st_val.upper()
							content += "<option style=\"cursor:pointer; font-weight:bold; color:#555; background:#EFEFEF; font-size:9pt; border:0; font-family:Helvetica;\" onclick\"\">&nbsp;" + st_val.upper() + "</option>"
						
							# Now: since Python dictionaries are not ordered, arrays with > 2 items (e.g. Users - has more than 'add' and 'search') would appear scrambled.  Use an 'order' array instead
							for s_ord in submenu_order[st_val]:
								
								linkName = submenu_order[st_val][s_ord]
								linkURL = submenu_links[st_val][linkName]
								
								#print st_val
								#print linkName
								
								if menuitems[st_val][linkName] in allowedSections:

									content += "<option style=\"padding-left:15px; font-weight:bold; color:#555; font-size:8pt; border:0; font-family:Helvetica; cursor:pointer;\" value=\"" + linkURL + "\">&nbsp;&nbsp;&nbsp;" + linkName + "</option>"
							
						content += "</SELECT>"
						
						content += "</DIV>"
						
						# Quick links
						if quickLinks.has_key(name):
							content += "<div id=\"quick_links_" + name + "\" style=\"font-family:Helvetica; width:166px; padding-bottom:0; margin-top:0; padding-top:0; padding-left:2px;\">"
							
							content += "<UL style=\"padding-bottom:2px; padding-top:2px; padding-left:10px; position:relative;\">"
							
							for qlName in quickLinks[name]:
							
								if qlName in allowedSections:
								
									content += "<LI style=\"list-style:none;\"><img  src=\"../pictures/silvermenubullet.png\" width=\"7\" height=\"6\" style=\"padding-bottom:2px;\">&nbsp;<a style=\"font-weight:bold; font-size:8pt; font-family:Helvetica; text-decoration:none; color:#555; margin-left:2px;\" href=\"../" + pageLinkMap[qlName] + "\">" + qlName + "</a></LI>"
							
							content += "</UL>"
							
							content += "</DIV>"

						content += "</DIV>"
					else:
						if name == "Home":
							content += "<DIV style=\"background:url('../pictures/small_bg.png') repeat-y; padding-top:7px; margin-top:0; width:162px; border-top:6px double #FFF8DC; border-left:6px double #FFF8DC; border-right:6px double #FFF8DC; padding-bottom:8px;\">"

						else:
							content += "<DIV style=\"background:url('../pictures/small_bg.png') repeat-y; padding-top:7px; margin-top:2px; width:162px; border-left:6px double #FFF8DC; border-right:6px double #FFF8DC; padding-bottom:8px;\">"

						content += "<img src=\"../pictures/silvermenubullet.png\" style=\"width:11px; height:9px; margin-left:5px;\">"

						content += "<a style=\"font-weight:bold; color:#555; font-size:9pt; padding-left:3px; text-decoration:none;\" href=\"" + currentSectionLinks[name] + "\">" + name + "</a>"
						
						content += "</DIV>"
		else:
			# WRITE THIS FUNCTION!!!!!!!!!!
			#content += self.printGeneralMenu(publicSections)
			print "Content-type:text/html"
			print
			print "Unknown user"
		
		content += '''
					</UL>
				
					<!-- moved form down here on Aug. 20, 2010 -->
					<form name="curr_user_form" style="display:none" method="post" action="user_request_handler.py">"
					'''

		content += "<INPUT type=\"hidden\" ID=\"curr_username_hidden\" NAME=\"curr_username\" VALUE=\"" + currUser.getFullName() + "\">"
		
		content += "<INPUT TYPE=\"hidden\" id=\"curr_user_hidden\" name=\"view_user\" VALUE=\"" + `currUser.getUserID()` + "\">"
		
		content += '''
					</FORM>
				
					<div class="login">
					'''

		content += self.printLoginBlock()
		content += '''
					</div>
				</div>
			</div>
			'''
			
		return content
예제 #21
0
    def printSubmenuHeader(self, submenu_type):

        dbConn = DatabaseConn()
        hostname = dbConn.getHostname()  # to define form action URL

        db = dbConn.databaseConnect()
        cursor = db.cursor()

        uHandler = UserHandler(db, cursor)

        current_selection_names = []  # plain list of section names
        current_selection_links = {}  # dictionary, where section names are keys and their URLs are values

        if submenu_type == "Location":

            location_submenu_names = []
            location_submenu_links = {}

            location_submenu_names.append("Add container types")
            location_submenu_links["Add container types"] = "../Location.php?View=6&Sub=3"

            location_submenu_names.append("Add container sizes")
            location_submenu_links["Add container sizes"] = "../Location.php?View=6&Sub=1"

            location_submenu_names.append("Add containers")
            location_submenu_links["Add containers"] = "../Location.php?View=6&Sub=3"

            location_submenu_names.append("Search containers")
            location_submenu_links["Search containers"] = "../Location.php?View=2"

            current_selection_names = location_submenu_names
            current_selection_links = location_submenu_links

        elif submenu_type == "Reagent":

            reagent_submenu_names = []
            reagent_submenu_links = {}

            reagent_submenu_names.append("Add reagents")
            reagent_submenu_links["Add reagents"] = "../Reagent.php?View=2"

            reagent_submenu_names.append("Search reagents")
            reagent_submenu_links["Search reagents"] = "../search.php?View=1"

            # June 3/09
            reagent_submenu_names.append("Add reagent types")
            reagent_submenu_links["Add reagent types"] = "../Reagent.php?View=3"

            reagent_submenu_names.append("Search reagent types")
            reagent_submenu_links["Search reagent types"] = "../Reagent.php?View=5"

            current_selection_names = reagent_submenu_names
            current_selection_links = reagent_submenu_links

        elif submenu_type == "Chemical":

            chemical_submenu_names = []
            chemical_submenu_links = {}

            chemical_submenu_names.append("Add Chemicals")
            chemical_submenu_links["Add Chemicals"] = "../Chemical.php?View=2"

            chemical_submenu_names.append("Search Chemicals")
            chemical_submenu_links["Search Chemicals"] = "../Chemical.php?View=1"

            current_selection_names = chemical_submenu_names
            current_selection_links = chemical_submenu_links

        elif submenu_type == "Prediction":

            prediction_submenu_names = []
            prediction_submenu_links = {}

            prediction_submenu_names.append("Search predictions")
            prediction_submenu_links["Search predictions"] = "../Prediction.php?View=1"

            current_selection_names = prediction_submenu_names
            current_selection_links = prediction_submenu_links

        elif submenu_type == "Project":

            project_submenu_names = []
            project_submenu_links = {}

            project_submenu_names.append("Add projects")
            project_submenu_links["Add projects"] = "../Project.php?View=1"

            project_submenu_names.append("Search projects")
            project_submenu_links["Search projects"] = "../Project.php?View=2"

            current_selection_names = project_submenu_names
            current_selection_links = project_submenu_links

        elif submenu_type == "User":

            user_submenu_names = []
            user_submenu_links = {}

            user_submenu_names.append("Add users")
            user_submenu_links["Add users"] = "../User.php?View=1"

            user_submenu_names.append("Search users")
            user_submenu_links["Search users"] = "../User.php?View=2"

            user_submenu_names.append("Change your password")
            user_submenu_links["Change your password"] = "******"

            user_submenu_names.append("Personal page")
            user_submenu_links["Personal page"] = "User.php?View=7"

            user_submenu_names.append("View your orders")
            user_submenu_links["View your orders"] = "../User.php?View=8"

            current_selection_names = user_submenu_names
            current_selection_links = user_submenu_links

        elif submenu_type == "Lab":

            lab_submenu_names = []
            lab_submenu_links = {}

            lab_submenu_names.append("Add laboratories")
            lab_submenu_links["Add laboratories"] = "../User.php?View=3"

            lab_submenu_names.append("Search laboratories")
            lab_submenu_links["Search laboratories"] = "../User.php?View=4"

            current_selection_names = lab_submenu_names
            current_selection_links = lab_submenu_links

            # There can be permission differentiations within a menu section as well (e.g. Projects - only Creators can create, buit Writers can view)
        currUser = Session.getUser()

        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        currUserCategory = category_Name_ID_Map[currUser.getCategory()]
        allowedSections = uHandler.getAllowedSections(currUserCategory)

        # print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        # print					# DITTO
        # print `allowedSections`

        content = ""

        for name in current_selection_names:

            if name in allowedSections:

                if name == "Personal page":
                    content += '<LI class="submenu">'

                    content += '<IMG SRC="../pictures/star_bullet.gif" WIDTH="10" HEIGHT="10" BORDER="0" ALT="plus" class="menu-leaf">'

                    content += (
                        '<span class="linkShow" style="font-size:9pt" onClick="redirectToCurrentUserDetailedView('
                        + ` currUser.getUserID() `
                        + ');">'
                        + name
                        + "</span>"
                    )

                    content += "</LI>"

                    content += '<form name="curr_user_form" style="display:none" method="post" action="user_request_handler.py">'

                    content += (
                        '<INPUT type="hidden" ID="curr_username_hidden" NAME="curr_username" VALUE="'
                        + currUser.getFullName()
                        + '">'
                    )

                    content += '<INPUT type="hidden" id="curr_user_hidden" name="view_user">'
                    content += "</FORM>"
                else:
                    content += '<LI class="submenu">'

                    content += '<IMG SRC="../pictures/star_bullet.gif" WIDTH="10" HEIGHT="10" BORDER="0" ALT="plus" class="menu-leaf">'

                    content += '<a class="submenu" href="' + current_selection_links[name] + '">' + name + "</a>"
                    content += "</LI>"

        return content
예제 #22
0
    def printMainMenu(self):

        dbConn = DatabaseConn()
        hostname = dbConn.getHostname()  # to define form action URL

        db = dbConn.databaseConnect()
        cursor = db.cursor()

        uHandler = UserHandler(db, cursor)

        # Aug. 20, 2010
        pageMapper = SystemModuleMapper(db, cursor)

        pageLinkMap = pageMapper.mapPageNameLink()

        # Array of section names
        currentSectionNames = []

        # Dictionary of links to names, with names as dictionary keys and links as values
        currentSectionLinks = {}

        # Added Nov. 10/06 by Marina - Classify each header as to what OF section it belongs
        menuTypes = {}

        # June 04/07 - Differentiate between 'public' and 'private' pages
        publicSectionNames = []
        publicSectionLinks = []

        publicSections = {}

        # Feb. 2, 2010: change menu layout (reflect HeaderFunctions.php code changes Jan. 12/10)
        submenu_links = {}
        submenu_types = {}
        menuitems = {}

        # Home
        currentSectionNames.append("Home")
        currentSectionLinks["Home"] = "../index.php"
        publicSections["Home"] = "index.php"

        # Reagent
        currentSectionNames.append("Reagent Tracker")
        currentSectionLinks["Reagent Tracker"] = "../Reagent.php?View=1"

        menuTypes["Reagent Tracker"] = "Reagent"
        publicSections["Reagent Tracker"] = "../Reagent.php?View=1"

        # Feb. 2, 2010
        tmp_list = []
        tmp_list.append("Reagents")
        tmp_list.append("Reagent Types")

        submenu_types["Reagent Tracker"] = tmp_list

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        tmp_order_list[1] = "Search"
        tmp_order_list[2] = "Statistics"

        submenu_order = {}
        submenu_order["Reagents"] = tmp_order_list

        tmp_list = {}
        tmp_list["Add"] = "../Reagent.php?View=2"
        tmp_list["Search"] = "../search.php?View=1"
        tmp_list["Statistics"] = "../Reagent.php?View=4"

        submenu_links["Reagents"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "Add reagents"
        tmp_list["Search"] = "Search reagents"
        tmp_list["Statistics"] = "Statistics"

        menuitems["Reagents"] = tmp_list

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        tmp_order_list[1] = "Search"

        submenu_order["Reagent Types"] = tmp_order_list

        tmp_list = {}
        tmp_list["Add"] = "../Reagent.php?View=3"
        tmp_list["Search"] = "../Reagent.php?View=5"
        submenu_links["Reagent Types"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "Add reagent types"
        tmp_list["Search"] = "Search reagent types"
        menuitems["Reagent Types"] = tmp_list

        # Locations
        currentSectionNames.append("Location Tracker")
        currentSectionLinks["Location Tracker"] = "../Location.php?View=1"

        menuTypes["Location Tracker"] = "Location"
        publicSections["Location Tracker"] = "../Location.php?View=1"

        # Feb. 2/10
        tmp_list = []
        tmp_list.append("Containers")
        tmp_list.append("Container Sizes")
        tmp_list.append("Container Types")
        submenu_types["Location Tracker"] = tmp_list

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        tmp_order_list[1] = "Search"

        submenu_order["Container Types"] = tmp_order_list

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        # tmp_order_list[1] = "Search"

        submenu_order["Container Sizes"] = tmp_order_list

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        tmp_order_list[1] = "Search"

        submenu_order["Containers"] = tmp_order_list

        tmp_list = {}
        tmp_list["Add"] = "../Location.php?View=6&Sub=2"
        tmp_list["Search"] = "../Location.php?View=6&Sub=4"
        submenu_links["Container Types"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "Add container types"
        tmp_list["Search"] = "Search container types"
        menuitems["Container Types"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "../Location.php?View=6&Sub=1"
        tmp_list["Search"] = "../Location.php?View=6&Sub=5"
        submenu_links["Container Sizes"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "Add container sizes"
        # tmp_list["Search"] = "Search container sizes"
        menuitems["Container Sizes"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "../Location.php?View=6&Sub=3"
        tmp_list["Search"] = "../Location.php?View=2"
        submenu_links["Containers"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "Add containers"
        tmp_list["Search"] = "Search containers"
        menuitems["Containers"] = tmp_list

        # Projects
        currentSectionNames.append("Project Management")
        currentSectionLinks["Project Management"] = "../Project.php?View=1"
        menuTypes["Project Management"] = "Project"

        # Feb. 2/10
        tmp_list = []
        tmp_list.append("Projects")
        submenu_types["Project Management"] = tmp_list

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        tmp_order_list[1] = "Search"

        submenu_order["Projects"] = tmp_order_list

        tmp_list = {}
        tmp_list["Add"] = "../Project.php?View=1"
        tmp_list["Search"] = "../Project.php?View=2"
        submenu_links["Projects"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "Add projects"
        tmp_list["Search"] = "Search projects"
        menuitems["Projects"] = tmp_list

        # Users and Labs
        currentSectionNames.append("User Management")
        currentSectionLinks["User Management"] = "../User.php"
        menuTypes["User Management"] = "User"

        currentSectionNames.append("Lab Management")
        currentSectionLinks["Lab Management"] = "../User.php"
        menuTypes["Lab Management"] = "Laboratories"

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        tmp_order_list[1] = "Search"

        submenu_order["Laboratories"] = tmp_order_list

        # Jan. 7/09: Chemicals
        currentSectionNames.append("Chemical Tracker")
        currentSectionLinks["Chemical Tracker"] = "../Chemical.php?View=1"
        menuTypes["Chemical Tracker"] = "Chemical"

        # Feb. 2, 2010
        tmp_list = []
        tmp_list.append("Chemicals")
        submenu_types["Chemical Tracker"] = tmp_list

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        tmp_order_list[1] = "Search"

        submenu_order["Chemicals"] = tmp_order_list

        tmp_list = {}
        tmp_list["Add"] = "../Chemical.php?View=2"
        tmp_list["Search"] = "../Chemical.php?View=1"
        submenu_links["Chemicals"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "Add Chemicals"
        tmp_list["Search"] = "Search Chemicals"
        menuitems["Chemicals"] = tmp_list

        # Feb. 2/10
        tmp_list = []
        tmp_list.append("Users")
        submenu_types["User Management"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "../User.php?View=1"
        tmp_list["Search"] = "../User.php?View=2"
        tmp_list["Change your password"] = "******"
        tmp_list["Personal page"] = "../User.php?View=7"
        tmp_list["View your orders"] = "../User.php?View=8"
        submenu_links["Users"] = tmp_list

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        tmp_order_list[1] = "Search"
        tmp_order_list[2] = "Change your password"
        tmp_order_list[3] = "Personal page"
        tmp_order_list[4] = "View your orders"

        submenu_order["Users"] = tmp_order_list

        tmp_list = {}
        tmp_list["Add"] = "Add users"
        tmp_list["Search"] = "Search users"
        tmp_list["Change your password"] = "******"
        tmp_list["Personal page"] = "Personal page"
        tmp_list["View your orders"] = "View your orders"
        menuitems["Users"] = tmp_list

        tmp_list = []
        tmp_list.append("Laboratories")
        submenu_types["Lab Management"] = tmp_list

        tmp_list = {}
        tmp_list["Add"] = "../User.php?View=3"
        tmp_list["Search"] = "../User.php?View=4"
        submenu_links["Laboratories"] = tmp_list

        tmp_order_list = {}
        tmp_order_list[0] = "Add"
        tmp_order_list[1] = "Search"
        submenu_order["Laboratories"] = tmp_order_list

        tmp_list = {}

        tmp_list["Add"] = "Add laboratories"
        tmp_list["Search"] = "Search laboratories"
        menuitems["Laboratories"] = tmp_list

        currentSectionNames.append("Documentation")
        currentSectionLinks["Documentation"] = "../docs.php"
        publicSections["Documentation"] = "docs.php"

        currentSectionNames.append("Terms and Conditions")
        currentSectionLinks["Terms and Conditions"] = "../copyright.php"
        publicSections["Terms and Conditions"] = "copyright.php"

        currentSectionNames.append("Help and Support")
        currentSectionLinks["Help and Support"] = "../bugreport.php"
        publicSections["Help and Support"] = "bugreport.php"

        currentSectionNames.append("Contact Us")
        currentSectionLinks["Contact Us"] = "../contacts.php"
        publicSections["Contact Us"] = "contacts.php"

        # Aug. 20/10: Quick links

        tmp_ql = []
        quickLinks = {}

        tmp_ql.append("Add reagents")
        tmp_ql.append("Search reagents")

        quickLinks["Reagent Tracker"] = tmp_ql

        tmp_ql = []

        tmp_ql.append("Add containers")
        tmp_ql.append("Search containers")

        quickLinks["Location Tracker"] = tmp_ql

        tmp_ql = []

        tmp_ql.append("Add projects")
        tmp_ql.append("Search projects")

        quickLinks["Project Management"] = tmp_ql

        tmp_ql = []

        tmp_ql.append("Change your password")
        tmp_ql.append("View your orders")

        quickLinks["User Management"] = tmp_ql

        content = """
			<div class="sidemenu" ID="mainMenu">
				<div class="menu-content">
					<ul class="menulist">
						<!-- menu goes here -->
						"""

        # Output the menu link IFF the user is authorized to access that page
        currUser = Session.getUser()

        if currUser:
            ucMapper = UserCategoryMapper(db, cursor)
            category_Name_ID_Map = ucMapper.mapCategoryNameToID()
            currUserCategory = category_Name_ID_Map[currUser.getCategory()]

            # print "Content-type:text/html"
            # print
            allowedSections = uHandler.getAllowedSections(currUserCategory)
            # print `allowedSections`

            for name in currentSectionNames:

                if name in allowedSections:

                    # added Jan. 7/09
                    if name in menuTypes:
                        # print "Content-type:text/html"
                        # print
                        # print name

                        content += '<DIV style="border-top:3px double #FFF8DC; border-right:6px double #FFF8DC; border-bottom:3px double #FFF8DC; border-left:6px double #FFF8DC; margin-top:2px; width:162px; padding-top:5px; padding-bottom:0;">'

                        content += "<DIV style=\"background-image:url('../pictures/small_bg.png'); width:166px; height:30px;\">"

                        content += '<select style="cursor:pointer; width:150px; background:#FFF8DC; font-weight:bold; color:#555; font-size:9pt; margin-top:3px; margin-left:2px;  font-family:Helvetica; border:0;" onChange="openPage(this.options[this.options.selectedIndex]);">'

                        content += (
                            '<option selected style="cursor:pointer; font-weight:bold; color:#555; font-size:9pt; border:0; font-family:Helvetica;" value="">&nbsp;'
                            + name
                            + "</option>"
                        )

                        for st_val in submenu_types[name]:
                            numDisallowed = 0

                            # Jan. 13, 2010: Don't print category heading if user has no access to any of its subitems
                            for s_ord in submenu_order[st_val]:
                                linkName = submenu_order[st_val][s_ord]
                                linkURL = submenu_links[st_val][linkName]

                                if not menuitems[st_val][linkName] in allowedSections:
                                    numDisallowed += 1

                            if numDisallowed == len(submenu_links[st_val]):
                                continue

                                # print st_val.upper()
                            content += (
                                '<option style="cursor:pointer; font-weight:bold; color:#555; background:#EFEFEF; font-size:9pt; border:0; font-family:Helvetica;" onclick"">&nbsp;'
                                + st_val.upper()
                                + "</option>"
                            )

                            # Now: since Python dictionaries are not ordered, arrays with > 2 items (e.g. Users - has more than 'add' and 'search') would appear scrambled.  Use an 'order' array instead
                            for s_ord in submenu_order[st_val]:

                                linkName = submenu_order[st_val][s_ord]
                                linkURL = submenu_links[st_val][linkName]

                                # print st_val
                                # print linkName

                                if menuitems[st_val][linkName] in allowedSections:

                                    content += (
                                        '<option style="padding-left:15px; font-weight:bold; color:#555; font-size:8pt; border:0; font-family:Helvetica; cursor:pointer;" value="'
                                        + linkURL
                                        + '">&nbsp;&nbsp;&nbsp;'
                                        + linkName
                                        + "</option>"
                                    )

                        content += "</SELECT>"

                        content += "</DIV>"

                        # Quick links
                        if quickLinks.has_key(name):
                            content += (
                                '<div id="quick_links_'
                                + name
                                + '" style="font-family:Helvetica; width:166px; padding-bottom:0; margin-top:0; padding-top:0; padding-left:2px;">'
                            )

                            content += '<UL style="padding-bottom:2px; padding-top:2px; padding-left:10px; position:relative;">'

                            for qlName in quickLinks[name]:

                                if qlName in allowedSections:

                                    content += (
                                        '<LI style="list-style:none;"><img  src="../pictures/silvermenubullet.png" width="7" height="6" style="padding-bottom:2px;">&nbsp;<a style="font-weight:bold; font-size:8pt; font-family:Helvetica; text-decoration:none; color:#555; margin-left:2px;" href="../'
                                        + pageLinkMap[qlName]
                                        + '">'
                                        + qlName
                                        + "</a></LI>"
                                    )

                            content += "</UL>"

                            content += "</DIV>"

                        content += "</DIV>"
                    else:
                        if name == "Home":
                            content += "<DIV style=\"background:url('../pictures/small_bg.png') repeat-y; padding-top:7px; margin-top:0; width:162px; border-top:6px double #FFF8DC; border-left:6px double #FFF8DC; border-right:6px double #FFF8DC; padding-bottom:8px;\">"

                        else:
                            content += "<DIV style=\"background:url('../pictures/small_bg.png') repeat-y; padding-top:7px; margin-top:2px; width:162px; border-left:6px double #FFF8DC; border-right:6px double #FFF8DC; padding-bottom:8px;\">"

                        content += '<img src="../pictures/silvermenubullet.png" style="width:11px; height:9px; margin-left:5px;">'

                        content += (
                            '<a style="font-weight:bold; color:#555; font-size:9pt; padding-left:3px; text-decoration:none;" href="'
                            + currentSectionLinks[name]
                            + '">'
                            + name
                            + "</a>"
                        )

                        content += "</DIV>"
        else:
            # WRITE THIS FUNCTION!!!!!!!!!!
            # content += self.printGeneralMenu(publicSections)
            print "Content-type:text/html"
            print
            print "Unknown user"

        content += """
					</UL>
				
					<!-- moved form down here on Aug. 20, 2010 -->
					<form name="curr_user_form" style="display:none" method="post" action="user_request_handler.py">"
					"""

        content += (
            '<INPUT type="hidden" ID="curr_username_hidden" NAME="curr_username" VALUE="'
            + currUser.getFullName()
            + '">'
        )

        content += (
            '<INPUT TYPE="hidden" id="curr_user_hidden" name="view_user" VALUE="' + ` currUser.getUserID() ` + '">'
        )

        content += """
					</FORM>
				
					<div class="login">
					"""

        content += self.printLoginBlock()
        content += """
					</div>
				</div>
			</div>
			"""

        return content
예제 #23
0
    def addUser(self, form):

        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname
        mail_server = self.__mail_server  # August 19, 2011

        mail_programmer = self.__mail_programmer  # July 30, 2010
        mail_biologist = self.__mail_biologist
        mail_admin = self.__mail_admin

        #print "Content-type:text/html"		# TEMPORARY, REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
        #print					# DITTO
        #print `form`

        uHandler = UserHandler(db, cursor)
        lHandler = LabHandler(db, cursor)
        pHandler = ProjectDatabaseHandler(db, cursor)

        ucMapper = UserCategoryMapper(db, cursor)
        category_Name_ID_Map = ucMapper.mapCategoryNameToID()

        # Get form values
        labID = int(form.getvalue("labs"))
        username = form.getvalue("username")

        firstName = form.getvalue("firstName")
        lastName = form.getvalue("lastName")
        description = firstName + " " + lastName

        to_email = form.getvalue("email")

        from_email = mail_admin

        # Change July 30, 2010 - random password generator
        #passwd = form.getvalue("password")

        chars = string.letters + string.digits
        passwd = ""

        for i in range(10):
            passwd += choice(chars)

        # System access level: Lab default or override?
        #if form.getvalue("privChoiceRadio") == 'override':
        accessLevel = category_Name_ID_Map[form.getvalue(
            "system_access_level")]
        #else:
        #accessLevel = lHandler.findDefaultAccessLevel(labID)

        newProps = {}

        try:
            # Insert User information
            userID = uHandler.insertUser(username, firstName, lastName,
                                         description, accessLevel, to_email,
                                         passwd, labID)
            #newUser = uHandler.getUserByID(userID)
            tmpLab = lHandler.findLabByID(labID)
            #print tmpLab.getName()

            # Insert Project info
            # Sept. 11/07: Differentiate between user categories Reader and Writer - different field names
            if form.has_key("userProjectsReadonly"):
                # list of IDs
                readonlyProjects = utils.unique(
                    form.getlist("userProjectsReadonly"))
                #print `readonlyProjects`
                pHandler.insertMemberProjects(userID, readonlyProjects,
                                              'Reader')

            elif form.has_key("userProjectsReadonlyWrite"):
                # list of IDs
                readonlyProjects = utils.unique(
                    form.getlist("userProjectsReadonlyWrite"))
                #print `readonlyProjects`
                pHandler.insertMemberProjects(userID, readonlyProjects,
                                              'Reader')

            # Write projects exist only for Writers
            if form.has_key("userProjectsWrite"):
                writeProjects = utils.unique(form.getlist("userProjectsWrite"))
                pHandler.insertMemberProjects(userID, writeProjects, 'Writer')

            # don't assign projects to a User instance - will retrieve them from db in output function
            newUser = User(userID, username, firstName, lastName,
                           description, tmpLab,
                           form.getvalue("system_access_level"), to_email,
                           passwd, [], [])

            email_subject = "OpenFreezer User Account"

            msg = email.MIMEMultipart.MIMEMultipart('alternative')

            msg['Subject'] = email_subject
            msg['To'] = to_email

            msgText = "Hi " + firstName + ",<BR><BR>An OpenFreezer account has been created for you.&nbsp;&nbsp;Your access level is " + form.getvalue(
                "system_access_level") + ", so you can "

            if form.getvalue("system_access_level") == 'Reader':
                msgText += "search for clones.&nbsp;&nbsp;If you wish to add/modify reagents or create projects, please contact the administrator to upgrade your access level.<BR>"

            elif form.getvalue("system_access_level") == 'Writer':
                msgText += "search, add, and modify reagents.&nbsp;&nbsp;If you wish to create projects, please contact the administrator to upgrade your access level.<BR>"

            elif form.getvalue("system_access_level") == 'Creator':
                msgText += "search for clones, add and modify reagents, as well as create your own projects.<BR>"

            #####################################################
            # CHANGE TEXT AS NEEDED
            #####################################################

            msgText += "<BR>The URL to access the system is <a href='" + hostname + "'>" + hostname + "</a>.&nbsp;&nbsp;Your username is <b>" + username + "</b>, and your temporary password is <b>" + passwd + "</b>.&nbsp;&nbsp;Please <u>change the temporary password as soon as you log into the website</u> - you can do it through the 'Change your password' link under the 'User Management' menu section.<BR><BR>Please refer to http://openfreezer.org for additional support.<BR><BR>Sincerely,<BR>OpenFreezer  support team.<BR><BR><span style='font-family:Courier; font-size:10pt;'><HR>This is an automatically generated e-mail message.&nbsp;&nbsp;Please do not reply to this e-mail.&nbsp;&nbsp;All questions should be directed to your local administrator.</span>"

            msgText = email.MIMEText.MIMEText(msgText, 'html')
            msg.attach(msgText)

            server = smtplib.SMTP(mail_server)
            server.set_debuglevel(1)

            server.sendmail(from_email, [to_email], msg.as_string())
            server.quit()

            self.printUserInfo('view', newUser)

        except DeletedUserException:

            # Without asking too many questions, reactivate the deleted user and overwrite his/her attributes with the form input values
            userID = uHandler.findUserIDByUsername(username)

            newProps["firstname"] = firstName
            newProps["lastname"] = lastName
            newProps["description"] = description
            newProps["email"] = email
            newProps["status"] = "ACTIVE"
            newProps["password"] = passwd

            # Insert new database values and create new object
            uHandler.updateUserProperties(userID, newProps)  # database update
            newUser = uHandler.getUserByID(userID)

            # Insert Project info
            readProjects = []
            writeProjects = []

            if form.has_key("userProjectsReadonly"):
                # list of IDs
                readonlyProjects = form.getlist("userProjectsReadonly")

                for r in readonlyProjects:
                    pHandler.addProjectMember(r, userID, 'Reader')

                    #tmpReadProject = pHandler.findPacket(r)
                    #readProjects.append(tmpReadProject)
                    #newUser.addProject(tmpReadProject, 'read')

            if form.has_key("userProjectsWrite"):
                writeProjects = form.getlist("userProjectsWrite")

                for w in writeProjects:
                    pHandler.addProjectMember(w, userID, 'Writer')

                    #tmpWriteProject = pHandler.findPacket(w)
                    #writeProjects.append(tmpWriteProject)
                    #newUser.addProject(tmpWriteProject, 'write')

            #newUser.setReadProjects(readProjects)
            #newUser.setWriteProjects(writeProjects)

            self.printUserInfo('view', newUser)
            #utils.redirect(hostname + "User.php?View=3&fd=" + filename)

        except DuplicateUsernameException:

            # return to the view with input values and error message
            # Need to construct a dummy User instance to save form values for error output on the next page (otherwise they're lost as soon as Submit is pressed and creation view is exited)
            newLab = lHandler.findLabByID(labID)
            newUser = User(0, username, firstName, lastName, description,
                           newLab, "", email, passwd)

            self.printUserInfo('create', newUser)