aboutsummaryrefslogtreecommitdiff
path: root/web/webqtl/misc
diff options
context:
space:
mode:
Diffstat (limited to 'web/webqtl/misc')
-rwxr-xr-xweb/webqtl/misc/__init__.py0
-rwxr-xr-xweb/webqtl/misc/editHtmlPage.py129
-rwxr-xr-xweb/webqtl/misc/uploadFilePage.py137
3 files changed, 266 insertions, 0 deletions
diff --git a/web/webqtl/misc/__init__.py b/web/webqtl/misc/__init__.py
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/web/webqtl/misc/__init__.py
diff --git a/web/webqtl/misc/editHtmlPage.py b/web/webqtl/misc/editHtmlPage.py
new file mode 100755
index 00000000..68595b83
--- /dev/null
+++ b/web/webqtl/misc/editHtmlPage.py
@@ -0,0 +1,129 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+import string
+import os
+import urlparse
+
+from htmlgen import HTMLgen2 as HT
+
+from base.templatePage import templatePage
+from base import webqtlConfig
+from utility import webqtlUtil
+
+
+#########################################
+# Edit HTML Page
+#########################################
+
+class editHtmlPage(templatePage):
+ htmlPath = webqtlConfig.ChangableHtmlPath
+
+ def __init__(self, fd):
+
+ templatePage.__init__(self, fd)
+
+ self.templateInclude = 1
+ self.dict['title'] = "Editing HTML"
+
+ if not self.updMysql():
+ return
+
+ if webqtlConfig.USERDICT[self.privilege] >= webqtlConfig.USERDICT['user']:
+ pass
+ else:
+ heading = "Editing HTML"
+ detail = ["You don't have the permission to modify this file"]
+ self.error(heading=heading,detail=detail,error="Error")
+ return
+
+ path = fd.formdata.getvalue('path')
+ preview = fd.formdata.getvalue('preview')
+ newHtmlCode = fd.formdata.getvalue('htmlSrc')
+ if newHtmlCode:
+ #newHtmlCode = string.replace(newHtmlCode, "&image", "&image")
+ newHtmlCode = string.replace(newHtmlCode,"&", "&")
+ if path and preview:
+ #preview
+ self.templateInclude = 0
+ #print newHtmlCode
+ self.debug = newHtmlCode
+ elif path:
+ #edit result
+ fileName = self.htmlPath + path
+ newfileName = fileName +'.old'
+ os.system("/bin/cp -f %s %s" % (fileName, newfileName))
+ fp = open(fileName, 'wb')
+ fp.write(newHtmlCode)
+ fp.close()
+ #print "chown qyh %s" % fileName
+ TD_LR = HT.TD(valign="top",colspan=2,bgcolor="#eeeeee", height=200)
+ mainTitle = HT.Paragraph("Edit HTML", Class="title")
+ url = HT.Href(text = "page", url =path, Class = "normal")
+ intro = HT.Blockquote("This ",url, " has been succesfully modified. ")
+ TD_LR.append(mainTitle, intro)
+ self.dict['body'] = TD_LR
+ #elif os.environ.has_key('HTTP_REFERER'):
+ elif fd.refURL:
+ #retrieve file to be edited
+ #refURL = os.environ['HTTP_REFERER']
+ addressing_scheme, network_location, path, parameters, query, fragment_identifier = urlparse.urlparse(fd.refURL)
+ if path[-1] == "/":
+ path += 'index.html'
+
+ fileName = self.htmlPath + path
+ try:
+ fp = open(fileName,'rb')
+ except:
+ fp = open(os.path.join(self.htmlPath, 'temp.html'),'rb')
+ htmlCode = fp.read()
+ #htmlCode = string.replace(htmlCode, "&nbsp","&nbsp")
+ htmlCode = string.replace(htmlCode, "&","&")
+ fp.close()
+ form = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), name='editHtml',submit=HT.Input(type='hidden'))
+ inputBox = HT.Textarea(name='htmlSrc', cols="100", rows=30,text=htmlCode)
+
+ hddn = {'FormID':'editHtml', 'path':path, 'preview':''}
+ for key in hddn.keys():
+ form.append(HT.Input(name=key, value=hddn[key], type='hidden'))
+ previewButton = HT.Input(type='button',name='previewhtml', value='Preview',Class="button", onClick= "editHTML(this.form, 'preview');")
+ submitButton = HT.Input(type='button',name='submitchange', value='Submit Change',Class="button", onClick= "editHTML(this.form, 'submit');")
+ resetButton = HT.Input(type='reset',Class="button")
+ form.append(HT.Center(inputBox, HT.P(), previewButton, submitButton, resetButton))
+
+ TD_LR = HT.TD(valign="top",colspan=2,bgcolor="#eeeeee")
+ mainTitle = HT.Paragraph("Edit HTML", Class="title")
+ intro = HT.Blockquote("You may edit the HTML source code in the editbox below, or you can copy the content of the editbox to your favorite HTML editor. ")
+ imgUpload = HT.Href(url="javascript:openNewWin('/upload.html', 'menubar=0,toolbar=0,location=0,resizable=0,status=1,scrollbars=1,height=400, width=600');", text="here", Class="fs14")
+ intro2 = HT.Blockquote("Click ", imgUpload, " to upload Images. ")
+ TD_LR.append(mainTitle, intro, intro2, HT.Center(form))
+ self.dict['body'] = TD_LR
+ else:
+ heading = "Editing HTML"
+ detail = ["Error occured while trying to edit the html file."]
+ self.error(heading=heading,detail=detail,error="Error")
+ return
+
diff --git a/web/webqtl/misc/uploadFilePage.py b/web/webqtl/misc/uploadFilePage.py
new file mode 100755
index 00000000..da679910
--- /dev/null
+++ b/web/webqtl/misc/uploadFilePage.py
@@ -0,0 +1,137 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+import os
+import string
+
+from htmlgen import HTMLgen2 as HT
+
+from base.templatePage import templatePage
+from base import webqtlConfig
+from utility import webqtlUtil
+
+#########################################
+# Upload File Page
+#########################################
+
+class uploadFilePage(templatePage):
+
+ uploadPath = webqtlConfig.UPLOADPATH
+
+ def __init__(self, fd, formdata, cookies):
+
+ templatePage.__init__(self, fd)
+
+ if not self.openMysql():
+ return
+
+ if webqtlConfig.USERDICT[self.privilege] >= webqtlConfig.USERDICT['user']:
+ pass
+ else:
+ heading = "Upload File"
+ detail = ["You don't have the permission to upload file to the server."]
+ self.error(heading=heading,detail=detail)
+ return
+
+ self.cursor.close()
+
+ file1 = self.save_uploaded_file (formdata, 'imgName1')
+ file2 = self.save_uploaded_file (formdata, 'imgName2')
+ file3 = self.save_uploaded_file (formdata, 'imgName3')
+ file4 = self.save_uploaded_file (formdata, 'imgName4')
+ file5 = self.save_uploaded_file (formdata, 'imgName5')
+
+ i = 0
+ uploaded = []
+
+ for filename in (file1, file2, file3, file4, file5):
+ if filename:
+ i += 1
+ uploaded.append(filename)
+
+ if i == 0:
+ heading = "Upload File"
+ detail = ["No file was selected, no file uploaded."]
+ self.error(heading=heading,detail=detail)
+ return
+ else:
+ TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee')
+
+ imgTbl = HT.TableLite(border=0, width = "90%",cellspacing=2, cellpadding=2, align="Center")
+ imgTbl.append(HT.TR(HT.TD("Thumbnail", width="%30", align='center',Class="colorBlue"),
+ HT.TD("URL", width="%60",Class="colorBlue", align='center')))
+ for item in uploaded:
+ img = HT.Image("/images/upload/" + item, border = 0, width=80)
+
+ #url = "%s/images/upload/" % webqtlConfig.PORTADDR + item
+ #url = HT.Href(text=url, url = url, Class='normalsize', target="_blank")
+ url2 = "/images/upload/" + item
+ url2 = HT.Href(text=url2, url = url2, Class='normalsize', target="_blank")
+ imgTbl.append(HT.TR(HT.TD(img, width="%30", align='center',Class="colorWhite"),
+ #HT.TD(url, HT.BR(), 'OR', HT.BR(), url2, width="%60",Class="colorWhite", align='center')))
+ HT.TD(url2, width="%60",Class="colorWhite", align='center')))
+
+ intro = HT.Paragraph('A total of %d files are uploaded' % i)
+ TD_LR.append( HT.Center(intro) )
+
+ TD_LR.append( imgTbl )
+
+ self.dict['body'] = str(TD_LR)
+
+ def save_uploaded_file(self, form, form_field, upload_dir=""):
+ if not upload_dir:
+ upload_dir = self.uploadPath
+ if not form.has_key(form_field):
+ return None
+ fileitem = form[form_field]
+
+ if not fileitem.filename or not fileitem.file:
+ return None
+
+ seqs = [""] + range(200)
+ try:
+ newfileName = string.split(fileitem.filename, ".")
+ for seq in seqs:
+ newfileName2 = newfileName[:]
+ if seq != "":
+ newfileName2[-2] = "%s-%s" % (newfileName2[-2], seq)
+ fileExist = glob.glob(os.path.join(upload_dir, string.join(newfileName2, ".")))
+ if not fileExist:
+ break
+ except:
+ pass
+
+ newfileName = string.join(newfileName2, ".")
+ #print [newfileName, os.path.join(upload_dir, newfileName)]
+ #return
+
+ fout = file (os.path.join(upload_dir, newfileName), 'wb')
+ while 1:
+ chunk = fileitem.file.read(100000)
+ if not chunk: break
+ fout.write (chunk)
+ fout.close()
+ return newfileName