def show_adminMenu(self, values=None, message=''): page = read_file('adminmenu.html') if values is None: values = {'%USERNAME%' : '', '%FULLNAME%' : '', '%EMAIL%' : '', '%TELEPHONE%' : '', '%USER%' :'', '%SUPERUSER%' : 'checked="checked"' } page = page.replace('%MESSAGE%', message) page = page.replace('%INSTSELECT%', self.create_select()) page = page.replace('%INSTUSERLIST%', self.list_usersByInst()) page = page.replace('%INSTSELECTOPTIONS%', self.get_institutions()) page = page.replace('%DOCSTORESELECT%', self.get_docStoreSelect()) page = multiReplace(page, values) return page
def handle(self, req): form = FieldStorage(req, True) tmpl = unicode(read_file(self.baseTemplatePath)) title = ' :: '.join(self.htmlTitle) navbar = ' '.join(self.htmlNav) replaceAll = { "%TITLE%": title, "%NAVBAR%": navbar, "%USERNAME%": session.user.username, "%REALNAME%": session.user.realName } tmpl = multiReplace(tmpl, replaceAll) path = req.uri[1:] path = path[path.rfind('/') + 1:] content = None operation = form.get('operation', None) if path.endswith('.js'): self.send_response(read_file(abspath('../js/{0}'.format(path))), req, content_type='text/javascript', code=200 ) return apache.OK elif path == 'users.html': if (operation): if (operation == 'findcontacts'): content = self.get_contactDetails(form) self.send_xml(content, req) return else: if (operation == 'adduser'): content = self.add_user(form) elif (operation == 'addinstitution'): content = self.add_inst(form) elif (operation == 'editinstitution'): content = self.edit_inst(form) elif (operation == 'deleteinst'): content = self.delete_inst(form) elif (operation == 'deleteuser'): content = self.delete_user(form) elif operation in ['edit', 'edituser']: content = self.edit_user(form) else: content = self.show_adminMenu() else: content = self.show_adminMenu() elif path == 'admin': # redirect to make sure later relative links work correctly redirect(req, 'admin/', permanent=False, # TODO: make me True text=("To prevent URL collisions caused by internal " "relative, this service must be accessed at " "admin/" ) ) return else: content = self.show_adminMenu() content = tmpl.replace('%CONTENT%', content) # send the display self.send_html(content, req)
def delete_inst(self, form): global instStore, rebuild instid = form.get('inst', None) cancel = form.get('cancel', None) confirm = form.get('confirm', None) passwd = form.get('passwd', None) #check again to see that this inst has no users. sqlQ = ("SELECT hubAuthStore FROM hubAuthStore_linkauthinst WHERE " "institutionid=%s" ) result = userStore._query(sqlQ, (instid,)) if len(result): return self.show_adminMenu( None, '<p class="error">Unable to delete institution - ' 'there are still {0} users in this institution which must be ' 'deleted first.</p>'.format(len(result)) ) if (confirm == 'true'): sqlQ = ("SELECT editingstore FROM editingstore_linkrecinst WHERE " "institutionid=%s" ) result = userStore._query(sqlQ, (instid,)) if len(result): fileinfo = ('<b>This institution still has draft files ' 'linked to it - if you delete this institution ' 'the draft files linked to it will also be ' 'deleted</b>' ) output = ['<div id="single"><h3 class="bar">Delete ' 'Institution Confirmation.</h3>', multiReplace(read_file('deleteinst.html'), dict(['%INSTID%', instid, '%%%FILEINFO%%%', fileinfo ]) ), '</div>' ] else: output = ['<div id="single">', '<h3 class="bar">', 'Delete Institution Confirmation.', '</h3>', multiReplace(read_file('deleteinst.html'), dict([('%INSTID%', instid), ('%%%FILEINFO%%%', '') ]) ), '</div>' ] return ''.join(output) elif (cancel == 'Cancel'): return self.show_adminMenu() else: if (passwd and session.user.check_password(session, passwd)): try: instStore.delete_record(session, instid) except: return self.show_adminMenu( None, '<p class="error">Unable to delete institution - ' 'user does not exist.</p>' ) else: sqlQ = ("SELECT editingstore FROM " "editingstore_linkrecinst WHERE institutionid=%s" ) result = userStore._query(sqlQ, (instid,)) for r in result: recid = r['editingstore'] try: editStore.delete_record(session, recid) except: pass rebuild = True return self.show_adminMenu() else : return self.show_adminMenu( None, '<p class="error">Unable to delete institution - ' 'incorrect password.</p>' )
def show_userEdit(self, values, message=''): page = read_file('users.html') values['%message%'] = message return multiReplace(page, values)