v0.5.0 update

Global variables removed from JS file
Plugins system evolved, now including setInterval
Seperate CodeMirror instances per tab
backupOpenFiles plugin created
Minor fixes & improvements
This commit is contained in:
Matt Pass
2012-01-20 09:55:29 +00:00
commit 972a3434bc
77 changed files with 8053 additions and 0 deletions

19
CodeMirror-2.2/LICENSE Normal file
View File

@@ -0,0 +1,19 @@
Copyright (C) 2011 by Marijn Haverbeke <marijnh@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

6
CodeMirror-2.2/README.md Normal file
View File

@@ -0,0 +1,6 @@
# CodeMirror 2
CodeMirror 2 is a rewrite of [CodeMirror
1](http://github.com/marijnh/CodeMirror). The docs live
[here](http://codemirror.net/doc/manual.html), and the project page is
[http://codemirror.net/](http://codemirror.net/).

View File

@@ -0,0 +1,29 @@
// TODO number prefixes
(function() {
// Really primitive kill-ring implementation.
var killRing = [];
function addToRing(str) {
killRing.push(str);
if (killRing.length > 50) killRing.shift();
}
function getFromRing() { return killRing[killRing.length - 1] || ""; }
function popFromRing() { if (killRing.length > 1) killRing.pop(); return getFromRing(); }
CodeMirror.keyMap.emacs = {
"Ctrl-X": function(cm) {cm.setOption("keyMap", "emacs-Ctrl-X");},
"Ctrl-W": function(cm) {addToRing(cm.getSelection()); cm.replaceSelection("");},
"Ctrl-Alt-W": function(cm) {addToRing(cm.getSelection()); cm.replaceSelection("");},
"Alt-W": function(cm) {addToRing(cm.getSelection());},
"Ctrl-Y": function(cm) {cm.replaceSelection(getFromRing());},
"Alt-Y": function(cm) {cm.replaceSelection(popFromRing());},
"Ctrl-/": "undo", "Shift-Ctrl--": "undo", "Shift-Alt-,": "goDocStart", "Shift-Alt-.": "goDocEnd",
"Ctrl-S": "findNext", "Ctrl-R": "findPrev", "Ctrl-G": "clearSearch", "Shift-Alt-5": "replace",
"Ctrl-Z": "undo", "Cmd-Z": "undo",
fallthrough: ["basic", "emacsy"]
};
CodeMirror.keyMap["emacs-Ctrl-X"] = {
"Ctrl-S": "save", "Ctrl-W": "save", "S": "saveAll", "F": "open", "U": "undo", "K": "close",
auto: "emacs", catchall: function(cm) {/*ignore*/}
};
})();

View File

@@ -0,0 +1,76 @@
(function() {
var count = "";
function pushCountDigit(digit) { return function(cm) {count += digit;} }
function popCount() { var i = parseInt(count); count = ""; return i || 1; }
function countTimes(func) {
if (typeof func == "string") func = CodeMirror.commands[func];
return function(cm) { for (var i = 0, c = popCount(); i < c; ++i) func(cm); }
}
function iterObj(o, f) {
for (var prop in o) if (o.hasOwnProperty(prop)) f(prop, o[prop]);
}
var word = [/\w/, /[^\w\s]/], bigWord = [/\S/];
function findWord(line, pos, dir, regexps) {
var stop = 0, next = -1;
if (dir > 0) { stop = line.length; next = 0; }
var start = stop, end = stop;
// Find bounds of next one.
outer: for (; pos != stop; pos += dir) {
for (var i = 0; i < regexps.length; ++i) {
if (regexps[i].test(line.charAt(pos + next))) {
start = pos;
for (; pos != stop; pos += dir) {
if (!regexps[i].test(line.charAt(pos + next))) break;
}
end = pos;
break outer;
}
}
}
return {from: Math.min(start, end), to: Math.max(start, end)};
}
function moveToWord(cm, regexps, dir, where) {
var cur = cm.getCursor(), ch = cur.ch, line = cm.getLine(cur.line), word;
while (true) {
word = findWord(line, ch, dir, regexps);
ch = word[where == "end" ? "to" : "from"];
if (ch == cur.ch && word.from != word.to) ch = word[dir < 0 ? "from" : "to"];
else break;
}
cm.setCursor(cur.line, word[where == "end" ? "to" : "from"], true);
}
var map = CodeMirror.keyMap.vim = {
"0": function(cm) {count.length > 0 ? pushCountDigit("0")(cm) : CodeMirror.commands.goLineStart(cm);},
"I": function(cm) {popCount(); cm.setOption("keyMap", "vim-insert");},
"G": function(cm) {cm.setOption("keyMap", "vim-prefix-g");},
catchall: function(cm) {/*ignore*/}
};
// Add bindings for number keys
for (var i = 1; i < 10; ++i) map[i] = pushCountDigit(i);
// Add bindings that are influenced by number keys
iterObj({"H": "goColumnLeft", "L": "goColumnRight", "J": "goLineDown", "K": "goLineUp",
"Left": "goColumnLeft", "Right": "goColumnRight", "Down": "goLineDown", "Up": "goLineUp",
"Backspace": "goCharLeft", "Space": "goCharRight",
"B": function(cm) {moveToWord(cm, word, -1, "end");},
"E": function(cm) {moveToWord(cm, word, 1, "end");},
"W": function(cm) {moveToWord(cm, word, 1, "start");},
"Shift-B": function(cm) {moveToWord(cm, bigWord, -1, "end");},
"Shift-E": function(cm) {moveToWord(cm, bigWord, 1, "end");},
"Shift-W": function(cm) {moveToWord(cm, bigWord, 1, "start");},
"U": "undo", "Ctrl-R": "redo", "Shift-4": "goLineEnd"},
function(key, cmd) { map[key] = countTimes(cmd); });
CodeMirror.keyMap["vim-prefix-g"] = {
"E": countTimes(function(cm) { moveToWord(cm, word, -1, "start");}),
"Shift-E": countTimes(function(cm) { moveToWord(cm, bigWord, -1, "start");}),
auto: "vim", catchall: function(cm) {/*ignore*/}
};
CodeMirror.keyMap["vim-insert"] = {
"Esc": function(cm) {cm.setOption("keyMap", "vim");},
fallthrough: ["default"]
};
})();

View File

@@ -0,0 +1,104 @@
.CodeMirror {
line-height: 1em;
font-family: monospace;
}
.CodeMirror-scroll {
overflow: auto;
height: 300px;
/* This is needed to prevent an IE[67] bug where the scrolled content
is visible outside of the scrolling box. */
position: relative;
}
.CodeMirror-gutter {
position: absolute; left: 0; top: 0;
z-index: 10;
background-color: #f7f7f7;
border-right: 1px solid #eee;
min-width: 2em;
height: 100%;
}
.CodeMirror-gutter-text {
color: #aaa;
text-align: right;
padding: .4em .2em .4em .4em;
white-space: pre !important;
}
.CodeMirror-lines {
padding: .4em;
}
.CodeMirror pre {
-moz-border-radius: 0;
-webkit-border-radius: 0;
-o-border-radius: 0;
border-radius: 0;
border-width: 0; margin: 0; padding: 0; background: transparent;
font-family: inherit;
font-size: inherit;
padding: 0; margin: 0;
white-space: pre;
word-wrap: normal;
}
.CodeMirror-wrap pre {
word-wrap: break-word;
white-space: pre-wrap;
}
.CodeMirror-wrap .CodeMirror-scroll {
overflow-x: hidden;
}
.CodeMirror textarea {
outline: none !important;
}
.CodeMirror pre.CodeMirror-cursor {
z-index: 10;
position: absolute;
visibility: hidden;
border-left: 1px solid black;
}
.CodeMirror-focused pre.CodeMirror-cursor {
visibility: visible;
}
span.CodeMirror-selected { background: #d9d9d9; }
.CodeMirror-focused span.CodeMirror-selected { background: #d2dcf8; }
.CodeMirror-searching {background: #ffa;}
/* Default theme */
.cm-s-default span.cm-keyword {color: #708;}
.cm-s-default span.cm-atom {color: #219;}
.cm-s-default span.cm-number {color: #164;}
.cm-s-default span.cm-def {color: #00f;}
.cm-s-default span.cm-variable {color: black;}
.cm-s-default span.cm-variable-2 {color: #05a;}
.cm-s-default span.cm-variable-3 {color: #085;}
.cm-s-default span.cm-property {color: black;}
.cm-s-default span.cm-operator {color: black;}
.cm-s-default span.cm-comment {color: #a50;}
.cm-s-default span.cm-string {color: #a11;}
.cm-s-default span.cm-string-2 {color: #f50;}
.cm-s-default span.cm-meta {color: #555;}
.cm-s-default span.cm-error {color: #f00;}
.cm-s-default span.cm-qualifier {color: #555;}
.cm-s-default span.cm-builtin {color: #30a;}
.cm-s-default span.cm-bracket {color: #cc7;}
.cm-s-default span.cm-tag {color: #170;}
.cm-s-default span.cm-attribute {color: #00c;}
.cm-s-default span.cm-header {color: #a0a;}
.cm-s-default span.cm-quote {color: #090;}
.cm-s-default span.cm-hr {color: #999;}
.cm-s-default span.cm-link {color: #00c;}
span.cm-header, span.cm-strong {font-weight: bold;}
span.cm-em {font-style: italic;}
span.cm-emstrong {font-style: italic; font-weight: bold;}
span.cm-link {text-decoration: underline;}
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,23 @@
.CodeMirror-dialog {
position: relative;
}
.CodeMirror-dialog > div {
position: absolute;
top: 0; left: 0; right: 0;
background: white;
border-bottom: 1px solid #eee;
z-index: 15;
padding: .1em .8em;
overflow: hidden;
color: #333;
}
.CodeMirror-dialog input {
border: none;
outline: none;
background: transparent;
width: 20em;
color: inherit;
font-family: monospace;
}

View File

@@ -0,0 +1,63 @@
// Open simple dialogs on top of an editor. Relies on dialog.css.
(function() {
function dialogDiv(cm, template) {
var wrap = cm.getWrapperElement();
var dialog = wrap.insertBefore(document.createElement("div"), wrap.firstChild);
dialog.className = "CodeMirror-dialog";
dialog.innerHTML = '<div>' + template + '</div>';
return dialog;
}
CodeMirror.defineExtension("openDialog", function(template, callback) {
var dialog = dialogDiv(this, template);
var closed = false, me = this;
function close() {
if (closed) return;
closed = true;
dialog.parentNode.removeChild(dialog);
}
var inp = dialog.getElementsByTagName("input")[0];
if (inp) {
CodeMirror.connect(inp, "keydown", function(e) {
if (e.keyCode == 13 || e.keyCode == 27) {
CodeMirror.e_stop(e);
close();
me.focus();
if (e.keyCode == 13) callback(inp.value);
}
});
inp.focus();
CodeMirror.connect(inp, "blur", close);
}
return close;
});
CodeMirror.defineExtension("openConfirm", function(template, callbacks) {
var dialog = dialogDiv(this, template);
var buttons = dialog.getElementsByTagName("button");
var closed = false, me = this, blurring = 1;
function close() {
if (closed) return;
closed = true;
dialog.parentNode.removeChild(dialog);
me.focus();
}
buttons[0].focus();
for (var i = 0; i < buttons.length; ++i) {
var b = buttons[i];
(function(callback) {
CodeMirror.connect(b, "click", function(e) {
CodeMirror.e_preventDefault(e);
close();
if (callback) callback(me);
});
})(callbacks[i]);
CodeMirror.connect(b, "blur", function() {
--blurring;
setTimeout(function() { if (blurring <= 0) close(); }, 200);
});
CodeMirror.connect(b, "focus", function() { ++blurring; });
}
});
})();

View File

@@ -0,0 +1,66 @@
CodeMirror.braceRangeFinder = function(cm, line) {
var lineText = cm.getLine(line);
var startChar = lineText.lastIndexOf("{");
if (startChar < 0 || lineText.lastIndexOf("}") > startChar) return;
var tokenType = cm.getTokenAt({line: line, ch: startChar}).className;
var count = 1, lastLine = cm.lineCount(), end;
outer: for (var i = line + 1; i < lastLine; ++i) {
var text = cm.getLine(i), pos = 0;
for (;;) {
var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (cm.getTokenAt({line: i, ch: pos + 1}).className == tokenType) {
if (pos == nextOpen) ++count;
else if (!--count) { end = i; break outer; }
}
++pos;
}
}
if (end == null || end == line + 1) return;
return end;
};
CodeMirror.newFoldFunction = function(rangeFinder, markText) {
var folded = [];
if (markText == null) markText = '<div style="position: absolute; left: 2px; color:#600">&#x25bc;</div>%N%';
function isFolded(cm, n) {
for (var i = 0; i < folded.length; ++i) {
var start = cm.lineInfo(folded[i].start);
if (!start) folded.splice(i--, 1);
else if (start.line == n) return {pos: i, region: folded[i]};
}
}
function expand(cm, region) {
cm.clearMarker(region.start);
for (var i = 0; i < region.hidden.length; ++i)
cm.showLine(region.hidden[i]);
}
return function(cm, line) {
cm.operation(function() {
var known = isFolded(cm, line);
if (known) {
folded.splice(known.pos, 1);
expand(cm, known.region);
} else {
var end = rangeFinder(cm, line);
if (end == null) return;
var hidden = [];
for (var i = line + 1; i < end; ++i) {
var handle = cm.hideLine(i);
if (handle) hidden.push(handle);
}
var first = cm.setMarker(line, markText);
var region = {start: first, hidden: hidden};
cm.onDeleteLine(first, function() { expand(cm, region); });
folded.push(region);
}
});
};
};

View File

@@ -0,0 +1,291 @@
// ============== Formatting extensions ============================
// A common storage for all mode-specific formatting features
if (!CodeMirror.modeExtensions) CodeMirror.modeExtensions = {};
// Returns the extension of the editor's current mode
CodeMirror.defineExtension("getModeExt", function () {
return CodeMirror.modeExtensions[this.getOption("mode")];
});
// If the current mode is 'htmlmixed', returns the extension of a mode located at
// the specified position (can be htmlmixed, css or javascript). Otherwise, simply
// returns the extension of the editor's current mode.
CodeMirror.defineExtension("getModeExtAtPos", function (pos) {
var token = this.getTokenAt(pos);
if (token && token.state && token.state.mode)
return CodeMirror.modeExtensions[token.state.mode == "html" ? "htmlmixed" : token.state.mode];
else
return this.getModeExt();
});
// Comment/uncomment the specified range
CodeMirror.defineExtension("commentRange", function (isComment, from, to) {
var curMode = this.getModeExtAtPos(this.getCursor());
if (isComment) { // Comment range
var commentedText = this.getRange(from, to);
this.replaceRange(curMode.commentStart + this.getRange(from, to) + curMode.commentEnd
, from, to);
if (from.line == to.line && from.ch == to.ch) { // An empty comment inserted - put cursor inside
this.setCursor(from.line, from.ch + curMode.commentStart.length);
}
}
else { // Uncomment range
var selText = this.getRange(from, to);
var startIndex = selText.indexOf(curMode.commentStart);
var endIndex = selText.lastIndexOf(curMode.commentEnd);
if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) {
// Take string till comment start
selText = selText.substr(0, startIndex)
// From comment start till comment end
+ selText.substring(startIndex + curMode.commentStart.length, endIndex)
// From comment end till string end
+ selText.substr(endIndex + curMode.commentEnd.length);
}
this.replaceRange(selText, from, to);
}
});
// Applies automatic mode-aware indentation to the specified range
CodeMirror.defineExtension("autoIndentRange", function (from, to) {
var cmInstance = this;
this.operation(function () {
for (var i = from.line; i <= to.line; i++) {
cmInstance.indentLine(i);
}
});
});
// Applies automatic formatting to the specified range
CodeMirror.defineExtension("autoFormatRange", function (from, to) {
var absStart = this.indexFromPos(from);
var absEnd = this.indexFromPos(to);
// Insert additional line breaks where necessary according to the
// mode's syntax
var res = this.getModeExt().autoFormatLineBreaks(this.getValue(), absStart, absEnd);
var cmInstance = this;
// Replace and auto-indent the range
this.operation(function () {
cmInstance.replaceRange(res, from, to);
var startLine = cmInstance.posFromIndex(absStart).line;
var endLine = cmInstance.posFromIndex(absStart + res.length).line;
for (var i = startLine; i <= endLine; i++) {
cmInstance.indentLine(i);
}
});
});
// Define extensions for a few modes
CodeMirror.modeExtensions["css"] = {
commentStart: "/*",
commentEnd: "*/",
wordWrapChars: [";", "\\{", "\\}"],
autoFormatLineBreaks: function (text) {
return text.replace(new RegExp("(;|\\{|\\})([^\r\n])", "g"), "$1\n$2");
}
};
CodeMirror.modeExtensions["javascript"] = {
commentStart: "/*",
commentEnd: "*/",
wordWrapChars: [";", "\\{", "\\}"],
getNonBreakableBlocks: function (text) {
var nonBreakableRegexes = [
new RegExp("for\\s*?\\(([\\s\\S]*?)\\)"),
new RegExp("'([\\s\\S]*?)('|$)"),
new RegExp("\"([\\s\\S]*?)(\"|$)"),
new RegExp("//.*([\r\n]|$)")
];
var nonBreakableBlocks = new Array();
for (var i = 0; i < nonBreakableRegexes.length; i++) {
var curPos = 0;
while (curPos < text.length) {
var m = text.substr(curPos).match(nonBreakableRegexes[i]);
if (m != null) {
nonBreakableBlocks.push({
start: curPos + m.index,
end: curPos + m.index + m[0].length
});
curPos += m.index + Math.max(1, m[0].length);
}
else { // No more matches
break;
}
}
}
nonBreakableBlocks.sort(function (a, b) {
return a.start - b.start;
});
return nonBreakableBlocks;
},
autoFormatLineBreaks: function (text) {
var curPos = 0;
var reLinesSplitter = new RegExp("(;|\\{|\\})([^\r\n])", "g");
var nonBreakableBlocks = this.getNonBreakableBlocks(text);
if (nonBreakableBlocks != null) {
var res = "";
for (var i = 0; i < nonBreakableBlocks.length; i++) {
if (nonBreakableBlocks[i].start > curPos) { // Break lines till the block
res += text.substring(curPos, nonBreakableBlocks[i].start).replace(reLinesSplitter, "$1\n$2");
curPos = nonBreakableBlocks[i].start;
}
if (nonBreakableBlocks[i].start <= curPos
&& nonBreakableBlocks[i].end >= curPos) { // Skip non-breakable block
res += text.substring(curPos, nonBreakableBlocks[i].end);
curPos = nonBreakableBlocks[i].end;
}
}
if (curPos < text.length - 1) {
res += text.substr(curPos).replace(reLinesSplitter, "$1\n$2");
}
return res;
}
else {
return text.replace(reLinesSplitter, "$1\n$2");
}
}
};
CodeMirror.modeExtensions["xml"] = {
commentStart: "<!--",
commentEnd: "-->",
wordWrapChars: [">"],
autoFormatLineBreaks: function (text) {
var lines = text.split("\n");
var reProcessedPortion = new RegExp("(^\\s*?<|^[^<]*?)(.+)(>\\s*?$|[^>]*?$)");
var reOpenBrackets = new RegExp("<", "g");
var reCloseBrackets = new RegExp("(>)([^\r\n])", "g");
for (var i = 0; i < lines.length; i++) {
var mToProcess = lines[i].match(reProcessedPortion);
if (mToProcess != null && mToProcess.length > 3) { // The line starts with whitespaces and ends with whitespaces
lines[i] = mToProcess[1]
+ mToProcess[2].replace(reOpenBrackets, "\n$&").replace(reCloseBrackets, "$1\n$2")
+ mToProcess[3];
continue;
}
}
return lines.join("\n");
}
};
CodeMirror.modeExtensions["htmlmixed"] = {
commentStart: "<!--",
commentEnd: "-->",
wordWrapChars: [">", ";", "\\{", "\\}"],
getModeInfos: function (text, absPos) {
var modeInfos = new Array();
modeInfos[0] =
{
pos: 0,
modeExt: CodeMirror.modeExtensions["xml"],
modeName: "xml"
};
var modeMatchers = new Array();
modeMatchers[0] =
{
regex: new RegExp("<style[^>]*>([\\s\\S]*?)(</style[^>]*>|$)", "i"),
modeExt: CodeMirror.modeExtensions["css"],
modeName: "css"
};
modeMatchers[1] =
{
regex: new RegExp("<script[^>]*>([\\s\\S]*?)(</script[^>]*>|$)", "i"),
modeExt: CodeMirror.modeExtensions["javascript"],
modeName: "javascript"
};
var lastCharPos = (typeof (absPos) !== "undefined" ? absPos : text.length - 1);
// Detect modes for the entire text
for (var i = 0; i < modeMatchers.length; i++) {
var curPos = 0;
while (curPos <= lastCharPos) {
var m = text.substr(curPos).match(modeMatchers[i].regex);
if (m != null) {
if (m.length > 1 && m[1].length > 0) {
// Push block begin pos
var blockBegin = curPos + m.index + m[0].indexOf(m[1]);
modeInfos.push(
{
pos: blockBegin,
modeExt: modeMatchers[i].modeExt,
modeName: modeMatchers[i].modeName
});
// Push block end pos
modeInfos.push(
{
pos: blockBegin + m[1].length,
modeExt: modeInfos[0].modeExt,
modeName: modeInfos[0].modeName
});
curPos += m.index + m[0].length;
continue;
}
else {
curPos += m.index + Math.max(m[0].length, 1);
}
}
else { // No more matches
break;
}
}
}
// Sort mode infos
modeInfos.sort(function sortModeInfo(a, b) {
return a.pos - b.pos;
});
return modeInfos;
},
autoFormatLineBreaks: function (text, startPos, endPos) {
var modeInfos = this.getModeInfos(text);
var reBlockStartsWithNewline = new RegExp("^\\s*?\n");
var reBlockEndsWithNewline = new RegExp("\n\\s*?$");
var res = "";
// Use modes info to break lines correspondingly
if (modeInfos.length > 1) { // Deal with multi-mode text
for (var i = 1; i <= modeInfos.length; i++) {
var selStart = modeInfos[i - 1].pos;
var selEnd = (i < modeInfos.length ? modeInfos[i].pos : endPos);
if (selStart >= endPos) { // The block starts later than the needed fragment
break;
}
if (selStart < startPos) {
if (selEnd <= startPos) { // The block starts earlier than the needed fragment
continue;
}
selStart = startPos;
}
if (selEnd > endPos) {
selEnd = endPos;
}
var textPortion = text.substring(selStart, selEnd);
if (modeInfos[i - 1].modeName != "xml") { // Starting a CSS or JavaScript block
if (!reBlockStartsWithNewline.test(textPortion)
&& selStart > 0) { // The block does not start with a line break
textPortion = "\n" + textPortion;
}
if (!reBlockEndsWithNewline.test(textPortion)
&& selEnd < text.length - 1) { // The block does not end with a line break
textPortion += "\n";
}
}
res += modeInfos[i - 1].modeExt.autoFormatLineBreaks(textPortion);
}
}
else { // Single-mode text
res = modeInfos[0].modeExt.autoFormatLineBreaks(text.substring(startPos, endPos));
}
return res;
}
};

View File

@@ -0,0 +1,83 @@
(function () {
function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}
function arrayContains(arr, item) {
if (!Array.prototype.indexOf) {
var i = arr.length;
while (i--) {
if (arr[i] === item) {
return true;
}
}
return false;
}
return arr.indexOf(item) != -1;
}
CodeMirror.javascriptHint = function(editor) {
// Find the token at the cursor
var cur = editor.getCursor(), token = editor.getTokenAt(cur), tprop = token;
// If it's not a 'word-style' token, ignore the token.
if (!/^[\w$_]*$/.test(token.string)) {
token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
className: token.string == "." ? "property" : null};
}
// If it is a property, find out what it is a property of.
while (tprop.className == "property") {
tprop = editor.getTokenAt({line: cur.line, ch: tprop.start});
if (tprop.string != ".") return;
tprop = editor.getTokenAt({line: cur.line, ch: tprop.start});
if (!context) var context = [];
context.push(tprop);
}
return {list: getCompletions(token, context),
from: {line: cur.line, ch: token.start},
to: {line: cur.line, ch: token.end}};
}
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
"toUpperCase toLowerCase split concat match replace search").split(" ");
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
"lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
var funcProps = "prototype apply call bind".split(" ");
var keywords = ("break case catch continue debugger default delete do else false finally for function " +
"if in instanceof new null return switch throw true try typeof var void while with").split(" ");
function getCompletions(token, context) {
var found = [], start = token.string;
function maybeAdd(str) {
if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
}
function gatherCompletions(obj) {
if (typeof obj == "string") forEach(stringProps, maybeAdd);
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
for (var name in obj) maybeAdd(name);
}
if (context) {
// If this is a property, see if it belongs to some object we can
// find in the current environment.
var obj = context.pop(), base;
if (obj.className == "variable")
base = window[obj.string];
else if (obj.className == "string")
base = "";
else if (obj.className == "atom")
base = 1;
while (base != null && context.length)
base = base[context.pop().string];
if (base != null) gatherCompletions(base);
}
else {
// If not, just look in the window object and any local scope
// (reading into JS mode internals to get at the local variables)
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
gatherCompletions(window);
forEach(keywords, maybeAdd);
}
return found;
}
})();

View File

@@ -0,0 +1,51 @@
// Utility function that allows modes to be combined. The mode given
// as the base argument takes care of most of the normal mode
// functionality, but a second (typically simple) mode is used, which
// can override the style of text. Both modes get to parse all of the
// text, but when both assign a non-null style to a piece of code, the
// overlay wins, unless the combine argument was true, in which case
// the styles are combined.
CodeMirror.overlayParser = function(base, overlay, combine) {
return {
startState: function() {
return {
base: CodeMirror.startState(base),
overlay: CodeMirror.startState(overlay),
basePos: 0, baseCur: null,
overlayPos: 0, overlayCur: null
};
},
copyState: function(state) {
return {
base: CodeMirror.copyState(base, state.base),
overlay: CodeMirror.copyState(overlay, state.overlay),
basePos: state.basePos, baseCur: null,
overlayPos: state.overlayPos, overlayCur: null
};
},
token: function(stream, state) {
if (stream.start == state.basePos) {
state.baseCur = base.token(stream, state.base);
state.basePos = stream.pos;
}
if (stream.start == state.overlayPos) {
stream.pos = stream.start;
state.overlayCur = overlay.token(stream, state.overlay);
state.overlayPos = stream.pos;
}
stream.pos = Math.min(state.basePos, state.overlayPos);
if (stream.eol()) state.basePos = state.overlayPos = 0;
if (state.overlayCur == null) return state.baseCur;
if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur;
else return state.overlayCur;
},
indent: function(state, textAfter) {
return base.indent(state.base, textAfter);
},
electricChars: base.electricChars
};
};

View File

@@ -0,0 +1,27 @@
CodeMirror.runMode = function(string, modespec, callback) {
var mode = CodeMirror.getMode({indentUnit: 2}, modespec);
var isNode = callback.nodeType == 1;
if (isNode) {
var node = callback, accum = [];
callback = function(string, style) {
if (string == "\n")
accum.push("<br>");
else if (style)
accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + CodeMirror.htmlEscape(string) + "</span>");
else
accum.push(CodeMirror.htmlEscape(string));
}
}
var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
for (var i = 0, e = lines.length; i < e; ++i) {
if (i) callback("\n");
var stream = new CodeMirror.StringStream(lines[i]);
while (!stream.eol()) {
var style = mode.token(stream, state);
callback(stream.current(), style, i, stream.start);
stream.start = stream.pos;
}
}
if (isNode)
node.innerHTML = accum.join("");
};

View File

@@ -0,0 +1,114 @@
// Define search commands. Depends on dialog.js or another
// implementation of the openDialog method.
// Replace works a little oddly -- it will do the replace on the next
// Ctrl-G (or whatever is bound to findNext) press. You prevent a
// replace by making sure the match is no longer selected when hitting
// Ctrl-G.
(function() {
function SearchState() {
this.posFrom = this.posTo = this.query = null;
this.marked = [];
}
function getSearchState(cm) {
return cm._searchState || (cm._searchState = new SearchState());
}
function dialog(cm, text, shortText, f) {
if (cm.openDialog) cm.openDialog(text, f);
else f(prompt(shortText, ""));
}
function confirmDialog(cm, text, shortText, fs) {
if (cm.openConfirm) cm.openConfirm(text, fs);
else if (confirm(shortText)) fs[0]();
}
function parseQuery(query) {
var isRE = query.match(/^\/(.*)\/$/);
return isRE ? new RegExp(isRE[1]) : query;
}
var queryDialog =
'Search: <input type="text" style="width: 10em"> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
function doSearch(cm, rev) {
var state = getSearchState(cm);
if (state.query) return findNext(cm, rev);
dialog(cm, queryDialog, "Search for:", function(query) {
cm.operation(function() {
if (!query || state.query) return;
state.query = parseQuery(query);
if (cm.lineCount() < 2000) { // This is too expensive on big documents.
for (var cursor = cm.getSearchCursor(query); cursor.findNext();)
state.marked.push(cm.markText(cursor.from(), cursor.to(), "CodeMirror-searching"));
}
state.posFrom = state.posTo = cm.getCursor();
findNext(cm, rev);
});
});
}
function findNext(cm, rev) {cm.operation(function() {
var state = getSearchState(cm);
var cursor = cm.getSearchCursor(state.query, rev ? state.posFrom : state.posTo);
if (!cursor.find(rev)) {
cursor = cm.getSearchCursor(state.query, rev ? {line: cm.lineCount() - 1} : {line: 0, ch: 0});
if (!cursor.find(rev)) return;
}
cm.setSelection(cursor.from(), cursor.to());
state.posFrom = cursor.from(); state.posTo = cursor.to();
})}
function clearSearch(cm) {cm.operation(function() {
var state = getSearchState(cm);
if (!state.query) return;
state.query = null;
for (var i = 0; i < state.marked.length; ++i) state.marked[i].clear();
state.marked.length = 0;
})}
var replaceQueryDialog =
'Replace: <input type="text" style="width: 10em"> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
var replacementQueryDialog = 'With: <input type="text" style="width: 10em">';
var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
function replace(cm, all) {
dialog(cm, replaceQueryDialog, "Replace:", function(query) {
if (!query) return;
query = parseQuery(query);
dialog(cm, replacementQueryDialog, "Replace with:", function(text) {
if (all) {
cm.operation(function() {
for (var cursor = cm.getSearchCursor(query); cursor.findNext();) {
if (typeof query != "string") {
var match = cm.getRange(cursor.from(), cursor.to()).match(query);
cursor.replace(text.replace(/\$(\d)/, function(w, i) {return match[i];}));
} else cursor.replace(text);
}
});
} else {
clearSearch(cm);
var cursor = cm.getSearchCursor(query, cm.getCursor());
function advance() {
var start = cursor.from(), match;
if (!(match = cursor.findNext())) {
cursor = cm.getSearchCursor(query);
if (!(match = cursor.findNext()) ||
(cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
}
cm.setSelection(cursor.from(), cursor.to());
confirmDialog(cm, doReplaceConfirm, "Replace?",
[function() {doReplace(match);}, advance]);
}
function doReplace(match) {
cursor.replace(typeof query == "string" ? text :
text.replace(/\$(\d)/, function(w, i) {return match[i];}));
advance();
}
advance();
}
});
});
}
CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
CodeMirror.commands.findNext = doSearch;
CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
CodeMirror.commands.clearSearch = clearSearch;
CodeMirror.commands.replace = replace;
CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
})();

View File

@@ -0,0 +1,117 @@
(function(){
function SearchCursor(cm, query, pos, caseFold) {
this.atOccurrence = false; this.cm = cm;
if (caseFold == null) caseFold = typeof query == "string" && query == query.toLowerCase();
pos = pos ? cm.clipPos(pos) : {line: 0, ch: 0};
this.pos = {from: pos, to: pos};
// The matches method is filled in based on the type of query.
// It takes a position and a direction, and returns an object
// describing the next occurrence of the query, or null if no
// more matches were found.
if (typeof query != "string") // Regexp match
this.matches = function(reverse, pos) {
if (reverse) {
var line = cm.getLine(pos.line).slice(0, pos.ch), match = line.match(query), start = 0;
while (match) {
var ind = line.indexOf(match[0]);
start += ind;
line = line.slice(ind + 1);
var newmatch = line.match(query);
if (newmatch) match = newmatch;
else break;
start++;
}
}
else {
var line = cm.getLine(pos.line).slice(pos.ch), match = line.match(query),
start = match && pos.ch + line.indexOf(match[0]);
}
if (match)
return {from: {line: pos.line, ch: start},
to: {line: pos.line, ch: start + match[0].length},
match: match};
};
else { // String query
if (caseFold) query = query.toLowerCase();
var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
var target = query.split("\n");
// Different methods for single-line and multi-line queries
if (target.length == 1)
this.matches = function(reverse, pos) {
var line = fold(cm.getLine(pos.line)), len = query.length, match;
if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1)
: (match = line.indexOf(query, pos.ch)) != -1)
return {from: {line: pos.line, ch: match},
to: {line: pos.line, ch: match + len}};
};
else
this.matches = function(reverse, pos) {
var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(cm.getLine(ln));
var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
if (reverse ? offsetA >= pos.ch || offsetA != match.length
: offsetA <= pos.ch || offsetA != line.length - match.length)
return;
for (;;) {
if (reverse ? !ln : ln == cm.lineCount() - 1) return;
line = fold(cm.getLine(ln += reverse ? -1 : 1));
match = target[reverse ? --idx : ++idx];
if (idx > 0 && idx < target.length - 1) {
if (line != match) return;
else continue;
}
var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length);
if (reverse ? offsetB != line.length - match.length : offsetB != match.length)
return;
var start = {line: pos.line, ch: offsetA}, end = {line: ln, ch: offsetB};
return {from: reverse ? end : start, to: reverse ? start : end};
}
};
}
}
SearchCursor.prototype = {
findNext: function() {return this.find(false);},
findPrevious: function() {return this.find(true);},
find: function(reverse) {
var self = this, pos = this.cm.clipPos(reverse ? this.pos.from : this.pos.to);
function savePosAndFail(line) {
var pos = {line: line, ch: 0};
self.pos = {from: pos, to: pos};
self.atOccurrence = false;
return false;
}
for (;;) {
if (this.pos = this.matches(reverse, pos)) {
this.atOccurrence = true;
return this.pos.match || true;
}
if (reverse) {
if (!pos.line) return savePosAndFail(0);
pos = {line: pos.line-1, ch: this.cm.getLine(pos.line-1).length};
}
else {
var maxLine = this.cm.lineCount();
if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
pos = {line: pos.line+1, ch: 0};
}
}
},
from: function() {if (this.atOccurrence) return this.pos.from;},
to: function() {if (this.atOccurrence) return this.pos.to;},
replace: function(newText) {
var self = this;
if (this.atOccurrence)
self.pos.to = this.cm.replaceRange(newText, self.pos.from, self.pos.to);
}
};
CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
return new SearchCursor(this, query, pos, caseFold);
});
})();

View File

@@ -0,0 +1,16 @@
.CodeMirror-completions {
position: absolute;
z-index: 10;
overflow: hidden;
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
}
.CodeMirror-completions select {
background: #fafafa;
outline: none;
border: none;
padding: 0;
margin: 0;
font-family: monospace;
}

View File

@@ -0,0 +1,66 @@
(function() {
CodeMirror.simpleHint = function(editor, getHints) {
// We want a single cursor position.
if (editor.somethingSelected()) return;
var result = getHints(editor);
if (!result || !result.list.length) return;
var completions = result.list;
function insert(str) {
editor.replaceRange(str, result.from, result.to);
}
// When there is only one completion, use it directly.
if (completions.length == 1) {insert(completions[0]); return true;}
// Build the select widget
var complete = document.createElement("div");
complete.className = "CodeMirror-completions";
var sel = complete.appendChild(document.createElement("select"));
// Opera doesn't move the selection when pressing up/down in a
// multi-select, but it does properly support the size property on
// single-selects, so no multi-select is necessary.
if (!window.opera) sel.multiple = true;
for (var i = 0; i < completions.length; ++i) {
var opt = sel.appendChild(document.createElement("option"));
opt.appendChild(document.createTextNode(completions[i]));
}
sel.firstChild.selected = true;
sel.size = Math.min(10, completions.length);
var pos = editor.cursorCoords();
complete.style.left = pos.x + "px";
complete.style.top = pos.yBot + "px";
document.body.appendChild(complete);
// Hack to hide the scrollbar.
if (completions.length <= 10)
complete.style.width = (sel.clientWidth - 1) + "px";
var done = false;
function close() {
if (done) return;
done = true;
complete.parentNode.removeChild(complete);
}
function pick() {
insert(completions[sel.selectedIndex]);
close();
setTimeout(function(){editor.focus();}, 50);
}
CodeMirror.connect(sel, "blur", close);
CodeMirror.connect(sel, "keydown", function(event) {
var code = event.keyCode;
// Enter
if (code == 13) {CodeMirror.e_stop(event); pick();}
// Escape
else if (code == 27) {CodeMirror.e_stop(event); close(); editor.focus();}
else if (code != 38 && code != 40) {
close(); editor.focus();
setTimeout(function(){CodeMirror.simpleHint(editor, getHints);}, 50);
}
});
CodeMirror.connect(sel, "dblclick", pick);
sel.focus();
// Opera sometimes ignores focusing a freshly created node
if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100);
return true;
};
})();

View File

@@ -0,0 +1,249 @@
CodeMirror.defineMode("clike", function(config, parserConfig) {
var indentUnit = config.indentUnit,
keywords = parserConfig.keywords || {},
blockKeywords = parserConfig.blockKeywords || {},
atoms = parserConfig.atoms || {},
hooks = parserConfig.hooks || {},
multiLineStrings = parserConfig.multiLineStrings;
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
var curPunc;
function tokenBase(stream, state) {
var ch = stream.next();
if (hooks[ch]) {
var result = hooks[ch](stream, state);
if (result !== false) return result;
}
if (ch == '"' || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
}
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
curPunc = ch;
return null
}
if (/\d/.test(ch)) {
stream.eatWhile(/[\w\.]/);
return "number";
}
if (ch == "/") {
if (stream.eat("*")) {
state.tokenize = tokenComment;
return tokenComment(stream, state);
}
if (stream.eat("/")) {
stream.skipToEnd();
return "comment";
}
}
if (isOperatorChar.test(ch)) {
stream.eatWhile(isOperatorChar);
return "operator";
}
stream.eatWhile(/[\w\$_]/);
var cur = stream.current();
if (keywords.propertyIsEnumerable(cur)) {
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
return "keyword";
}
if (atoms.propertyIsEnumerable(cur)) return "atom";
return "word";
}
function tokenString(quote) {
return function(stream, state) {
var escaped = false, next, end = false;
while ((next = stream.next()) != null) {
if (next == quote && !escaped) {end = true; break;}
escaped = !escaped && next == "\\";
}
if (end || !(escaped || multiLineStrings))
state.tokenize = tokenBase;
return "string";
};
}
function tokenComment(stream, state) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
break;
}
maybeEnd = (ch == "*");
}
return "comment";
}
function Context(indented, column, type, align, prev) {
this.indented = indented;
this.column = column;
this.type = type;
this.align = align;
this.prev = prev;
}
function pushContext(state, col, type) {
return state.context = new Context(state.indented, col, type, null, state.context);
}
function popContext(state) {
var t = state.context.type;
if (t == ")" || t == "]" || t == "}")
state.indented = state.context.indented;
return state.context = state.context.prev;
}
// Interface
return {
startState: function(basecolumn) {
return {
tokenize: null,
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
indented: 0,
startOfLine: true
};
},
token: function(stream, state) {
var ctx = state.context;
if (stream.sol()) {
if (ctx.align == null) ctx.align = false;
state.indented = stream.indentation();
state.startOfLine = true;
}
if (stream.eatSpace()) return null;
curPunc = null;
var style = (state.tokenize || tokenBase)(stream, state);
if (style == "comment" || style == "meta") return style;
if (ctx.align == null) ctx.align = true;
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
else if (curPunc == "{") pushContext(state, stream.column(), "}");
else if (curPunc == "[") pushContext(state, stream.column(), "]");
else if (curPunc == "(") pushContext(state, stream.column(), ")");
else if (curPunc == "}") {
while (ctx.type == "statement") ctx = popContext(state);
if (ctx.type == "}") ctx = popContext(state);
while (ctx.type == "statement") ctx = popContext(state);
}
else if (curPunc == ctx.type) popContext(state);
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
pushContext(state, stream.column(), "statement");
state.startOfLine = false;
return style;
},
indent: function(state, textAfter) {
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
var closing = firstChar == ctx.type;
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
else return ctx.indented + (closing ? 0 : indentUnit);
},
electricChars: "{}"
};
});
(function() {
function words(str) {
var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
return obj;
}
var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
"double static else struct entry switch extern typedef float union for unsigned " +
"goto while enum void const signed volatile";
function cppHook(stream, state) {
if (!state.startOfLine) return false;
stream.skipToEnd();
return "meta";
}
// C#-style strings where "" escapes a quote.
function tokenAtString(stream, state) {
var next;
while ((next = stream.next()) != null) {
if (next == '"' && !stream.eat('"')) {
state.tokenize = null;
break;
}
}
return "string";
}
CodeMirror.defineMIME("text/x-csrc", {
name: "clike",
keywords: words(cKeywords),
blockKeywords: words("case do else for if switch while struct"),
atoms: words("null"),
hooks: {"#": cppHook}
});
CodeMirror.defineMIME("text/x-c++src", {
name: "clike",
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
"static_cast typeid catch operator template typename class friend private " +
"this using const_cast inline public throw virtual delete mutable protected " +
"wchar_t"),
blockKeywords: words("catch class do else finally for if struct switch try while"),
atoms: words("true false null"),
hooks: {"#": cppHook}
});
CodeMirror.defineMIME("text/x-java", {
name: "clike",
keywords: words("abstract assert boolean break byte case catch char class const continue default " +
"do double else enum extends final finally float for goto if implements import " +
"instanceof int interface long native new package private protected public " +
"return short static strictfp super switch synchronized this throw throws transient " +
"try void volatile while"),
blockKeywords: words("catch class do else finally for if switch try while"),
atoms: words("true false null"),
hooks: {
"@": function(stream, state) {
stream.eatWhile(/[\w\$_]/);
return "meta";
}
}
});
CodeMirror.defineMIME("text/x-csharp", {
name: "clike",
keywords: words("abstract as base bool break byte case catch char checked class const continue decimal" +
" default delegate do double else enum event explicit extern finally fixed float for" +
" foreach goto if implicit in int interface internal is lock long namespace new object" +
" operator out override params private protected public readonly ref return sbyte sealed short" +
" sizeof stackalloc static string struct switch this throw try typeof uint ulong unchecked" +
" unsafe ushort using virtual void volatile while add alias ascending descending dynamic from get" +
" global group into join let orderby partial remove select set value var yield"),
blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
atoms: words("true false null"),
hooks: {
"@": function(stream, state) {
if (stream.eat('"')) {
state.tokenize = tokenAtString;
return tokenAtString(stream, state);
}
stream.eatWhile(/[\w\$_]/);
return "meta";
}
}
});
CodeMirror.defineMIME("text/x-groovy", {
name: "clike",
keywords: words("abstract as assert boolean break byte case catch char class const continue def default " +
"do double else enum extends final finally float for goto if implements import " +
"in instanceof int interface long native new package property private protected public " +
"return short static strictfp super switch synchronized this throw throws transient " +
"try void volatile while"),
atoms: words("true false null"),
hooks: {
"@": function(stream, state) {
stream.eatWhile(/[\w\$_]/);
return "meta";
}
}
});
}());

View File

@@ -0,0 +1,101 @@
<!doctype html>
<html>
<head>
<title>CodeMirror: C-like mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="clike.js"></script>
<link rel="stylesheet" href="../../doc/docs.css">
<style>.CodeMirror {border: 2px inset #dee;}</style>
</head>
<body>
<h1>CodeMirror: C-like mode</h1>
<form><textarea id="code" name="code">
/* C demo code */
#include <zmq.h>
#include <pthread.h>
#include <semaphore.h>
#include <time.h>
#include <stdio.h>
#include <fcntl.h>
#include <malloc.h>
typedef struct {
void* arg_socket;
zmq_msg_t* arg_msg;
char* arg_string;
unsigned long arg_len;
int arg_int, arg_command;
int signal_fd;
int pad;
void* context;
sem_t sem;
} acl_zmq_context;
#define p(X) (context->arg_##X)
void* zmq_thread(void* context_pointer) {
acl_zmq_context* context = (acl_zmq_context*)context_pointer;
char ok = 'K', err = 'X';
int res;
while (1) {
while ((res = sem_wait(&amp;context->sem)) == EINTR);
if (res) {write(context->signal_fd, &amp;err, 1); goto cleanup;}
switch(p(command)) {
case 0: goto cleanup;
case 1: p(socket) = zmq_socket(context->context, p(int)); break;
case 2: p(int) = zmq_close(p(socket)); break;
case 3: p(int) = zmq_bind(p(socket), p(string)); break;
case 4: p(int) = zmq_connect(p(socket), p(string)); break;
case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &amp;p(len)); break;
case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break;
case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break;
case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break;
case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break;
}
p(command) = errno;
write(context->signal_fd, &amp;ok, 1);
}
cleanup:
close(context->signal_fd);
free(context_pointer);
return 0;
}
void* zmq_thread_init(void* zmq_context, int signal_fd) {
acl_zmq_context* context = malloc(sizeof(acl_zmq_context));
pthread_t thread;
context->context = zmq_context;
context->signal_fd = signal_fd;
sem_init(&amp;context->sem, 1, 0);
pthread_create(&amp;thread, 0, &amp;zmq_thread, context);
pthread_detach(thread);
return context;
}
</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true,
mode: "text/x-csrc"
});
</script>
<p>Simple mode that tries to handle C-like languages as well as it
can. Takes two configuration parameters: <code>keywords</code>, an
object whose property names are the keywords in the language,
and <code>useCPP</code>, which determines whether C preprocessor
directives are recognized.</p>
<p><strong>MIME types defined:</strong> <code>text/x-csrc</code>
(C code), <code>text/x-c++src</code> (C++
code), <code>text/x-java</code> (Java
code), <code>text/x-groovy</code> (Groovy code).</p>
</body>
</html>

View File

@@ -0,0 +1,124 @@
CodeMirror.defineMode("css", function(config) {
var indentUnit = config.indentUnit, type;
function ret(style, tp) {type = tp; return style;}
function tokenBase(stream, state) {
var ch = stream.next();
if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());}
else if (ch == "/" && stream.eat("*")) {
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
}
else if (ch == "<" && stream.eat("!")) {
state.tokenize = tokenSGMLComment;
return tokenSGMLComment(stream, state);
}
else if (ch == "=") ret(null, "compare");
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
else if (ch == "\"" || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
}
else if (ch == "#") {
stream.eatWhile(/[\w\\\-]/);
return ret("atom", "hash");
}
else if (ch == "!") {
stream.match(/^\s*\w*/);
return ret("keyword", "important");
}
else if (/\d/.test(ch)) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
}
else if (/[,.+>*\/]/.test(ch)) {
return ret(null, "select-op");
}
else if (/[;{}:\[\]]/.test(ch)) {
return ret(null, ch);
}
else {
stream.eatWhile(/[\w\\\-]/);
return ret("variable", "variable");
}
}
function tokenCComment(stream, state) {
var maybeEnd = false, ch;
while ((ch = stream.next()) != null) {
if (maybeEnd && ch == "/") {
state.tokenize = tokenBase;
break;
}
maybeEnd = (ch == "*");
}
return ret("comment", "comment");
}
function tokenSGMLComment(stream, state) {
var dashes = 0, ch;
while ((ch = stream.next()) != null) {
if (dashes >= 2 && ch == ">") {
state.tokenize = tokenBase;
break;
}
dashes = (ch == "-") ? dashes + 1 : 0;
}
return ret("comment", "comment");
}
function tokenString(quote) {
return function(stream, state) {
var escaped = false, ch;
while ((ch = stream.next()) != null) {
if (ch == quote && !escaped)
break;
escaped = !escaped && ch == "\\";
}
if (!escaped) state.tokenize = tokenBase;
return ret("string", "string");
};
}
return {
startState: function(base) {
return {tokenize: tokenBase,
baseIndent: base || 0,
stack: []};
},
token: function(stream, state) {
if (stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
var context = state.stack[state.stack.length-1];
if (type == "hash" && context == "rule") style = "atom";
else if (style == "variable") {
if (context == "rule") style = "number";
else if (!context || context == "@media{") style = "tag";
}
if (context == "rule" && /^[\{\};]$/.test(type))
state.stack.pop();
if (type == "{") {
if (context == "@media") state.stack[state.stack.length-1] = "@media{";
else state.stack.push("{");
}
else if (type == "}") state.stack.pop();
else if (type == "@media") state.stack.push("@media");
else if (context == "{" && type != "comment") state.stack.push("rule");
return style;
},
indent: function(state, textAfter) {
var n = state.stack.length;
if (/^\}/.test(textAfter))
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
return state.baseIndent + n * indentUnit;
},
electricChars: "}"
};
});
CodeMirror.defineMIME("text/css", "css");

View File

@@ -0,0 +1,55 @@
<!doctype html>
<html>
<head>
<title>CodeMirror: CSS mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="css.js"></script>
<style>.CodeMirror {background: #f8f8f8;}</style>
<link rel="stylesheet" href="../../doc/docs.css">
</head>
<body>
<h1>CodeMirror: CSS mode</h1>
<form><textarea id="code" name="code">
/* Some example CSS */
@import url("something.css");
body {
margin: 0;
padding: 3em 6em;
font-family: tahoma, arial, sans-serif;
color: #000;
}
#navigation a {
font-weight: bold;
text-decoration: none !important;
}
h1 {
font-size: 2.5em;
}
h2 {
font-size: 1.7em;
}
h1:before, h2:before {
content: "::";
}
code {
font-family: courier, monospace;
font-size: 80%;
color: #418A8A;
}
</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
</script>
<p><strong>MIME types defined:</strong> <code>text/css</code>.</p>
</body>
</html>

View File

@@ -0,0 +1,77 @@
<!doctype html>
<html>
<head>
<title>CodeMirror: JavaScript mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="javascript.js"></script>
<link rel="stylesheet" href="../../doc/docs.css">
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
</head>
<body>
<h1>CodeMirror: JavaScript mode</h1>
<div><textarea id="code" name="code">
// Demo code (the actual new parser character stream implementation)
function StringStream(string) {
this.pos = 0;
this.string = string;
}
StringStream.prototype = {
done: function() {return this.pos >= this.string.length;},
peek: function() {return this.string.charAt(this.pos);},
next: function() {
if (this.pos &lt; this.string.length)
return this.string.charAt(this.pos++);
},
eat: function(match) {
var ch = this.string.charAt(this.pos);
if (typeof match == "string") var ok = ch == match;
else var ok = ch &amp;&amp; match.test ? match.test(ch) : match(ch);
if (ok) {this.pos++; return ch;}
},
eatWhile: function(match) {
var start = this.pos;
while (this.eat(match));
if (this.pos > start) return this.string.slice(start, this.pos);
},
backUp: function(n) {this.pos -= n;},
column: function() {return this.pos;},
eatSpace: function() {
var start = this.pos;
while (/\s/.test(this.string.charAt(this.pos))) this.pos++;
return this.pos - start;
},
match: function(pattern, consume, caseInsensitive) {
if (typeof pattern == "string") {
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
if (consume !== false) this.pos += str.length;
return true;
}
}
else {
var match = this.string.slice(this.pos).match(pattern);
if (match &amp;&amp; consume !== false) this.pos += match[0].length;
return match;
}
}
};
</textarea></div>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true
});
</script>
<p>JavaScript mode supports a single configuration
option, <code>json</code>, which will set the mode to expect JSON
data rather than a JavaScript program.</p>
<p><strong>MIME types defined:</strong> <code>text/javascript</code>, <code>application/json</code>.</p>
</body>
</html>

View File

@@ -0,0 +1,360 @@
CodeMirror.defineMode("javascript", function(config, parserConfig) {
var indentUnit = config.indentUnit;
var jsonMode = parserConfig.json;
// Tokenizer
var keywords = function(){
function kw(type) {return {type: type, style: "keyword"};}
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
return {
"if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C,
"var": kw("var"), "const": kw("var"), "let": kw("var"),
"function": kw("function"), "catch": kw("catch"),
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
"in": operator, "typeof": operator, "instanceof": operator,
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
};
}();
var isOperatorChar = /[+\-*&%=<>!?|]/;
function chain(stream, state, f) {
state.tokenize = f;
return f(stream, state);
}
function nextUntilUnescaped(stream, end) {
var escaped = false, next;
while ((next = stream.next()) != null) {
if (next == end && !escaped)
return false;
escaped = !escaped && next == "\\";
}
return escaped;
}
// Used as scratch variables to communicate multiple values without
// consing up tons of objects.
var type, content;
function ret(tp, style, cont) {
type = tp; content = cont;
return style;
}
function jsTokenBase(stream, state) {
var ch = stream.next();
if (ch == '"' || ch == "'")
return chain(stream, state, jsTokenString(ch));
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
return ret(ch);
else if (ch == "0" && stream.eat(/x/i)) {
stream.eatWhile(/[\da-f]/i);
return ret("number", "number");
}
else if (/\d/.test(ch)) {
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
return ret("number", "number");
}
else if (ch == "/") {
if (stream.eat("*")) {
return chain(stream, state, jsTokenComment);
}
else if (stream.eat("/")) {
stream.skipToEnd();
return ret("comment", "comment");
}
else if (state.reAllowed) {
nextUntilUnescaped(stream, "/");
stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
return ret("regexp", "string");
}
else {
stream.eatWhile(isOperatorChar);
return ret("operator", null, stream.current());
}
}
else if (ch == "#") {
stream.skipToEnd();
return ret("error", "error");
}
else if (isOperatorChar.test(ch)) {
stream.eatWhile(isOperatorChar);
return ret("operator", null, stream.current());
}
else {
stream.eatWhile(/[\w\$_]/);
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
return (known && state.kwAllowed) ? ret(known.type, known.style, word) :
ret("variable", "variable", word);
}
}
function jsTokenString(quote) {
return function(stream, state) {
if (!nextUntilUnescaped(stream, quote))
state.tokenize = jsTokenBase;
return ret("string", "string");
};
}
function jsTokenComment(stream, state) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = jsTokenBase;
break;
}
maybeEnd = (ch == "*");
}
return ret("comment", "comment");
}
// Parser
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true};
function JSLexical(indented, column, type, align, prev, info) {
this.indented = indented;
this.column = column;
this.type = type;
this.prev = prev;
this.info = info;
if (align != null) this.align = align;
}
function inScope(state, varname) {
for (var v = state.localVars; v; v = v.next)
if (v.name == varname) return true;
}
function parseJS(state, style, type, content, stream) {
var cc = state.cc;
// Communicate our context to the combinators.
// (Less wasteful than consing up a hundred closures on every call.)
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc;
if (!state.lexical.hasOwnProperty("align"))
state.lexical.align = true;
while(true) {
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
if (combinator(type, content)) {
while(cc.length && cc[cc.length - 1].lex)
cc.pop()();
if (cx.marked) return cx.marked;
if (type == "variable" && inScope(state, content)) return "variable-2";
return style;
}
}
}
// Combinator utils
var cx = {state: null, column: null, marked: null, cc: null};
function pass() {
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
}
function cont() {
pass.apply(null, arguments);
return true;
}
function register(varname) {
var state = cx.state;
if (state.context) {
cx.marked = "def";
for (var v = state.localVars; v; v = v.next)
if (v.name == varname) return;
state.localVars = {name: varname, next: state.localVars};
}
}
// Combinators
var defaultVars = {name: "this", next: {name: "arguments"}};
function pushcontext() {
if (!cx.state.context) cx.state.localVars = defaultVars;
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
}
function popcontext() {
cx.state.localVars = cx.state.context.vars;
cx.state.context = cx.state.context.prev;
}
function pushlex(type, info) {
var result = function() {
var state = cx.state;
state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info)
};
result.lex = true;
return result;
}
function poplex() {
var state = cx.state;
if (state.lexical.prev) {
if (state.lexical.type == ")")
state.indented = state.lexical.indented;
state.lexical = state.lexical.prev;
}
}
poplex.lex = true;
function expect(wanted) {
return function expecting(type) {
if (type == wanted) return cont();
else if (wanted == ";") return pass();
else return cont(arguments.callee);
};
}
function statement(type) {
if (type == "var") return cont(pushlex("vardef"), vardef1, expect(";"), poplex);
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
if (type == "{") return cont(pushlex("}"), block, poplex);
if (type == ";") return cont();
if (type == "function") return cont(functiondef);
if (type == "for") return cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"),
poplex, statement, poplex);
if (type == "variable") return cont(pushlex("stat"), maybelabel);
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
block, poplex, poplex);
if (type == "case") return cont(expression, expect(":"));
if (type == "default") return cont(expect(":"));
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
statement, poplex, popcontext);
return pass(pushlex("stat"), expression, expect(";"), poplex);
}
function expression(type) {
if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator);
if (type == "function") return cont(functiondef);
if (type == "keyword c") return cont(maybeexpression);
if (type == "(") return cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
if (type == "operator") return cont(expression);
if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
return cont();
}
function maybeexpression(type) {
if (type.match(/[;\}\)\],]/)) return pass();
return pass(expression);
}
function maybeoperator(type, value) {
if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
if (type == "operator") return cont(expression);
if (type == ";") return;
if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
if (type == ".") return cont(property, maybeoperator);
if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
}
function maybelabel(type) {
if (type == ":") return cont(poplex, statement);
return pass(maybeoperator, expect(";"), poplex);
}
function property(type) {
if (type == "variable") {cx.marked = "property"; return cont();}
}
function objprop(type) {
if (type == "variable") cx.marked = "property";
if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expression);
}
function commasep(what, end) {
function proceed(type) {
if (type == ",") return cont(what, proceed);
if (type == end) return cont();
return cont(expect(end));
}
return function commaSeparated(type) {
if (type == end) return cont();
else return pass(what, proceed);
};
}
function block(type) {
if (type == "}") return cont();
return pass(statement, block);
}
function vardef1(type, value) {
if (type == "variable"){register(value); return cont(vardef2);}
return cont();
}
function vardef2(type, value) {
if (value == "=") return cont(expression, vardef2);
if (type == ",") return cont(vardef1);
}
function forspec1(type) {
if (type == "var") return cont(vardef1, forspec2);
if (type == ";") return pass(forspec2);
if (type == "variable") return cont(formaybein);
return pass(forspec2);
}
function formaybein(type, value) {
if (value == "in") return cont(expression);
return cont(maybeoperator, forspec2);
}
function forspec2(type, value) {
if (type == ";") return cont(forspec3);
if (value == "in") return cont(expression);
return cont(expression, expect(";"), forspec3);
}
function forspec3(type) {
if (type != ")") cont(expression);
}
function functiondef(type, value) {
if (type == "variable") {register(value); return cont(functiondef);}
if (type == "(") return cont(pushlex(")"), pushcontext, commasep(funarg, ")"), poplex, statement, popcontext);
}
function funarg(type, value) {
if (type == "variable") {register(value); return cont();}
}
// Interface
return {
startState: function(basecolumn) {
return {
tokenize: jsTokenBase,
reAllowed: true,
kwAllowed: true,
cc: [],
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
localVars: null,
context: null,
indented: 0
};
},
token: function(stream, state) {
if (stream.sol()) {
if (!state.lexical.hasOwnProperty("align"))
state.lexical.align = false;
state.indented = stream.indentation();
}
if (stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
if (type == "comment") return style;
state.reAllowed = type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/);
state.kwAllowed = type != '.';
return parseJS(state, style, type, content, stream);
},
indent: function(state, textAfter) {
if (state.tokenize != jsTokenBase) return 0;
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical,
type = lexical.type, closing = firstChar == type;
if (type == "vardef") return lexical.indented + 4;
else if (type == "form" && firstChar == "{") return lexical.indented;
else if (type == "stat" || type == "form") return lexical.indented + indentUnit;
else if (lexical.info == "switch" && !closing)
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
else return lexical.indented + (closing ? 0 : indentUnit);
},
electricChars: ":{}"
};
});
CodeMirror.defineMIME("text/javascript", "javascript");
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});

View File

@@ -0,0 +1,48 @@
<!doctype html>
<html>
<head>
<title>CodeMirror: PHP mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="../xml/xml.js"></script>
<script src="../javascript/javascript.js"></script>
<script src="../css/css.js"></script>
<script src="../clike/clike.js"></script>
<script src="php.js"></script>
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
<link rel="stylesheet" href="../../doc/docs.css">
</head>
<body>
<h1>CodeMirror: PHP mode</h1>
<form><textarea id="code" name="code">
<?php
function hello($who) {
return "Hello " . $who;
}
?>
<p>The program says <?= hello("World") ?>.</p>
<script>
alert("And here is some JS code"); // also colored
</script>
</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true,
mode: "application/x-httpd-php",
indentUnit: 4,
indentWithTabs: true,
enterMode: "keep",
tabMode: "shift"
});
</script>
<p>Simple HTML/PHP mode based on
the <a href="../clike/">C-like</a> mode. Depends on XML,
JavaScript, CSS, and C-like modes.</p>
<p><strong>MIME types defined:</strong> <code>application/x-httpd-php</code> (HTML with PHP code), <code>text/x-php</code> (plain, non-wrapped PHP code).</p>
</body>
</html>

View File

@@ -0,0 +1,120 @@
(function() {
function keywords(str) {
var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
return obj;
}
function heredoc(delim) {
return function(stream, state) {
if (stream.match(delim)) state.tokenize = null;
else stream.skipToEnd();
return "string";
}
}
var phpConfig = {
name: "clike",
keywords: keywords("abstract and array as break case catch cfunction class clone const continue declare " +
"default do else elseif enddeclare endfor endforeach endif endswitch endwhile extends " +
"final for foreach function global goto if implements interface instanceof namespace " +
"new or private protected public static switch throw try use var while xor return" +
"die echo empty exit eval include include_once isset list require require_once print unset"),
blockKeywords: keywords("catch do else elseif for foreach if switch try while"),
atoms: keywords("true false null TRUE FALSE NULL"),
multiLineStrings: true,
hooks: {
"$": function(stream, state) {
stream.eatWhile(/[\w\$_]/);
return "variable-2";
},
"<": function(stream, state) {
if (stream.match(/<</)) {
stream.eatWhile(/[\w\.]/);
state.tokenize = heredoc(stream.current().slice(3));
return state.tokenize(stream, state);
}
return false;
},
"#": function(stream, state) {
stream.skipToEnd();
return "comment";
}
}
};
CodeMirror.defineMode("php", function(config, parserConfig) {
var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
var jsMode = CodeMirror.getMode(config, "javascript");
var cssMode = CodeMirror.getMode(config, "css");
var phpMode = CodeMirror.getMode(config, phpConfig);
function dispatch(stream, state) { // TODO open PHP inside text/css
if (state.curMode == htmlMode) {
var style = htmlMode.token(stream, state.curState);
if (style == "meta" && /^<\?/.test(stream.current())) {
state.curMode = phpMode;
state.curState = state.php;
state.curClose = /^\?>/;
state.mode = 'php';
}
else if (style == "tag" && stream.current() == ">" && state.curState.context) {
if (/^script$/i.test(state.curState.context.tagName)) {
state.curMode = jsMode;
state.curState = jsMode.startState(htmlMode.indent(state.curState, ""));
state.curClose = /^<\/\s*script\s*>/i;
state.mode = 'javascript';
}
else if (/^style$/i.test(state.curState.context.tagName)) {
state.curMode = cssMode;
state.curState = cssMode.startState(htmlMode.indent(state.curState, ""));
state.curClose = /^<\/\s*style\s*>/i;
state.mode = 'css';
}
}
return style;
}
else if (stream.match(state.curClose, false)) {
state.curMode = htmlMode;
state.curState = state.html;
state.curClose = null;
state.mode = 'html';
return dispatch(stream, state);
}
else return state.curMode.token(stream, state.curState);
}
return {
startState: function() {
var html = htmlMode.startState();
return {html: html,
php: phpMode.startState(),
curMode: parserConfig.startOpen ? phpMode : htmlMode,
curState: parserConfig.startOpen ? phpMode.startState() : html,
curClose: parserConfig.startOpen ? /^\?>/ : null,
mode: parserConfig.startOpen ? 'php' : 'html'}
},
copyState: function(state) {
var html = state.html, htmlNew = CodeMirror.copyState(htmlMode, html),
php = state.php, phpNew = CodeMirror.copyState(phpMode, php), cur;
if (state.curState == html) cur = htmlNew;
else if (state.curState == php) cur = phpNew;
else cur = CodeMirror.copyState(state.curMode, state.curState);
return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur, curClose: state.curClose};
},
token: dispatch,
indent: function(state, textAfter) {
if ((state.curMode != phpMode && /^\s*<\//.test(textAfter)) ||
(state.curMode == phpMode && /^\?>/.test(textAfter)))
return htmlMode.indent(state.html, textAfter);
return state.curMode.indent(state.curState, textAfter);
},
electricChars: "/{}:"
}
});
CodeMirror.defineMIME("application/x-httpd-php", "php");
CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
CodeMirror.defineMIME("text/x-php", phpConfig);
})();

View File

@@ -0,0 +1,44 @@
<!doctype html>
<html>
<head>
<title>CodeMirror: XML mode</title>
<link rel="stylesheet" href="../../lib/codemirror.css">
<script src="../../lib/codemirror.js"></script>
<script src="xml.js"></script>
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
<link rel="stylesheet" href="../../doc/docs.css">
</head>
<body>
<h1>CodeMirror: XML mode</h1>
<form><textarea id="code" name="code">
&lt;html style="color: green"&gt;
&lt;!-- this is a comment --&gt;
&lt;head&gt;
&lt;title&gt;HTML Example&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
The indentation tries to be &lt;em&gt;somewhat &amp;quot;do what
I mean&amp;quot;&lt;/em&gt;... but might not match your style.
&lt;/body&gt;
&lt;/html&gt;
</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: {name: "xml", alignCDATA: true},
lineNumbers: true
});
</script>
<p>The XML mode supports two configuration parameters:</p>
<dl>
<dt><code>htmlMode (boolean)</code></dt>
<dd>This switches the mode to parse HTML instead of XML. This
means attributes do not have to be quoted, and some elements
(such as <code>br</code>) do not require a closing tag.</dd>
<dt><code>alignCDATA (boolean)</code></dt>
<dd>Setting this to true will force the opening tag of CDATA
blocks to not be indented.</dd>
</dl>
<p><strong>MIME types defined:</strong> <code>application/xml</code>, <code>text/html</code>.</p>
</body>
</html>

View File

@@ -0,0 +1,252 @@
CodeMirror.defineMode("xml", function(config, parserConfig) {
var indentUnit = config.indentUnit;
var Kludges = parserConfig.htmlMode ? {
autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true,
"meta": true, "col": true, "frame": true, "base": true, "area": true},
doNotIndent: {"pre": true},
allowUnquoted: true
} : {autoSelfClosers: {}, doNotIndent: {}, allowUnquoted: false};
var alignCDATA = parserConfig.alignCDATA;
// Return variables for tokenizers
var tagName, type;
function inText(stream, state) {
function chain(parser) {
state.tokenize = parser;
return parser(stream, state);
}
var ch = stream.next();
if (ch == "<") {
if (stream.eat("!")) {
if (stream.eat("[")) {
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
else return null;
}
else if (stream.match("--")) return chain(inBlock("comment", "-->"));
else if (stream.match("DOCTYPE", true, true)) {
stream.eatWhile(/[\w\._\-]/);
return chain(doctype(1));
}
else return null;
}
else if (stream.eat("?")) {
stream.eatWhile(/[\w\._\-]/);
state.tokenize = inBlock("meta", "?>");
return "meta";
}
else {
type = stream.eat("/") ? "closeTag" : "openTag";
stream.eatSpace();
tagName = "";
var c;
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
state.tokenize = inTag;
return "tag";
}
}
else if (ch == "&") {
stream.eatWhile(/[^;]/);
stream.eat(";");
return "atom";
}
else {
stream.eatWhile(/[^&<]/);
return null;
}
}
function inTag(stream, state) {
var ch = stream.next();
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
state.tokenize = inText;
type = ch == ">" ? "endTag" : "selfcloseTag";
return "tag";
}
else if (ch == "=") {
type = "equals";
return null;
}
else if (/[\'\"]/.test(ch)) {
state.tokenize = inAttribute(ch);
return state.tokenize(stream, state);
}
else {
stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);
return "word";
}
}
function inAttribute(quote) {
return function(stream, state) {
while (!stream.eol()) {
if (stream.next() == quote) {
state.tokenize = inTag;
break;
}
}
return "string";
};
}
function inBlock(style, terminator) {
return function(stream, state) {
while (!stream.eol()) {
if (stream.match(terminator)) {
state.tokenize = inText;
break;
}
stream.next();
}
return style;
};
}
function doctype(depth) {
return function(stream, state) {
var ch;
while ((ch = stream.next()) != null) {
if (ch == "<") {
state.tokenize = doctype(depth + 1);
return state.tokenize(stream, state);
} else if (ch == ">") {
if (depth == 1) {
state.tokenize = inText;
break;
} else {
state.tokenize = doctype(depth - 1);
return state.tokenize(stream, state);
}
}
}
return "meta";
};
}
var curState, setStyle;
function pass() {
for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
}
function cont() {
pass.apply(null, arguments);
return true;
}
function pushContext(tagName, startOfLine) {
var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
curState.context = {
prev: curState.context,
tagName: tagName,
indent: curState.indented,
startOfLine: startOfLine,
noIndent: noIndent
};
}
function popContext() {
if (curState.context) curState.context = curState.context.prev;
}
function element(type) {
if (type == "openTag") {
curState.tagName = tagName;
return cont(attributes, endtag(curState.startOfLine));
} else if (type == "closeTag") {
var err = false;
if (curState.context) {
err = curState.context.tagName != tagName;
} else {
err = true;
}
if (err) setStyle = "error";
return cont(endclosetag(err));
}
return cont();
}
function endtag(startOfLine) {
return function(type) {
if (type == "selfcloseTag" ||
(type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase())))
return cont();
if (type == "endTag") {pushContext(curState.tagName, startOfLine); return cont();}
return cont();
};
}
function endclosetag(err) {
return function(type) {
if (err) setStyle = "error";
if (type == "endTag") { popContext(); return cont(); }
setStyle = "error";
return cont(arguments.callee);
}
}
function attributes(type) {
if (type == "word") {setStyle = "attribute"; return cont(attributes);}
if (type == "equals") return cont(attvalue, attributes);
if (type == "string") {setStyle = "error"; return cont(attributes);}
return pass();
}
function attvalue(type) {
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
if (type == "string") return cont(attvaluemaybe);
return pass();
}
function attvaluemaybe(type) {
if (type == "string") return cont(attvaluemaybe);
else return pass();
}
return {
startState: function() {
return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
},
token: function(stream, state) {
if (stream.sol()) {
state.startOfLine = true;
state.indented = stream.indentation();
}
if (stream.eatSpace()) return null;
setStyle = type = tagName = null;
var style = state.tokenize(stream, state);
state.type = type;
if ((style || type) && style != "comment") {
curState = state;
while (true) {
var comb = state.cc.pop() || element;
if (comb(type || style)) break;
}
}
state.startOfLine = false;
return setStyle || style;
},
indent: function(state, textAfter, fullLine) {
var context = state.context;
if ((state.tokenize != inTag && state.tokenize != inText) ||
context && context.noIndent)
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
if (context && /^<\//.test(textAfter))
context = context.prev;
while (context && !context.startOfLine)
context = context.prev;
if (context) return context.indent + indentUnit;
else return 0;
},
compareStates: function(a, b) {
if (a.indented != b.indented || a.tokenize != b.tokenize) return false;
for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) {
if (!ca || !cb) return ca == cb;
if (ca.tagName != cb.tagName) return false;
}
},
electricChars: "/"
};
});
CodeMirror.defineMIME("application/xml", "xml");
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});

29
README.md Normal file
View File

@@ -0,0 +1,29 @@
ICE coder :: Matt Pass
Very early version of the web based IDE which allows for creation of websites in the web browser.
Uses the brilliant CodeMirror plus some other PHP & JS code to deal with file handling and make the whole thing work. Also has the extra plugin 'Adminer' for DB management.
Is fully open source and I'd encourage you to take it, make it your own and customise to your hearts content! :)
Suitable for commercial & non-commercial projects, just let me know if it's useful to you and any cool customisations you make to it.
In respect of this, I see ICE coder as a community project and I very much suspect the code is less than perfect as my initial commit is a very early version.
Please feel free to assist with the development of this and maybe in time we can produce a fantastic web based IDE for web devs.
INSTALLATION
1.Open /lib/settings.php and adjust variables to suit
2.Upload all the files to a Linux or Windows host under a new sub-dir URL such as yourdomain.com/_coder
3.Visit this URL in your browser
4.ICE coder will be a view only mode with a userLevel of 0 out of 10. To get level 10 access append ?login=highAdmin to your URL
5.Now you have top level access and can save (CTRL+S), delete (DEL) etc
Plenty of comments included in the code to assist with understanding.
Comments, improvements & feedback welcomed!

105
editor.php Normal file
View File

@@ -0,0 +1,105 @@
<!DOCTYPE html>
<html>
<head>
<title>CodeMirror 2: ICE Coders Editor of Choice</title>
<?php include("lib/settings.php");?>
<link rel="stylesheet" href="<?php echo $codeMirrorDir; ?>/lib/codemirror.css">
<script src="<?php echo $codeMirrorDir; ?>/lib/codemirror.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/xml/xml.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/javascript/javascript.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/css/css.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/clike/clike.js"></script>
<script src="<?php echo $codeMirrorDir; ?>/mode/php/php.js"></script>
<link rel="stylesheet" href="lib/editor.css">
<style type="text/css">
.CodeMirror {position: absolute; width: 0px; background-color: #ffffff}
.CodeMirror-scroll {width: 100px; height: 100px;}
.cm-s-visible {width: 100px}
.cm-s-hidden {width: 0px}
</style>
</head>
<body onKeyDown="return top.ICEcoder.interceptKeys('content', event);" onKeyUp="top.ICEcoder.resetKeys(event);">
<script>
<?php
for ($i=1;$i<=10;$i++) {
?>
var cM<?php echo $i;?> = CodeMirror(document.body, {
mode: "application/x-httpd-php",
theme: "icecoder",
lineNumbers: true,
lineWrapping: true,
indentUnit: 4,
tabSize: 4,
indentWithTabs: true,
electricChars: false,
onCursorActivity: function() {
top.ICEcoder.getCaretPosition();
top.ICEcoder.updateCharDisplay();
},
onChange: function() {
top.ICEcoder.getCaretPosition();
top.ICEcoder.updateCharDisplay();
top.ICEcoder.updateNestingIndicator();
if (top.ICEcoder.findMode) {
top.ICEcoder.results.splice(top.ICEcoder.findResult,1);
top.document.getElementById('results').innerHTML = top.ICEcoder.results.length + " results";
top.ICEcoder.findMode = false;
}
},
onKeyEvent: function(instance, e) {
top.ICEcoder.redoChangedContent(event);
top.ICEcoder.findReplace('find',true);
top.ICEcoder.getCaretPosition();
top.ICEcoder.updateCharDisplay();
tok = cM<?php echo $i;?>.getTokenAt(cM<?php echo $i;?>.getCursor());
if (tok.string!=">") {lastString=tok.string};
if (e.type=="keyup"&&e.keyCode=="16"&&lastKeyCode=="190") {
canDoEndTag=true;
for (i=0;i<top.ICEcoder.tagNestExceptions.length;i++) {
if(top.ICEcoder.tagString!="script" && top.ICEcoder.tagString==top.ICEcoder.tagNestExceptions[i]) {
canDoEndTag=false;
}
}
contentType = top.ICEcoder.caretLocType;
if (canDoEndTag && (contentType!="JavaScript"||(contentType=="JavaScript"&&top.ICEcoder.tagString=="script"))) {
numTabs = top.ICEcoder.htmlTagArray.length;
if (top.ICEcoder.htmlTagArray[0]=="html") {numTabs--};
tabs = "";
for (i=0;i<numTabs-1;i++) {
tabs += "\t";
}
endTag = "</" + top.ICEcoder.htmlTagArray[top.ICEcoder.htmlTagArray.length-1] + ">";
if (top.ICEcoder.tagString=="script") {endTag="</"+"script>"};
if(top.ICEcoder.tagString=="title") {
cM<?php echo $i;?>.replaceSelection(endTag);
cM<?php echo $i;?>.setCursor(cM<?php echo $i;?>.getCursor().line,top.ICEcoder.tagString.length+2);
} else if(top.ICEcoder.tagString=="html"||top.ICEcoder.tagString=="head") {
cM<?php echo $i;?>.replaceSelection("\n\n"+endTag);
cM<?php echo $i;?>.setCursor(cM<?php echo $i;?>.getCursor().line-1,numTabs);
} else {
cM<?php echo $i;?>.replaceSelection("\n"+tabs+"\t\n"+tabs+endTag);
cM<?php echo $i;?>.setCursor(cM<?php echo $i;?>.getCursor().line-1,numTabs);
}
}
};
lastKeyCode = e.keyCode;
},
extraKeys: {"Enter": false}
});
cM<?php echo $i;?>.getWrapperElement().getElementsByClassName("CodeMirror-lines")[0].addEventListener("click", function(){
if (top.ICEcoder.results) {
top.document.getElementById('results').innerHTML = top.ICEcoder.results.length + " results";
}
top.ICEcoder.findMode = false;
}, false);
<?php
;};
?>
</script>
</body>
</html>

163
files.php Normal file
View File

@@ -0,0 +1,163 @@
<?php
function fileManager($directory, $return_link) {
$code = "";
// Generates a list of all directories, sub-directories, and files in $directory
// Remove trailing slash
if(substr($directory, -1) == "/" ) {$directory = substr($directory, 0, strlen($directory)-1);};
$code .= fileManager_dir($directory, $return_link);
return $code;
}
function fileManager_dir($directory, $return_link, $first_call=true) {
if (!isset($_SESSION['restrictedFiles'])) {include("lib/settings.php");};
$restrictedFiles = $_SESSION['restrictedFiles'];
$bannedFiles = $_SESSION['bannedFiles'];
$docRoot = str_replace("\\","/",$_SERVER['DOCUMENT_ROOT']);
if (strrpos($_SERVER['DOCUMENT_ROOT'],":")) {
$serverType = "Windows";
} else {
$serverType = "Linux";
}
// Chop off trailing slash
if (strrpos($docRoot,"/")==strlen($docRoot)-1) {$docRoot = substr($docRoot,0,strlen($docRoot)-1);};
$fileManager = "";
// Recursive function called by fileManager() to list directories/files
// Get and sort directories/files
if(function_exists("scandir")) {$file = scandir($directory);} else {$file = php4_scandir($directory);};
natcasesort($file);
// Make directories first
$files = $dirs = array();
foreach($file as $this_file) {
if(is_dir("$directory/$this_file")) {$dirs[] = $this_file;} else {$files[] = $this_file;};
}
$file = array_merge($dirs, $files);
// Filter unwanted files
if(!empty($bannedFiles)) {
foreach(array_keys($file) as $key) {
$fileFolder = $file[$key];
for ($i=0;$i<count($bannedFiles);$i++) {
if(strpos($fileFolder,$bannedFiles[$i])!==false) {unset($file[$key]);};
}
}
}
if(count($file) > 2) { // To ignore . and .. directories
if($first_call) {
// Root Directory
$dirRep = str_replace("\\","/",$directory);
$link = str_replace("[link]", "$dirRep/", $return_link);
$link = str_replace("//","/",$link);
$fileAtts = "";
if ($serverType=="Linux") {
$ownerInfo = posix_getpwuid(fileowner($link));
$chmodInfo = substr(sprintf('%o', fileperms($link)), -4);
if ($ownerInfo['name']!="nobody"&&(substr($chmodInfo, -1)!=2&&substr($chmodInfo, -1)!=3&&substr($chmodInfo, -1)!=6&&substr($chmodInfo, -1)!=7)) {
$fileAtts = "<img src=\"images/file-manager-icons/padlock.png\" onClick=\"alert('Owner: ".$ownerInfo['name']."\\nCHMOD:".$chmodInfo."')\">";
}
}
$fileManager = "<ul class=\"fileManager\">";
$fileManager .= "<li class=\"pft-directory\"><a href=\"#\" onMouseOver=\"top.ICEcoder.overFileFolder('folder','$link')\" onMouseOut=\"top.ICEcoder.overFileFolder('folder','')\" style=\"position: relative; left:-22px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id=\"|\">/ [ROOT]</span> ".$fileAtts."</a>";
$fileManager .= $fileManager .= fileManager_dir("$directory/", $return_link ,false);
$fileManager .= "</li>";
$first_call = false;
} else {
$fileManager = "<ul>";
}
foreach( $file as $this_file ) {
$bannedFile=false;
for ($i=0;$i<count($bannedFiles);$i++) {
if (strpos($directory,$bannedFiles[$i])!=""||strpos($this_file,$bannedFiles[$i])!="") {
$bannedFile=true;
}
}
if( $this_file != "." && $this_file != ".." && $bannedFile == false) {
if( is_dir("$directory/$this_file") ) {
// Directory
$dirRep = str_replace("\\","/",$directory);
$link = str_replace("[link]", "$dirRep/" . urlencode($this_file), $return_link);
$link = str_replace("//","/",$link);
$fileAtts = "";
if ($serverType=="Linux") {
$ownerInfo = posix_getpwuid(fileowner($link));
$chmodInfo = substr(sprintf('%o', fileperms($link)), -4);
if ($ownerInfo['name']!="nobody"&&(substr($chmodInfo, -1)!=2&&substr($chmodInfo, -1)!=3&&substr($chmodInfo, -1)!=6&&substr($chmodInfo, -1)!=7)) {
$fileAtts = "<img src=\"images/file-manager-icons/padlock.png\" onClick=\"alert('Owner: ".$ownerInfo['name']."\\nCHMOD:".$chmodInfo."')\">";
}
}
$fileManager .= "<li class=\"pft-directory\"><a href=\"#\" onMouseOver=\"top.ICEcoder.overFileFolder('folder','$link')\" onMouseOut=\"top.ICEcoder.overFileFolder('folder','')\" style=\"position: relative; left:-22px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id=\"".str_replace("/","|",str_replace($docRoot,"",$link))."\">" . htmlspecialchars($this_file) . "</span> ".$fileAtts."</a>";
$fileManager .= fileManager_dir("$directory/$this_file", $return_link , false);
$fileManager .= "</li>";
} else {
// File
// Get extension (prefix 'ext-' to prevent invalid classes from extensions that begin with numbers)
$ext = "ext-" . substr($this_file, strrpos($this_file, ".") + 1);
$dirRep = str_replace("\\","/",$directory);
$link = str_replace("[link]", "$dirRep/" . urlencode($this_file), $return_link);
$link = str_replace("//","/",$link);
$restrictedFile=false;
for ($i=0;$i<count($restrictedFiles);$i++) {
if (strpos($link,$restrictedFiles[$i])!="") {
$restrictedFile=true;
}
}
if ($_SESSION['userLevel'] == 10 || ($_SESSION['userLevel'] < 10 && $restrictedFile==false)) {
$fileAtts = "";
if ($serverType=="Linux") {
$ownerInfo = posix_getpwuid(fileowner($link));
$chmodInfo = substr(sprintf('%o', fileperms($link)), -4);
if ($ownerInfo['name']!="nobody"&&(substr($chmodInfo, -1)!=2&&substr($chmodInfo, -1)!=3&&substr($chmodInfo, -1)!=6&&substr($chmodInfo, -1)!=7)) {
$fileAtts = "<img src=\"images/file-manager-icons/padlock.png\" onClick=\"alert('Owner: ".$ownerInfo['name']."\\nCHMOD:".$chmodInfo."')\">";
}
}
$fileManager .= "<li class=\"pft-file " . strtolower($ext) . "\"><a nohref onMouseOver=\"top.ICEcoder.overFileFolder('file','$link')\" onMouseOut=\"top.ICEcoder.overFileFolder('file','')\" style=\"position: relative; left:-22px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id=\"".str_replace("/","|",str_replace($docRoot,"",$link))."\">" . htmlspecialchars($this_file) . "</span> ".$fileAtts."</a></li>";
} else {
if ($_SESSION['userLevel'] == 0) {
$fileAtts = "<img src=\"images/file-manager-icons/padlock.png\" style=\"cursor: pointer\" onClick=\"alert('Sorry, you need higher admin level rights to view.')\">";
$fileManager .= "<li class=\"pft-file " . strtolower($ext) . "\" style=\"cursor: default\"><span style=\"position: relative; left:-22px; color: #888888\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [HIDDEN] ".$fileAtts."</span></li>";
} else {
$fileAtts = "<img src=\"images/file-manager-icons/padlock.png\" onClick=\"alert('Sorry, you need higher admin level rights to open.')\">";
$fileManager .= "<li class=\"pft-file " . strtolower($ext) . "\"><a nohref onMouseOver=\"top.ICEcoder.overFileFolder('file','$link')\" onMouseOut=\"top.ICEcoder.overFileFolder('file','')\" style=\"position: relative; left:-22px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span id=\"".str_replace("/","|",str_replace($docRoot,"",$link))."\">" . htmlspecialchars($this_file) . "</span> ".$fileAtts."</a></li>";
}
}
}
}
}
$fileManager .= "</ul>";
}
return $fileManager;
}
// For PHP4 compatibility
function php4_scandir($dir) {
$dh = opendir($dir);
while( false !== ($filename = readdir($dh)) ) {
$files[] = $filename;
}
sort($files);
return($files);
}
?>
<!DOCTYPE html>
<html onContextMenu="return top.ICEcoder.showMenu()">
<head>
<title>ICE Coder File Manager</title>
<link rel="stylesheet" type="text/css" href="lib/files.css">
<script src="lib/coder.js" type="text/javascript"></script>
</head>
<body onLoad="top.ICEcoder.fileManager()" onClick="top.ICEcoder.selectFileFolder()" onDblClick="top.ICEcoder.openFile()" onKeyDown="return top.ICEcoder.interceptKeys('files', event);" onKeyUp="top.ICEcoder.resetKeys(event);">
<?php
echo fileManager($_SERVER['DOCUMENT_ROOT'], "[link]");
?>
<iframe name="fileControl" style="display: none"></iframe>
</body>
</html>

BIN
images/Thumbs.db Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

BIN
images/clipboard.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
images/database.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 464 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 856 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 B

BIN
images/files-arrow.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

BIN
images/ice-coder.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
images/images.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
images/nav-bg.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
images/nav-close.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 B

BIN
images/nav-new.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

BIN
images/upload.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

128
index.php Normal file
View File

@@ -0,0 +1,128 @@
<?php
include("lib/settings.php");
$allowedIP = false;
for($i=0;$i<count($allowedIPs);$i++) {
if ($allowedIPs[$i]==$_SERVER["REMOTE_ADDR"]||$allowedIPs[$i]=="*") {
$allowedIP = true;
}
}
if (!$allowedIP) {
// 404 the page
header('HTTP/1.0 404 Not Found');
?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL <?php echo str_replace("/index.php","",$_SERVER["SCRIPT_NAME"]);?> was not found on this server.</p>
<hr>
<address>Apache/2.2.3 (CentOS) Server at www.mattpass.com Port 80</address>
</body></html>
<?php
exit();
};
// Test for latest CodeMirror version
if ($testcMVersion) {
$cMLatestVer = json_encode(file_get_contents("http://codemirror.net/latest-version.txt"));
$cMLatestVer = rtrim(ltrim($cMLatestVer,"\""),"\"\\n");
if ($cMThisVer<$cMLatestVer) {
echo '<script>alert(\'Code Mirror '.$cMLatestVer.' now released\n\nPlease upgrade\');</script>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>ICE Coder - <?php echo $versionNo;?></title>
<link rel="stylesheet" type="text/css" href="lib/coder.css">
<script>
shortURLStarts = "<?php echo $shortURLStarts;?>";
</script>
<script language="JavaScript" src="lib/coder.js"></script>
</head><?php
$onLoadExtras = "";
for ($i=0;$i<count($plugins);$i++) {
if ($plugins[$i][5]!="") {
$onLoadExtras .= ";ICEcoder.startPluginIntervals('".$plugins[$i][3]."','".$plugins[$i][4]."','".$plugins[$i][5]."')";
};
};
?>
<body onLoad="ICEcoder.init()<?php echo $onLoadExtras;?>" onResize="ICEcoder.setLayout()" onKeyDown="return ICEcoder.interceptKeys('coder', event);" onKeyUp="parent.ICEcoder.resetKeys(event);">
<div id="blackMask" class="blackMask" onClick="ICEcoder.showHide('hide',this)">
<div class="popupVCenter">
<div class="popup" id="mediaContainer"></div>
</div>
</div>
<div id="header" class="header" onContextMenu="return false">
<div class="plugins">
<?php
for ($i=0;$i<count($plugins);$i++) {
echo '<a href="'.$plugins[$i][3].'" target="'.$plugins[$i][4].'"><img src="'.$plugins[$i][1].'" style="'.$plugins[$i][2].'" alt="'.$plugins[$i][0].'"></a>';
};
?>
<iframe id="pluginActions" style="display: none"></iframe>
</div>
<div class="version"><?php echo $versionNo;?></div>
<img src="images/ice-coder.gif" class="logo">
</div>
<div id="files" class="files" onMouseOver="ICEcoder.changeFilesW('expand')" onMouseOut="ICEcoder.changeFilesW('contract')">
<div class="account" id="account"><a nohref style="cursor: pointer" onClick="ICEcoder.lockUnlockNav()"><img src="images/file-manager-icons/padlock-disabled.png" id="fmLock" style="margin-left: 232px; margin-top: 27px"></a></div>
<iframe id="filesFrame" class="frame" name="ff" src="files.php"></iframe>
<div class="upload" style="display: none"><a href="javascript:alert('Doesn\'t do anything yet but will be a drag & drop style uploader')"><img src="images/upload.png"></a></div>
</div>
<div id="editor" class="editor">
<div id="tabsBar" class="tabsBar" onContextMenu="return false">
<?php
for ($i=1;$i<=10;$i++) {
echo '<div id="tab'.$i.'" class="tab" onClick="if(ICEcoder.canSwitchTabs) {ICEcoder.switchTab('.$i.')} else {ICEcoder.canSwitchTabs=true}"></div>';
}
?><div class="newTab" onClick="ICEcoder.newTab()"><img src="images/nav-new.png"></div>
</div>
<div id="findBar" class="findBar" onContextMenu="return false">
<form name="findAndReplace">
<div class="findReplace">
<div class="findText">Find</div>
<input type="text" name="find" value="" id="find" class="textbox find" onKeyUp="ICEcoder.findReplace('find',true)">
<div class="findTextPlural">'s</div>
<select name="connector" onChange="ICEcoder.findReplaceOptions()">
<option>in</option>
<option>and</option>
</select>
<div class="replaceText" id="rText" style="display: none">replace with</div>
<input type="text" name="replace" value="" id="replace" class="textbox replace" style="display: none">
<div class="targetText" id="rTarget" style="display: none">in</div>
<select name="target">
<option>this document</option>
<option>open documents</option>
<option>all files</option>
<option>all filenames</option>
</select>
<input type="button" name="submit" value="&gt;&gt;" class="submit" onClick="ICEcoder.findReplace('findReplace',false)">
<div class="results" id="results"></div>
</div>
</form>
<form onSubmit="return ICEcoder.goToLine()">
<div class="goLine">Go to Line<input type="text" name="goToLine" value="" id="goToLineNo" class="textbox goToLine">
</form>
</div>
<iframe name="contentFrame" id="content" src="editor.php" class="code">
</iframe>
</div>
<div class="footer" id="footer" onContextMenu="return false">
<div class="nesting" id="nestValid">Nesting OK</div>
<div class="nestLoc">Cursor nest location</div>
<div class="nestDisplay" id="nestDisplay"></div>
<div class="charDisplay" id="charDisplay"><span id="char"></span></div>
</div>
</body>
</html>

95
lib/coder.css Normal file
View File

@@ -0,0 +1,95 @@
/* First, reset everything to a standard */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
font-family: arial, verdana, helvetica, sans-serif;
border: 0px;
margin: 0px;
padding: 0px;
outline: 0px;
font-size: 12px;
vertical-align: top;
}
body {overflow: hidden}
.blackMask {position: fixed; display: table; width: 100%; height: 100%; top: 0px; left: 0px; visibility: hidden; background-color: rgba(0,0,0,0.8); text-align: center; z-index: 100}
.blackMask .popupVCenter {#position: absolute; display: table-cell; #top: 50%; vertical-align: middle; text-align: center}
.popupVCenter .popup {#position: relative; #top: -50%; text-align: center}
.header {position: absolute; display: inline-block; width: 100%; height: 40px; background-color: #ffffff; text-align: right; z-index: 2}
.header .plugins {position: absolute; display: inline-block; left: 27px; top: 3px}
.header .plugins img {position: relative; display: inline-block; margin-right: 15px}
.header .version {position: relative; display: inline-block; margin-top: 25px; font-size: 10px; color: #bbbbbb}
.header .logo {position: relative; margin: 5px 10px 0px 5px}
.files {position: absolute; display: inline-block; height: 100%; width: 15px; background-color: #e0e0e0; background-image: url('../images/files-arrow.gif'); background-repeat: no-repeat; background-position: 100% 50%; overflow: hidden; z-index: 1;
-webkit-box-shadow: 0px 0px 10px 4px rgba(0,0,0,0.4);
-moz-box-shadow: 0px 0px 10px 4px rgba(0,0,0,0.4);
box-shadow: 0px 0px 10px 4px rgba(0,0,0,0.4);
-webkit-transition: width 0.5s ease-in-out;
-moz-transition: width 0.5s ease-in-out;
-o-transition: width 0.5s ease-in-out;
-ms-transition: width 0.5s ease-in-out;
transition: width 0.5s ease-in-out;
}
.files .account {display: inline-block; height: 50px; width: 250px; margin-top: 40px; background-color: #888888}
.files .frame {display: inline-block; width: 250px}
.files .upload {display: inline-block; height: 40px; width: 250px; background-color: #888888}
.files .upload img {margin: 8px 0px 0px 15px}
.editor {position: absolute; display: inline-block; top: 0px; left: 15px; width: 2400px; background-color: #fbfbfb;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.editor .tabsBar {display: inline-block; height: 21px; width: 2400px; margin-top: 40px; padding-left: 41px; border-bottom: solid 1px #888888; background-color: #eeeeee;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.tabsBar .tab {display: inline-block; display: none; background-image: url('../images/nav-bg.gif'); background-repeat: repeat-x; background-position: 0px 0px; padding: 4px 8px 2px 8px; font-size: 10px; border-left: solid 1px #ffffff; border-right: solid 1px #bbbbbb; color: #ffffff; cursor: pointer}
.tabsBar .tab img {margin: 1px 0px 0px 5px}
.tabsBar .newTab {display: inline-block; background-image: url('../images/nav-bg.gif'); background-repeat: repeat-x; background-position: 0px 0px; padding: 5px 5px 1px 5px; border-left: solid 1px #ffffff; border-right: solid 1px #bbbbbb; cursor: pointer;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
.editor .findBar {display: inline-block; height: 28px; width: 2400px; background-color: #eeeeee}
.findBar .findReplace {position: absolute; z-index: 1}
.findReplace select {position: relative; font-size: 10px; margin: 8px 2px 0px 2px; top: -2px;}
.findReplace .findText {display: inline-block; height: 21px; font-size: 10px; margin: 8px 2px 0px 2px; margin-left: 43px}
.findReplace .find {position: relative; width: 120px; height: 16px; border: 0; top: -2px; font-size: 10px; padding-left: 5px}
.findReplace .findTextPlural {display: inline-block; height: 21px; font-size: 10px; margin: 8px 2px 0px 0px}
.findReplace .replaceText {height: 21px; font-size: 10px; margin: 8px 2px 0px 2px}
.findReplace .replace {position: relative; width: 120px; height: 16px; border: 0; top: -2px; font-size: 10px; padding-left: 5px}
.findReplace .targetText {height: 21px; font-size: 10px; margin: 8px 2px 0px 2px}
.findReplace .submit {position: relative; top: -2px; height: 17px; border: 1px solid #bbbbbb; background-color: #f8f8f8; font-size: 10px; cursor: pointer}
.findReplace .results {position: relative; display: inline-block; width: 200px; height: 20px; font-size: 10px; margin: 8px 0px 0px 20px}
.findBar .goLine {position: fixed; display: inline-block; width: 100px; right: -10px; top: 70px; height: 21px; font-size: 10px; z-index: 1}
.goLine .goToLine {width: 25px; height: 16px; border: 0; font-size: 10px; margin: -3px 0px 0px 3px}
.editor .code {position: relative; display: inline-block; top: 28px; width: 600px; height: 600px; visibility: hidden}
.footer {position: fixed; display: inline-block; width: 100%; height: 30px; bottom: 0px; background-color: rgba(0,0,0,0.7); left: 0px; z-index: 2}
.footer .nesting {display: inline-block; padding: 5px 8px; margin: 4px 0px 0px 15px; font-weight: bold; font-size: 10px; color: #ffffff; background-color: #00bb00}
.footer .nestLoc {position: absolute; display: inline-block; width: 120px; padding: 5px 0px 0px 8px; margin-top: 3px; left: 112px; font-weight: bold; font-size: 12px; color: #ffffff; text-align: right}
.footer .nestDisplay {position: absolute; display: inline-block; padding: 5px 0px 0px 8px; margin-top: 3px; left: 255px; font-size: 12px; color: #ffffff; text-align: right}
.footer .charDisplay {position: absolute; display: inline-block; padding: 5px 0px 0px 8px; margin-top: 3px; left: 100%; font-weight: bold; font-size: 12px; color: #ffffff; text-align: right; width: 200px; text-align: right; margin-left: -220px}
.textbox {
-webkit-box-shadow: inset 1px 1px 2px 0px rgba(0,0,0,0.4);
-moz-box-shadow: inset 1px 1px 2px 0px rgba(0,0,0,0.4);
box-shadow: inset 1px 1px 2px 0px rgba(0,0,0,0.4);
}

844
lib/coder.js Normal file
View File

@@ -0,0 +1,844 @@
// ICE coder by Matt Pass
// Free to use it for your own purposes, commercial or not, just let me know of any cool uses or customisations. :)
// No warranty or liability accepted for anything, all responsibility of use is your own.
// Latest version: https://github.com/mattpass/ICEcoder
// Twitter: @mattpass
var ICEcoder = {
// Define settings
filesW: 15, // Initial width of the files pane
minFilesW: 15, // Min width of the files pane
maxFilesW: 250, // Max width of the files pane
selectedTab: 0, // The tab that's currently selected
changedContent: [], // Binary array to indicate which tabs have changed
ctrlKeyDown: false, // Indicates if CTRL keydown
delKeyDown: false, // Indicates if DEL keydown
canSwitchTabs: true, // Stops switching of tabs when trying to close
openFiles: [], // Array of open file URLs
selectedFiles: [], // Array of selected files
findMode: false, // States if we're in find/replace mode
lockedNav: false, // Nav is locked or not
// Don't consider these tags as part of nesting as they're singles, JS or PHP code blocks
tagNestExceptions: ["!DOCTYPE","meta","link","img","br","hr","input","script","?"],
// On load, set aliases, set the layout and get the nest location
init: function() {
var aliasArray = ["header","files","account","filesFrame","editor","tabsBar","findBar","content","footer","nestValid","nestDisplay","charDisplay"];
ICEcoder.tD = top.document;
// Create our ID aliases
for (var i=0;i<aliasArray.length;i++) {
ICEcoder[aliasArray[i]] = ICEcoder.tD.getElementById(aliasArray[i]);
}
// Set layout & the nest location
ICEcoder.setLayout();
ICEcoder.getNestLocation('yes');
},
// Set out our layout according to the browser size
setLayout: function() {
var winW, winH, headerH, footerH, accountH, uploadH, tabsBarH, findBarH, cMCSS;
// Determin width & height available
if (window.innerWidth) {
var winW = window.innerWidth;
var winH = window.innerHeight;
} else {
var winW = document.body.clientWidth;
var winH = document.body.clientHeight;
}
// Apply sizes to various elements of the page
headerH = 40, footerH = 30, accountH = 50, uploadH = 40, tabsBarH = 21, findBarH = 28;
header.style.width = tabsBar.style.width = findBar.style.width = winW + "px";
files.style.width = editor.style.left = this.filesW + "px";
account.style.height = accountH + "px";
filesFrame.style.height = (winH-headerH-accountH-footerH-uploadH) + "px";
editor.style.width = ICEcoder.content.style.width = (winW-this.filesW) + "px";
ICEcoder.content.style.height = (winH-headerH-footerH-tabsBarH-findBarH) + "px";
// Resize the CodeMirror instances to match the window size
document.all ? strCSS = 'rules' : strCSS = 'cssRules';
cMCSS = ICEcoder.content.contentWindow.document;
cMCSS.styleSheets[2][strCSS][1].style['width'] = ICEcoder.content.style.width;
cMCSS.styleSheets[2][strCSS][1].style['height'] = ICEcoder.content.style.height;
cMCSS.styleSheets[2][strCSS][2].style['width'] = ICEcoder.content.style.width;
},
// Clean up our loaded code
contentCleanUp: function() {
var cM, codeTemp, lastBreakPos, prevBreakPos, startLineNestNum, endLineNestNum, numTabs;
cM = ICEcoder.getcMInstance();
codeTemp = cM.getValue();
// Remove excess white space, reducing doubles down to a single
while (codeTemp.indexOf(" ")>-1) {codeTemp = (codeTemp.replace(/ /g," "))}
// Remove any existing tabs
while (codeTemp.indexOf(" ")>-1) {codeTemp = (codeTemp.replace(/ /g,""))}
// Redo the tabbing according to nest position
lastBreakPos = 0;
while (codeTemp.indexOf('\n',lastBreakPos)<codeTemp.lastIndexOf('\n')) {
lastBreakPos = codeTemp.indexOf('\n',lastBreakPos+1);
prevBreakPos = codeTemp.lastIndexOf('\n',lastBreakPos-1);
// Now we've established looking at each line break plus the previous one,
// get the caret position & the nest depth position for both of those
ICEcoder.caretPos=lastBreakPos;
ICEcoder.getNestLocation();
endLineNestNum = ICEcoder.htmlTagArray.length;
ICEcoder.caretPos=prevBreakPos;
ICEcoder.getNestLocation();
startLineNestNum = ICEcoder.htmlTagArray.length;
// OK, if the start of the line has less of a nest depth than the end, we must have finished a tag, otherwise we must have started a tag
startLineNestNum<endLineNestNum ? numTabs=startLineNestNum : numTabs=endLineNestNum;
// If they're the same though, remove 1 to make it line up with the above tag
if (startLineNestNum==endLineNestNum) {numTabs--};
// Now we can generate the number of tabs needed
nestTabs = "";
for(var i=0;i<numTabs;i++) {
nestTabs += " "
}
// Lastly, put it all together
codeTemp = (codeTemp.substr(0,prevBreakPos+1) + nestTabs + codeTemp.substr(prevBreakPos+1,codeTemp.length));
// and adjust the last break position accordingly, ready to repeat this again
lastBreakPos += nestTabs.length;
}
// Then set the content in the editor & clear the history
cM.setValue(codeTemp);
cM.clearHistory();
},
// Work out the nesting depth location on demand and update our display if required
getNestLocation: function(updateNestDisplay) {
var cM, openTag, nestCheck, startPos, tagStart, canDoTheEndTag, tagEnd, tagEndJS, fileName;
cM = ICEcoder.getcMInstance();
nestCheck = cM.getValue();
// Set up array to store nest data, a var to establish if a tag is open and another to establish if we're in a code block
ICEcoder.htmlTagArray = [], openTag = false, ICEcoder.codeBlock = false;
// For every character from the start to our caret position
for(var i=0;i<=ICEcoder.caretPos;i++) {
// If we find a < tag and we're not within a tag, change the open tag state & set our start position
if(nestCheck.charAt(i)=="<" && openTag==false) {
openTag=true;
startPos=i+1;
// Get the tag name and if it's the start of a code block, set the var for that
tagStart=nestCheck.substr(startPos,nestCheck.length).split(" ")[0].split(">")[0].split("\n")[0];
if (tagStart=="script"||tagStart=="?") {ICEcoder.codeBlock=true}
if (tagStart!="") {ICEcoder.tagStart = tagStart}
};
// If we find a > tag and we're within a tag or codeblock
if(nestCheck.charAt(i)==">" && (openTag||ICEcoder.codeBlock)) {
// Get the tag name
tagString=nestCheck.substr(0,i);
tagString=tagString.substr(tagString.lastIndexOf('<')+1,tagString.length);
tagString=tagString.split(" ")[0];
ICEcoder.tagString = tagString;
canDoTheEndTag=true;
// Check it's not on our list of exceptions
for (var j=0;j<ICEcoder.tagNestExceptions.length;j++) {
if (tagString==ICEcoder.tagNestExceptions[j]) {
canDoTheEndTag=false;
}
}
if (canDoTheEndTag) {
// Get this end tag name
tagEnd=nestCheck.substr(0,i);
tagEndJS=tagEnd.substr(tagEnd.lastIndexOf('<'),tagEnd.length);
tagEnd=tagEnd.substr(tagEnd.lastIndexOf('<')+1,tagEnd.length);
tagEnd=tagEnd.substr(tagEnd.lastIndexOf(' ')+1,tagEnd.length);
tagEnd=tagEnd.substr(tagEnd.lastIndexOf('\t')+1,tagEnd.length);
tagEnd=tagEnd.substr(tagEnd.lastIndexOf(';')+1,tagEnd.length);
if (!ICEcoder.codeBlock) {
// OK, we can do something further as we're not in a code block
// If it's the same as the previously logged tag preceeded by /, it's the equivalent end tag
if (tagEnd=="/"+ICEcoder.htmlTagArray[ICEcoder.htmlTagArray.length-1]) {
// So remove the last logged tag, thereby going up one in the nest
ICEcoder.htmlTagArray.pop();
} else {
// Otherwise it's a different tag, add it to the end
ICEcoder.htmlTagArray.push(tagString);
}
} else if (
((ICEcoder.tagStart=="script"||ICEcoder.tagStart=="/script")&&tagEndJS=="</script")||
(ICEcoder.tagStart=="?"&&tagEnd=="?")) {
ICEcoder.codeBlock=false;
}
}
// Reset our open tag state ready for next time
openTag=false;
}
}
// Now we've built up our nest depth array, if we're due to show it in the display
if (updateNestDisplay) {
// Clear the display
ICEcoder.nestDisplay.innerHTML = "";
if ("undefined" != typeof ICEcoder.openFiles[ICEcoder.selectedTab-1]) {
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
if (fileName.indexOf(".js")<0&&fileName.indexOf(".css")<0) {
// Then for all the array items, output as the nest display
for (var i=0;i<ICEcoder.htmlTagArray.length;i++) {
ICEcoder.nestDisplay.innerHTML += ICEcoder.htmlTagArray[i];
if(i<ICEcoder.htmlTagArray.length-1) {ICEcoder.nestDisplay.innerHTML += " &gt; "};
}
}
}
}
},
// Detect keys/combos plus identify our area and set the vars, perform actions
interceptKeys: function(area, evt) {
var key;
key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
// DEL (Delete file)
if (key==46 && area == "files") {
top.ICEcoder.delKeyDown = true;
top.ICEcoder.deleteFile();
return false;
// CTRL key down
} else if(key==17) {
top.ICEcoder.ctrlKeyDown = true;
return false;
// CTRL+F (Find)
} else if(key==70&&top.ICEcoder.ctrlKeyDown==true) {
top.document.getElementById('find').focus();
return false;
// CTRL+S (Save)
} else if(key==83&&top.ICEcoder.ctrlKeyDown==true) {
top.ICEcoder.saveFile();
return false;
// Any other key
} else {
return key;
}
},
// Reset the state of keys back to the normal state
resetKeys: function(evt) {
var key;
key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
if (key==17) {top.ICEcoder.ctrlKeyDown = false;}
if (key==46) {top.ICEcoder.delKeyDown = false;}
},
// Set the width of the file manager on demand
changeFilesW: function(expandContract) {
var expandContract;
if (!ICEcoder.lockedNav) {
expandContract=="expand" ? ICEcoder.filesW = this.maxFilesW : ICEcoder.filesW = this.minFilesW;
// Redo the layout to match
ICEcoder.setLayout();
}
},
// Change tabs by reloading content
switchTab: function(newTab) {
var cM;
// Identify tab that's currently selected & show the instance
ICEcoder.selectedTab = newTab;
cM = ICEcoder.getcMInstance();
// Switch mode
ICEcoder.switchMode();
// Set all 10 cM instances to be hidden, then make our selected instance visable
for (var i=1;i<=10;i++) {
ICEcoder.content.contentWindow['cM'+i].setOption('theme','icecoder hidden');
}
cM.setOption('theme','icecoder visible');
// Focus on our selected instance
cM = ICEcoder.getcMInstance();
cM.focus();
// Highlight the selected tab
ICEcoder.redoTabHighlight(ICEcoder.selectedTab);
},
// Reset all tabs to be without a highlight and then highlight the selected
redoTabHighlight: function(selectedTab) {
for(var i=1;i<=10;i++) {
ICEcoder.changedContent[i-1]==1 ? bgVPos = -44 : bgVPos = 0;
i==selectedTab ? ICEcoder.changedContent[selectedTab-1]==1 ? bgVPos = -33 : bgVPos = -22 : bgVPos = bgVPos;
document.getElementById('tab'+i).style.backgroundPosition = "0px "+bgVPos+"px";
}
},
// Starts a new file by setting a few vars & clearing the editor
newTab: function() {
var cM;
ICEcoder.thisFileFolderType='file';
ICEcoder.thisFileFolderLink=shortURLStarts+'/[NEW]';
ICEcoder.openFile();
cM = ICEcoder.getcMInstance('new');
cM.setValue('');
cM.clearHistory();
ICEcoder.switchTab(ICEcoder.openFiles.length);
ICEcoder.content.style.visibility='visible';
},
// Create a new tab for a file
createNewTab: function() {
var closeTabLink;
// Push new file into array
top.ICEcoder.openFiles.push(top.ICEcoder.shortURL);
// Setup a new tab
closeTabLink = '<a nohref onClick="parent.ICEcoder.closeTab('+(top.ICEcoder.openFiles.length)+')"><img src="images/nav-close.gif"></a>';
top.document.getElementById('tab'+(top.ICEcoder.openFiles.length)).style.display = "inline-block";
top.document.getElementById('tab'+(top.ICEcoder.openFiles.length)).innerHTML = top.ICEcoder.openFiles[top.ICEcoder.openFiles.length-1] + " " + closeTabLink;
// Highlight it and state it's selected
top.ICEcoder.redoTabHighlight(top.ICEcoder.openFiles.length);
top.ICEcoder.selectedTab=top.ICEcoder.openFiles.length;
// Add a new value ready to indicate if this content has been changed
top.ICEcoder.changedContent.push(0);
},
// Indicate if the nesting structure of the code is OK
updateNestingIndicator: function () {
var cM, fileName;
cM = ICEcoder.getcMInstance();
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
ICEcoder.caretPos=cM.getValue().length;
ICEcoder.getNestLocation();
// Nesting is OK if at the end of the file we have no nests left, or it's a JS or CSS file
if (ICEcoder.htmlTagArray.length==0||fileName.indexOf(".js")>0||fileName.indexOf(".css")>0) {
ICEcoder.nestValid.style.backgroundColor="#00bb00";
ICEcoder.nestValid.innerHTML = "Nesting OK";
} else {
ICEcoder.nestValid.style.backgroundColor="#ff0000";
ICEcoder.nestValid.innerHTML = "Nesting Broken";
}
},
// Get the caret position on demand
getCaretPosition: function() {
var cM, content, line, char, charPos, charCount;
cM = ICEcoder.getcMInstance();
content = cM.getValue();
line = cM.getCursor().line;
char = cM.getCursor().ch;
charPos = 0;
for (var i=0;i<line;i++) {
charCount = content.indexOf("\n",charPos);
charPos=charCount+1;
}
ICEcoder.caretPos=(charPos+char-1);
ICEcoder.getNestLocation('yes');
},
// Update the code type, line & character display
updateCharDisplay: function() {
var cM;
cM = ICEcoder.getcMInstance();
ICEcoder.caretLocationType();
ICEcoder.charDisplay.innerHTML = ICEcoder.caretLocType + ", Line: " + (cM.getCursor().line+1) + ", Char: " + cM.getCursor().ch;
},
// Determine which area of the document we're in
caretLocationType: function () {
var cM, caretLocType, caretChunk;
cM = ICEcoder.getcMInstance();
caretLocType = "Unknown";
caretChunk = cM.getValue().substr(0,ICEcoder.caretPos+1);
if (caretChunk.lastIndexOf("<script")>caretChunk.lastIndexOf("</script>")&&caretLocType=="Unknown") {caretLocType = "JavaScript"};
if (caretChunk.lastIndexOf("<?")>caretChunk.lastIndexOf("?>")&&caretLocType=="Unknown") {caretLocType = "PHP"};
if (caretChunk.lastIndexOf("<")>caretChunk.lastIndexOf(">")&&caretLocType=="Unknown") {caretLocType = "HTML"};
if (caretLocType=="Unknown") {caretLocType = "Content"};
ICEcoder.caretLocType = caretLocType;
// If we're in a JS or PHP code block, add that to the nest display
if (caretLocType=="JavaScript"||caretLocType=="PHP") {
ICEcoder.nestDisplay.innerHTML += " &gt; " + caretLocType;
}
},
// Alter array indicating which files have changed
redoChangedContent: function(evt) {
var key;
key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;
// Exclude a few keys such as Escape...
if (top.ICEcoder.ctrlKeyDown==false && key!=27 && key!=20 && (key<16||key>19) && (key<37||key>40) && (key!=144||key!=145) && (key!=44||key!=45) && (key<33||key>36) && (key!=91||key!=92) && (key<112||key>123)) {
ICEcoder.changedContent[ICEcoder.selectedTab-1] = 1;
ICEcoder.redoTabHighlight(ICEcoder.selectedTab);
}
},
// Close the tab upon request
closeTab: function(closeTabNum) {
var cM, okToRemove;
cM = ICEcoder.getcMInstance();
okToRemove = true;
if (ICEcoder.changedContent[closeTabNum-1]==1) {
okToRemove = confirm('You have made changes.\n\nAre you sure you want to close without saving?');
}
if (okToRemove) {
// recursively copy over all tab data from the tab to the right, if there is one
for (var i=closeTabNum;i<ICEcoder.openFiles.length;i++) {
ICEcoder.tD.getElementById('tab'+i).innerHTML = ICEcoder.tD.getElementById('tab'+(i+1)).innerHTML;
ICEcoder.openFiles[i-1] = ICEcoder.openFiles[i];
// reduce the tab reference number on the closeTab link by 1
ICEcoder.tD.getElementById('tab'+i).innerHTML = ICEcoder.tD.getElementById('tab'+i).innerHTML.replace(("closeTab("+(i+1)+")"),"closeTab("+i+")");
}
// clear the rightmost tab (or only one left in a 1 tab scenario)
ICEcoder.tD.getElementById('tab'+ICEcoder.openFiles.length).style.display = "none";
ICEcoder.tD.getElementById('tab'+ICEcoder.openFiles.length).innerHTML = "";
ICEcoder.openFiles.pop();
// Determin the new selectedTab number, reduced by 1 if we have some tabs, 0 for a reset state
ICEcoder.openFiles.length>0 ? ICEcoder.selectedTab-=1 : ICEcoder.selectedTab = 0;
if (ICEcoder.openFiles.length>0 && ICEcoder.selectedTab==0) {ICEcoder.selectedTab=1};
// clear & hide the code textarea if we have no tabs open
if (ICEcoder.openFiles.length==0) {
// clear the value & HTML of the code textarea and also hide it
cM = ICEcoder.getcMInstance();
cM.setValue('');
cM.clearHistory();
ICEcoder.tD.getElementById('content').style.visibility = "hidden";
} else {
// Switch the mode & the tab
ICEcoder.switchMode();
ICEcoder.switchTab(ICEcoder.selectedTab);
}
// Highlight the selected tab after splicing the change state out of the array
top.ICEcoder.changedContent.splice(closeTabNum-1,1);
top.parent.ICEcoder.redoTabHighlight(ICEcoder.selectedTab);
}
// Lastly, stop it from trying to also switch tab
top.ICEcoder.canSwitchTabs=false;
},
// Setup the file manager
fileManager: function() {
ICEcoder.filesFrame = top.document.getElementById('filesFrame');
if (!ICEcoder.filesFrame.contentWindow.document.getElementsByTagName) {return;};
var aMenus = ICEcoder.filesFrame.contentWindow.document.getElementsByTagName("LI");
for (var i=0; i<aMenus.length; i++) {
var mclass = aMenus[i].className;
if (mclass.indexOf("pft-directory") > -1) {
var submenu=aMenus[i].childNodes;
for (var j=0; j<submenu.length; j++) {
if (submenu[j].tagName == "A") {
submenu[j].onclick = function() {
var node = this.nextSibling;
while (1) {
if (node != null) {
if (node.tagName == "UL") {
var d = (node.style.display == "none")
node.style.display = (d) ? "block" : "none";
this.className = (d) ? "open" : "closed";
return false;
}
node = node.nextSibling;
} else {
return false;
}
}
return false;
}
submenu[j].className = (mclass.indexOf("open") > -1) ? "open" : "closed";
}
if (submenu[j].tagName == "UL")
submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "none";
}
}
}
return false;
},
// Note which files or foldets we are over on mouseover/mouseout
overFileFolder: function(type, link) {
ICEcoder.thisFileFolderType=type;
ICEcoder.thisFileFolderLink=link;
},
// Select file or folder on demand
selectFileFolder: function() {
var resetFile, shortURL, foundSelectedFile, foundShortURL, foundFile, resetFile;
// If we've clicked somewhere other than a file/folder
if (top.ICEcoder.thisFileFolderLink=="") {
if (!top.ICEcoder.ctrlKeyDown) {
// Deselect all files
for (var i=0;i<=top.ICEcoder.selectedFiles.length;i++) {
if (top.ICEcoder.selectedFiles[i]) {
resetFile = top.ICEcoder.filesFrame.contentWindow.document.getElementById(top.ICEcoder.selectedFiles[i]);
resetFile.style.backgroundColor="#dddddd";
resetFile.style.color="#000000";
}
}
// Set our arrray to contain 0 items
top.ICEcoder.selectedFiles.length = 0;
}
} else {
// We clicked a file/folder. Work out a shortened URL for the file, with pipes instead of slashes
shortURL = top.ICEcoder.thisFileFolderLink.substr((top.ICEcoder.thisFileFolderLink.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.thisFileFolderLink.length).replace(/\//g,"|");
// If we have the CTRL key down
if (top.ICEcoder.ctrlKeyDown) {
foundSelectedFile=false;
// Reset all files to not be highlighted
for (i=0;i<=top.ICEcoder.selectedFiles.length;i++) {
if (top.ICEcoder.selectedFiles[i]==shortURL) {
resetFile = ICEcoder.filesFrame.contentWindow.document.getElementById(top.ICEcoder.selectedFiles[i]);
resetFile.style.backgroundColor="#dddddd";
resetFile.style.color="#000000";
top.ICEcoder.selectedFiles.splice(i);
foundSelectedFile=true;
}
}
if (!foundSelectedFile) {
foundFile = ICEcoder.filesFrame.contentWindow.document.getElementById(shortURL);
foundFile.style.backgroundColor="#888888";
foundFile.style.color="#f8f8f8";
top.ICEcoder.selectedFiles.push(shortURL);
}
// We are single clicking
} else {
if (top.ICEcoder.selectedFiles.length==1 && shortURL==top.ICEcoder.selectedFiles[0]) {
// Go into edit mode...
if (top.ICEcoder.slowClick) {top.ICEcoder.renameFile()}
} else {
// First deselect all files
for (i=0;i<top.ICEcoder.selectedFiles.length;i++) {
resetFile = ICEcoder.filesFrame.contentWindow.document.getElementById(top.ICEcoder.selectedFiles[i]);
resetFile.style.backgroundColor="#dddddd";
resetFile.style.color="#000000";
}
// Set our arrray to contain 0 items
top.ICEcoder.selectedFiles.length = 0;
// Add our URL and highlight the file
top.ICEcoder.selectedFiles.push(shortURL);
foundFile = ICEcoder.filesFrame.contentWindow.document.getElementById(shortURL);
foundFile.style.backgroundColor="#888888";
foundFile.style.color="#f8f8f8";
// Set a variable to test for slow double clicking (1-3secs)
top.ICEcoder.slowClick = false;
clearInterval(top.ICEcoder.slowClickS);
clearInterval(top.ICEcoder.slowClickE);
top.ICEcoder.slowClickS = setTimeout('top.ICEcoder.slowClick = true',1000);
top.ICEcoder.slowClickE = setTimeout('top.ICEcoder.slowClick = false',3000);
}
}
}
// Adjust the file & replace select values depending on if we have files selected
if (!top.ICEcoder.selectedFiles[0]) {
document.findAndReplace.target[2].innerHTML = "all files";
document.findAndReplace.target[3].innerHTML = "all filenames";
} else {
document.findAndReplace.target[2].innerHTML = "selected files";
document.findAndReplace.target[3].innerHTML = "selected filenames";
}
},
// Open a file on demand
openFile: function() {
if (top.ICEcoder.thisFileFolderLink!="" && top.ICEcoder.thisFileFolderType=="file") {
var shortURL, canOpenFile;
// work out a shortened URL for the file
shortURL = top.ICEcoder.thisFileFolderLink.replace(/\|/g,"/");
shortURL = shortURL.substr((shortURL.indexOf(shortURLStarts)+shortURLStarts.length),shortURL.length);
// No reason why we can't open a file (so far)
canOpenFile = true;
// Limit to 10 files open at a time
if (top.ICEcoder.openFiles.length<10) {
// check if we've already got it in our array
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
if (top.ICEcoder.openFiles[i]==shortURL) {
// we have, so don't bother opening again
canOpenFile = false;
// instead, switch to that tab
top.ICEcoder.switchTab(i+1);
}
}
} else {
// show a message because we have 10 files open
alert('Sorry, you can only have 10 files open at a time!');
canOpenFile = false;
}
// if we're still OK to open it...
if (canOpenFile) {
top.ICEcoder.shortURL = shortURL;
if (shortURL!="/[NEW]") {
// replace forward slashes with pipes so it get be placed in a querystring
top.ICEcoder.thisFileFolderLink = top.ICEcoder.thisFileFolderLink.replace(/\//g,"|");
ICEcoder.filesFrame.contentWindow.frames['fileControl'].location.href = "lib/file-control.php?action=load&file="+top.ICEcoder.thisFileFolderLink;
} else {
top.ICEcoder.createNewTab();
}
}
}
},
// Save a file on demand
saveFile: function() {
filesFrame.contentWindow.frames['fileControl'].location.href="lib/file-control.php?action=save&file="+ICEcoder.openFiles[ICEcoder.selectedTab-1].replace(/\//g,"|");
},
// Prompt a rename dialog on demand
renameFile: function() {
var renamedFile;
renamedFile = false;
renamedFile = prompt('Please enter the new name for',shortURL);
if (renamedFile) {
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
if(top.ICEcoder.openFiles[i]==shortURL.replace(/\|/g,"/")) {
// rename array item and the tab
top.ICEcoder.openFiles[i] = renamedFile;
closeTabLink = '<a nohref onClick="top.ICEcoder.files.contentWindow.closeTab('+(i+1)+')"><img src="images/nav-close.gif"></a>';
top.document.getElementById('tab'+(i+1)).innerHTML = top.ICEcoder.openFiles[i] + " " + closeTabLink;
}
}
ICEcoder.filesFrame.contentWindow.frames['fileControl'].location.href = "lib/file-control.php?action=rename&file="+renamedFile+"&oldFileName="+top.ICEcoder.thisFileFolderLink;
}
},
// Delete a file on demand
deleteFile: function() {
var delFiles, selectedFilesList;
delFiles = confirm('Delete: '+top.ICEcoder.selectedFiles+'?');
// Upon supply a new name, rename tabs and update filename on server
if (delFiles) {
selectedFilesList = "";
for (var i=0;i<top.ICEcoder.selectedFiles.length;i++) {
selectedFilesList += top.ICEcoder.selectedFiles[i];
if (i<top.ICEcoder.selectedFiles.length-1) {selectedFilesList+=";"}
}
ICEcoder.filesFrame.contentWindow.frames['fileControl'].location.href = "lib/file-control.php?action=delete&file="+selectedFilesList;
};
},
// Show menu on right clicking in file manager
showMenu: function() {
if ("undefined" != typeof top.ICEcoder.thisFileFolderLink && top.ICEcoder.thisFileFolderLink!="") {
alert('show menu');
}
return false;
},
// Show & hide target element
showHide: function(doVis,elem) {
doVis=="show" ? elem.style.visibility='visible' : elem.style.visibility='hidden';
},
// Update find & replace options based on user selection
findReplaceOptions: function() {
var rText, replace, rTarget;
rText = document.getElementById('rText').style.display;
replace = document.getElementById('replace').style.display;
rTarget = document.getElementById('rTarget').style.display;
document.findAndReplace.connector.value=="and" ? document.getElementById('rText').style.display = document.getElementById('replace').style.display = document.getElementById('rTarget').style.display = "inline-block" : document.getElementById('rText').style.display = document.getElementById('replace').style.display = document.getElementById('rTarget').style.display = "none";
},
// Find & replace text according to user selections
findReplace: function(action,resultsOnly) {
var find, findLen, cM, content, lineCount, numChars, charsToCursor, charCount, startPos, endPos;
// Determine our find string, in lowercase and the length of that
find = parent.parent.document.getElementById('find').value.toLowerCase();
findLen = find.length;
// If we have something to find
if (findLen>0) {
cM = ICEcoder.getcMInstance();
content = cM.getValue().toLowerCase();
// Find & replace the next instance?
if (document.findAndReplace.connector.value=="and" && cM.getSelection()==find) {
cM.replaceSelection(document.getElementById('replace').value);
}
if (!top.ICEcoder.findMode||parent.parent.document.getElementById('find').value!=ICEcoder.lastsearch) {
ICEcoder.results = [];
for (var i=0;i<content.length;i++) {
if (content.substr(i,findLen)==find) {
ICEcoder.results.push(i);
}
}
// Also remember the last search term made
ICEcoder.lastsearch = find;
}
// If we have results
if (ICEcoder.results.length>0) {
// Show results only
if (resultsOnly) {
parent.parent.document.getElementById('results').innerHTML = ICEcoder.results.length + " results";
// We need to take action instead
} else {
lineCount=1;
numChars=0;
for (var i=0;i<content.length;i++) {
if (content.indexOf('\n',i)==i && lineCount<=cM.getCursor().line) {
lineCount++;
numChars=i;
}
}
charsToCursor = numChars+cM.getCursor().ch;
ICEcoder.findResult = 0;
for (var i=0;i<ICEcoder.results.length;i++) {
if (ICEcoder.results[i]<=charsToCursor) {
ICEcoder.findResult++;
}
}
if (ICEcoder.findResult>ICEcoder.results.length-1) {ICEcoder.findResult=0};
parent.parent.document.getElementById('results').innerHTML = "Highlighted result "+(ICEcoder.findResult+1)+" of "+ICEcoder.results.length+" results";
lineCount=0;
for (var i=0;i<ICEcoder.results[ICEcoder.findResult];i++) {
if (content.indexOf('\n',i)==i) {
lineCount++;
}
}
charCount = ICEcoder.results[ICEcoder.findResult]-content.lastIndexOf('\n',ICEcoder.results[ICEcoder.findResult])-1;
startPos = new Object();
startPos.line = lineCount;
startPos.ch = charCount;
endPos = new Object();
endPos.line = lineCount;
endPos.ch = charCount+findLen;
// Finally, highlight our selection
cM = ICEcoder.getcMInstance();
cM.setSelection(startPos, endPos);
cM.focus();
top.ICEcoder.findMode = true;
}
} else {
parent.parent.document.getElementById('results').innerHTML = "No results";
}
} else {
parent.parent.document.getElementById('results').innerHTML = "";
}
},
// Go to a specific line number
goToLine: function() {
var cM;
cM = ICEcoder.getcMInstance();
cM.setCursor(document.getElementById('goToLineNo').value-1);
cM.focus();
return false;
},
// Switch the CodeMirror mode on demand
switchMode: function() {
var cM;
cM = ICEcoder.getcMInstance();
fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1];
if (fileName.indexOf('.js')>0) {
cM.setOption("mode","javascript");
} else if (fileName.indexOf('.css')>0) {
cM.setOption("mode","css");
} else {
cM.setOption("mode","application/x-httpd-php");
}
},
// Lock & unlock the file manager navigation on demand
lockUnlockNav: function() {
var lockIcon;
lockIcon = top.document.getElementById('fmLock');
ICEcoder.lockedNav ? ICEcoder.lockedNav = false : ICEcoder.lockedNav = true;
ICEcoder.lockedNav ? lockIcon.src="images/file-manager-icons/padlock.png" : lockIcon.src="images/file-manager-icons/padlock-disabled.png";
},
// Determine the CodeMirror instance we're using on demand
getcMInstance: function(newTab) {
var cM;
if (newTab=="new") {
cM = top.ICEcoder.content.contentWindow['cM'+ICEcoder.openFiles.length];
} else if (ICEcoder.openFiles.length==0) {
cM = top.ICEcoder.content.contentWindow['cM1'];
} else {
cM = top.ICEcoder.content.contentWindow['cM'+ICEcoder.selectedTab];
}
return cM;
},
// Start running plugin intervals according to given specifics
startPluginIntervals: function(plugURL,plugTarget,plugTimer) {
// For this window instances
if (plugTarget=="_parent"||plugTarget=="_top"||plugTarget=="_self"||plugTarget=="") {
setInterval('window.location=\''+plugURL+'\'',plugTimer*1000*60);
// for pluginActions iframe instances
} else if (plugTarget=="pluginActions") {
setInterval('document.getElementById(\'pluginActions\').src=\''+plugURL+'\'',plugTimer*1000*60);
// for _blank or named target window instances
} else {
setInterval('window.open(\''+plugURL+'\',\''+plugTarget+'\')',plugTimer*1000*60);
}
}
};

32
lib/editor.css Normal file
View File

@@ -0,0 +1,32 @@
html, body {margin: 0px}
.cm-s-icecoder {font-size: 12px; color: #888; background: #fcfcfc}
.cm-s-icecoder span.cm-keyword {color: #a0a;font-weight:bold}
.cm-s-icecoder span.cm-atom {color: #219;}
.cm-s-icecoder span.cm-number {color: #0a0;}
.cm-s-icecoder span.cm-def {color: #00f;}
.cm-s-icecoder span.cm-variable {color: #a0a;}
.cm-s-icecoder span.cm-variable-2 {color: #a0a;}
.cm-s-icecoder span.cm-variable-3 {color: #0a0;}
.cm-s-icecoder span.cm-property {color: #0a0;}
.cm-s-icecoder span.cm-operator {color: #0a0;}
.cm-s-icecoder span.cm-comment {color: #bbb;}
.cm-s-icecoder span.cm-string {color: #00c;}
.cm-s-icecoder span.cm-string-2 {color: #f50;}
.cm-s-icecoder span.cm-meta {color: #555;}
.cm-s-icecoder span.cm-error {color: #f00;}
.cm-s-icecoder span.cm-qualifier {color: #555;}
.cm-s-icecoder span.cm-builtin {color: #30a;}
.cm-s-icecoder span.cm-bracket {color: #cc7;}
.cm-s-icecoder span.cm-tag {color: #c00;}
.cm-s-icecoder span.cm-attribute {color: #333;}
.cm-s-icecoder span.cm-header {color: #a0a;}
.cm-s-icecoder span.cm-quote {color: #090;}
.cm-s-icecoder span.cm-hr {color: #999;}
.cm-s-icecoder span.cm-link {color: #00c;}
.cm-s-icecoder span.CodeMirror-selected {background: #ffff00 !important; color: #000 !important}
.cm-s-icecoder .CodeMirror-gutter {background: #333; border-right: 1px solid #e8e8e8;}
.cm-s-icecoder .CodeMirror-gutter-text {color: #999; width: 35px}
.cm-s-icecoder .CodeMirror-cursor {border-left: 1px solid black !important;}
.cm-s-icecoder .CodeMirror-matchingbracket{border: 1px solid grey; color: black !important;}

167
lib/file-control.php Normal file
View File

@@ -0,0 +1,167 @@
<?php include("settings.php");?>
<?php
// Establish the full file path reference
$file=$_GET['file'];
$docRoot = str_replace("\\","/",$_SERVER['DOCUMENT_ROOT']);
// Not done the first time we are on the save loop (ie, before the form posting reload)
if ($_GET['action']=="load"||$_GET['action']=="rename"||$_GET['action']=="delete"||isset($_POST['contents'])) {
$file= str_replace("|","/",$file);
}
// If we're due to open a file...
if ($_GET['action']=="load") {
echo '<script>action="load";</script>';
// Determine what to do based on filename
// Everything is opened as text in the editor unless specified otherwise
$fileType="text";
if (strpos($file,".jpg")>0||strpos($file,".jpeg")>0||strpos($file,".gif")>0||strpos($file,".png")>0) {$fileType="image";};
if ($fileType=="text") {
$bannedFile=false;
for ($i=0;$i<count($restrictedFiles);$i++) {
if (strpos($file,$restrictedFiles[$i])!="") {
$bannedFile=true;
}
}
if ($_SESSION['userLevel'] == 10 || ($_SESSION['userLevel'] < 10 && $bannedFile==false)) {
echo '<script>fileType="text";</script>';
$loadedFile = file_get_contents($file);
echo '<textarea name="loadedFile" id="loadedFile">'.$loadedFile.'</textarea>';
} else {
echo '<script>fileType="nothing";</script>';
echo '<script>alert(\'Sorry, you need a higher admin level to view this file\');</script>';
}
};
if ($fileType=="image") {
echo '<script>fileType="image";fileName=\''.$file.'\'</script>';
};
};
// If we're due to rename a file...
if ($_GET['action']=="rename") {
if ($_SESSION['userLevel'] > 0) {
rename($_GET['oldFileName'],$docRoot.$file);
// Reload file manager
echo '<script>top.ICEcoder.selectedFiles=[];top.ICEcoder.filesFrame.src="files.php";action="rename";</script>';
} else {
echo '<script>alert(\'Sorry, you need to be logged in to rename\');</script>';
echo '<script>action="nothing";</script>';
}
}
// If we're due to delete a file...
if ($_GET['action']=="delete") {
if ($_SESSION['userLevel'] > 0) {
$filesArray = split(";",$file); // May contain more than one file here
for ($i=0;$i<=count($filesArray)-1;$i++) {
if (is_dir($docRoot.$filesArray[$i])) {
rrmdir($docRoot.$filesArray[$i]);
} else {
unlink($docRoot.$filesArray[$i]);
}
}
// Reload file manager
echo '<script>top.ICEcoder.selectedFiles=[];top.ICEcoder.filesFrame.src="files.php";</script>';
} else {
echo '<script>alert(\'Sorry, you need to be logged in to delete\');</script>';
echo '<script>action="nothing";</script>';
}
}
// The function to recursively remove folders & files
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
if ($_GET['action']=="save") {
echo '<script>action="save";</script>';
// on the form posting via a reload, save the file
if (isset($_POST['contents'])) {
if ($_SESSION['userLevel'] > 0) {
if (isset($_POST['newFileName'])&&$_POST['newFileName']!="") {
$file = $_POST['newFileName'];
}
$saveFile = str_replace("\\","/",$_SERVER['DOCUMENT_ROOT']).$file;
$saveFile = str_replace("//","/",$saveFile);
$fh = fopen($saveFile, 'w') or die("can't open file");
fwrite($fh, $_POST['contents']);
fclose($fh);
if (isset($_POST['newFileName'])&&$_POST['newFileName']!="") {
// Reload file manager & stop CTRL+s being sticky
echo '<script>top.ICEcoder.selectedFiles=[];top.ICEcoder.filesFrame.src="files.php";</script>';
}
echo '<script>action="doneSave";</script>';
} else {
echo '<script>alert(\'Sorry, you need to be logged in to save\');</script>';
echo '<script>action="nothing";</script>';
}
}
};
?>
<script>
if (action=="load") {
if (fileType=="text") {
// Reset the various states back to their initial setting
selectedTab = top.ICEcoder.openFiles.length; // The tab that's currently selected
// Finally, store all data, show tabs etc
top.ICEcoder.createNewTab();
// Set the value & innerHTML of the code textarea to that of our loaded file plus make it visible (it's hidden on _coder's load)
top.ICEcoder.switchMode();
cM = top.ICEcoder.getcMInstance();
cM.setValue(document.getElementById('loadedFile').value);
cM.clearHistory();
top.document.getElementById('content').style.visibility='visible';
top.ICEcoder.switchTab(top.ICEcoder.selectedTab);
cM.focus();
// Then clean it up, set the text cursor, update the display and get the character data
top.ICEcoder.contentCleanUp();
}
if (fileType=="image") {
top.document.getElementById('blackMask').style.visibility = "visible";
top.document.getElementById('mediaContainer').innerHTML = "<img src=\"<?php echo str_replace($docRoot,"",$file);?>\" style=\"border: solid 10px #ffffff; max-width: 700px; max-height: 500px\" onClick=\"return false\"><br><span style=\"border: solid 10px #ffffff; background-color: #ffffff\" onClick=\"return false\"><?php echo str_replace($docRoot,"",$file);?></span>";
}
}
</script>
<form name="saveFile" action="file-control.php?action=save&file=<?php if (isset($file)) {echo $file;};?>" method="POST">
<textarea name="contents"></textarea>
<input type="hidden" name="newFileName" value="">
</form>
<script>
if (action=="save") {
<?php
if ($file=="|[NEW]") {
echo 'newFileName = prompt(\'Enter Filename\',\'/\');';
echo 'document.saveFile.newFileName.value = newFileName;';
}
?>
cM = top.ICEcoder.getcMInstance();
document.saveFile.contents.innerHTML = cM.getValue();
document.saveFile.submit();
}
</script>
<script>
if (action=="doneSave") {
top.ICEcoder.changedContent[top.ICEcoder.selectedTab-1] = 0;
top.ICEcoder.redoTabHighlight(top.ICEcoder.selectedTab);
}
</script>

98
lib/files.css Normal file
View File

@@ -0,0 +1,98 @@
/* First, reset everything to a standard */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
font-family: arial, verdana, helvetica, sans-serif;
border: 0px;
margin: 0px;
padding: 0px;
outline: 0px;
font-size: 12px;
vertical-align: top;
}
body {margin: 0px; overflow: auto}
.fileManager {
margin: 15px 0px 15px 22px;
-webkit-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
.fileManager span {font-family: helvetica, arial, swiss, verdana;}
.fileManager a {color: #000000; text-decoration: none;}
.fileManager .open {font-style: italic;}
.fileManager .closed {font-style: normal;}
.fileManager .pft-directory {list-style-image: url(../images/file-manager-icons/directory.png);}
.fileManager li {margin-left: 15px;}
/* Default file */
.fileManager LI.pft-file { list-style-image: url(../images/file-manager-icons/file.png); cursor: pointer;}
/* Additional file types */
.fileManager LI.ext-3gp { list-style-image: url(../images/file-manager-icons/film.png); }
.fileManager LI.ext-afp { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-afpa { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-asp { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-aspx { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-avi { list-style-image: url(../images/file-manager-icons/film.png); }
.fileManager LI.ext-bat { list-style-image: url(../images/file-manager-icons/application.png); }
.fileManager LI.ext-bmp { list-style-image: url(../images/file-manager-icons/picture.png); }
.fileManager LI.ext-c { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-cfm { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-cgi { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-com { list-style-image: url(../images/file-manager-icons/application.png); }
.fileManager LI.ext-cpp { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-css { list-style-image: url(../images/file-manager-icons/css.png); }
.fileManager LI.ext-doc { list-style-image: url(../images/file-manager-icons/doc.png); }
.fileManager LI.ext-exe { list-style-image: url(../images/file-manager-icons/application.png); }
.fileManager LI.ext-gif { list-style-image: url(../images/file-manager-icons/picture.png); }
.fileManager LI.ext-fla { list-style-image: url(../images/file-manager-icons/flash.png); }
.fileManager LI.ext-h { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-htm { list-style-image: url(../images/file-manager-icons/html.png); }
.fileManager LI.ext-html { list-style-image: url(../images/file-manager-icons/html.png); }
.fileManager LI.ext-jar { list-style-image: url(../images/file-manager-icons/java.png); }
.fileManager LI.ext-jpg { list-style-image: url(../images/file-manager-icons/picture.png); }
.fileManager LI.ext-jpeg { list-style-image: url(../images/file-manager-icons/picture.png); }
.fileManager LI.ext-js { list-style-image: url(../images/file-manager-icons/script.png); }
.fileManager LI.ext-lasso { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-log { list-style-image: url(../images/file-manager-icons/txt.png); }
.fileManager LI.ext-m4p { list-style-image: url(../images/file-manager-icons/music.png); }
.fileManager LI.ext-mov { list-style-image: url(../images/file-manager-icons/film.png); }
.fileManager LI.ext-mp3 { list-style-image: url(../images/file-manager-icons/music.png); }
.fileManager LI.ext-mp4 { list-style-image: url(../images/file-manager-icons/film.png); }
.fileManager LI.ext-mpg { list-style-image: url(../images/file-manager-icons/film.png); }
.fileManager LI.ext-mpeg { list-style-image: url(../images/file-manager-icons/film.png); }
.fileManager LI.ext-ogg { list-style-image: url(../images/file-manager-icons/music.png); }
.fileManager LI.ext-pcx { list-style-image: url(../images/file-manager-icons/picture.png); }
.fileManager LI.ext-pdf { list-style-image: url(../images/file-manager-icons/pdf.png); }
.fileManager LI.ext-php { list-style-image: url(../images/file-manager-icons/php.png); }
.fileManager LI.ext-png { list-style-image: url(../images/file-manager-icons/picture.png); }
.fileManager LI.ext-ppt { list-style-image: url(../images/file-manager-icons/ppt.png); }
.fileManager LI.ext-psd { list-style-image: url(../images/file-manager-icons/psd.png); }
.fileManager LI.ext-pl { list-style-image: url(../images/file-manager-icons/script.png); }
.fileManager LI.ext-py { list-style-image: url(../images/file-manager-icons/script.png); }
.fileManager LI.ext-rb { list-style-image: url(../images/file-manager-icons/ruby.png); }
.fileManager LI.ext-rbx { list-style-image: url(../images/file-manager-icons/ruby.png); }
.fileManager LI.ext-rhtml { list-style-image: url(../images/file-manager-icons/ruby.png); }
.fileManager LI.ext-rpm { list-style-image: url(../images/file-manager-icons/linux.png); }
.fileManager LI.ext-ruby { list-style-image: url(../images/file-manager-icons/ruby.png); }
.fileManager LI.ext-sql { list-style-image: url(../images/file-manager-icons/db.png); }
.fileManager LI.ext-swf { list-style-image: url(../images/file-manager-icons/flash.png); }
.fileManager LI.ext-tif { list-style-image: url(../images/file-manager-icons/picture.png); }
.fileManager LI.ext-tiff { list-style-image: url(../images/file-manager-icons/picture.png); }
.fileManager LI.ext-txt { list-style-image: url(../images/file-manager-icons/txt.png); }
.fileManager LI.ext-vb { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-wav { list-style-image: url(../images/file-manager-icons/music.png); }
.fileManager LI.ext-wmv { list-style-image: url(../images/file-manager-icons/film.png); }
.fileManager LI.ext-xls { list-style-image: url(../images/file-manager-icons/xls.png); }
.fileManager LI.ext-xml { list-style-image: url(../images/file-manager-icons/code.png); }
.fileManager LI.ext-zip { list-style-image: url(../images/file-manager-icons/zip.png); }

37
lib/settings.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
$versionNo = "v 0.5.0";
$codeMirrorDir = "CodeMirror-2.2";
$cMThisVer = 2.2;
$testcMVersion = false; // test if we're using the latest CodeMirror version
$restrictedFiles = array(".php",".asp",".aspx");
$bannedFiles = array("_coder","wp-",".exe");
$allowedIPs = array("*"); // allowed IPs, * for any
$plugins = array(
array("Database Admin","images/database.png","margin-top: 3px","plugins/adminer/adminer-3.3.3-mysql-en.php","_blank",""),
array("Batch Image Processor","images/images.png","margin-top: 5px","http://birme.net","_blank",""),
array("Backup","images/backup-open-files.png","margin-top: 3px","plugins/backupOpenFiles/index.php","pluginActions","10"),
array("Clipboard","images/clipboard.png","","javascript:alert('Doesn\'t do anything yet but will be a clipboard for copied text items, up to 100 levels')","_self","")
);
// Establish our user level
if (!isset($_SESSION['userLevel'])) {
session_start();
$_SESSION['userLevel'] = 0;
}
if(isset($_GET['login']) && $_GET['login']=="acesHigh") {$_SESSION['userLevel'] = 10;};
$_SESSION['userLevel'] = $_SESSION['userLevel'];
if (!isset($_SESSION['restrictedFiles'])) {$_SESSION['restrictedFiles'] = $restrictedFiles;}
if (!isset($_SESSION['bannedFiles'])) {$_SESSION['bannedFiles'] = $bannedFiles;}
// Establish our shortened URL, explode the path based on server type (Linux or Windows)
if (strpos($_SERVER['DOCUMENT_ROOT'],"/")>-1) {$slashType = "/";} else {$slashType = "\\";};
$shortURLStarts = explode($slashType,$_SERVER['DOCUMENT_ROOT']);
// Then clear item at the end if there is one, plus trailing slash
// We end up with the directory name of the server root
if ($shortURLStarts[count($shortURLStarts)-1]!="") {$trimArray=1;} else {$trimArray=2;}
$shortURLStarts = $shortURLStarts[count($shortURLStarts)-$trimArray];
?>

View File

@@ -0,0 +1,877 @@
<?php
/** Adminer - Compact database management
* @link http://www.adminer.org/
* @author Jakub Vrana, http://www.vrana.cz/
* @copyright 2007 Jakub Vrana
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
* @version 3.3.3
*/error_reporting(6135);$Tb=(!ereg('^(unsafe_raw)?$',ini_get("filter.default")));if($Tb||ini_get("filter.default_flags")){foreach(array('_GET','_POST','_COOKIE','_SERVER')as$X){$xf=filter_input_array(constant("INPUT$X"),FILTER_UNSAFE_RAW);if($xf){$$X=$xf;}}}if(isset($_GET["file"])){header("Expires: ".gmdate("D, d M Y H:i:s",time()+365*24*60*60)." GMT");if($_GET["file"]=="favicon.ico"){header("Content-Type: image/x-icon");echo
base64_decode("AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AAAA/wBhTgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAERERAAAAAAETMzEQAAAAATERExAAAAABMRETEAAAAAExERMQAAAAATERExAAAAABMRETEAAAAAEzMzMREREQATERExEhEhABEzMxEhEREAAREREhERIRAAAAARIRESEAAAAAESEiEQAAAAABEREQAAAAAAAAAAD//9UAwP/VAIB/AACAf/AAgH+kAIB/gACAfwAAgH8AAIABAACAAf8AgAH/AMAA/wD+AP8A/wAIAf+B1QD//9UA");}elseif($_GET["file"]=="default.css"){header("Content-Type: text/css; charset=utf-8");echo'body{color:#000;background:#fff;font:90%/1.25 Verdana,Arial,Helvetica,sans-serif;margin:0;}a{color:blue;}a:visited{color:navy;}a:hover{color:red;}h1{font-size:150%;margin:0;padding:.8em 1em;border-bottom:1px solid #999;font-weight:normal;color:#777;background:#eee;}h2{font-size:150%;margin:0 0 20px -18px;padding:.8em 1em;border-bottom:1px solid #000;color:#000;font-weight:normal;background:#ddf;}h3{font-weight:normal;font-size:130%;margin:1em 0 0;}form{margin:0;}table{margin:1em 20px 0 0;border:0;border-top:1px solid #999;border-left:1px solid #999;font-size:90%;}td,th{border:0;border-right:1px solid #999;border-bottom:1px solid #999;padding:.2em .3em;}th{background:#eee;text-align:left;}thead th{text-align:center;}thead td,thead th{background:#ddf;}fieldset{display:inline;vertical-align:top;padding:.5em .8em;margin:.8em .5em 0 0;border:1px solid #999;}p{margin:.8em 20px 0 0;}img{vertical-align:middle;border:0;}td img{max-width:200px;max-height:200px;}code{background:#eee;}tbody tr:hover td,tbody tr:hover th{background:#eee;}pre{margin:1em 0 0;}input[type=image]{vertical-align:middle;}.version{color:#777;font-size:67%;}.js .hidden,.nojs .jsonly{display:none;}.nowrap td,.nowrap th,td.nowrap{white-space:pre;}.wrap td{white-space:normal;}.error{color:red;background:#fee;}.error b{background:#fff;font-weight:normal;}.message{color:green;background:#efe;}.error,.message{padding:.5em .8em;margin:1em 20px 0 0;}.char{color:#007F00;}.date{color:#7F007F;}.enum{color:#007F7F;}.binary{color:red;}.odd td{background:#F5F5F5;}.js .checked td,.js .checked th{background:#ddf;}.time{color:silver;font-size:70%;}.function{text-align:right;}.number{text-align:right;}.datetime{text-align:right;}.type{width:15ex;width:auto\\9;}.options select{width:20ex;width:auto\\9;}.active{font-weight:bold;}.sqlarea{width:98%;}#menu{position:absolute;margin:10px 0 0;padding:0 0 30px 0;top:2em;left:0;width:19em;overflow:auto;overflow-y:hidden;white-space:nowrap;}#menu p{padding:.8em 1em;margin:0;border-bottom:1px solid #ccc;}#content{margin:2em 0 0 21em;padding:10px 20px 20px 0;}#lang{position:absolute;top:0;left:0;line-height:1.8em;padding:.3em 1em;}#breadcrumb{white-space:nowrap;position:absolute;top:0;left:21em;background:#eee;height:2em;line-height:1.8em;padding:0 1em;margin:0 0 0 -18px;}#loader{position:fixed;top:0;left:18em;z-index:1;}#h1{color:#777;text-decoration:none;font-style:italic;}#version{font-size:67%;color:red;}#schema{margin-left:60px;position:relative;}#schema .table{border:1px solid silver;padding:0 2px;cursor:move;position:absolute;}#schema .references{position:absolute;}.rtl h2{margin:0 -18px 20px 0;}.rtl p,.rtl table,.rtl .error,.rtl .message{margin:1em 0 0 20px;}.rtl #content{margin:2em 21em 0 0;padding:10px 0 20px 20px;}.rtl #breadcrumb{left:auto;right:21em;margin:0 -18px 0 0;}.rtl #lang,.rtl #menu{left:auto;right:0;}@media print{#lang,#menu{display:none;}#content{margin-left:1em;}#breadcrumb{left:1em;}.nowrap td,.nowrap th,td.nowrap{white-space:normal;}}';}elseif($_GET["file"]=="functions.js"){header("Content-Type: text/javascript; charset=utf-8");?>
function toggle(id){var el=document.getElementById(id);el.className=(el.className=='hidden'?'':'hidden');return true;}
function cookie(assign,days){var date=new Date();date.setDate(date.getDate()+days);document.cookie=assign+'; expires='+date;}
function verifyVersion(){cookie('adminer_version=0',1);var script=document.createElement('script');script.src=location.protocol+'//www.adminer.org/version.php';document.body.appendChild(script);}
function selectValue(select){var selected=select.options[select.selectedIndex];return((selected.attributes.value||{}).specified?selected.value:selected.text);}
function trCheck(el){var tr=el.parentNode.parentNode;tr.className=tr.className.replace(/(^|\s)checked(\s|$)/,'$2')+(el.checked?' checked':'');}
function formCheck(el,name){var elems=el.form.elements;for(var i=0;i<elems.length;i++){if(name.test(elems[i].name)){elems[i].checked=el.checked;trCheck(elems[i]);}}}
function tableCheck(){var tables=document.getElementsByTagName('table');for(var i=0;i<tables.length;i++){if(/(^|\s)checkable(\s|$)/.test(tables[i].className)){var trs=tables[i].getElementsByTagName('tr');for(var j=0;j<trs.length;j++){trCheck(trs[j].firstChild.firstChild);}}}}
function formUncheck(id){var el=document.getElementById(id);el.checked=false;trCheck(el);}
function formChecked(el,name){var checked=0;var elems=el.form.elements;for(var i=0;i<elems.length;i++){if(name.test(elems[i].name)&&elems[i].checked){checked++;}}
return checked;}
function tableClick(event){var click=true;var el=event.target||event.srcElement;while(!/^tr$/i.test(el.tagName)){if(/^table$/i.test(el.tagName)){return;}
if(/^(a|input|textarea)$/i.test(el.tagName)){click=false;}
el=el.parentNode;}
el=el.firstChild.firstChild;if(click){el.click&&el.click();el.onclick&&el.onclick();}
trCheck(el);}
function setHtml(id,html){var el=document.getElementById(id);if(el){if(html==undefined){el.parentNode.innerHTML='&nbsp;';}else{el.innerHTML=html;}}}
function nodePosition(el){var pos=0;while(el=el.previousSibling){pos++;}
return pos;}
function pageClick(href,page,event){if(!isNaN(page)&&page){href+=(page!=1?'&page='+(page-1):'');if(!ajaxSend(href)){location.href=href;}}}
function selectAddRow(field){field.onchange=function(){};var row=field.parentNode.cloneNode(true);var selects=row.getElementsByTagName('select');for(var i=0;i<selects.length;i++){selects[i].name=selects[i].name.replace(/[a-z]\[\d+/,'$&1');selects[i].selectedIndex=0;}
var inputs=row.getElementsByTagName('input');if(inputs.length){inputs[0].name=inputs[0].name.replace(/[a-z]\[\d+/,'$&1');inputs[0].value='';inputs[0].className='';}
field.parentNode.parentNode.appendChild(row);}
function bodyKeydown(event,button){var target=event.target||event.srcElement;if(event.ctrlKey&&(event.keyCode==13||event.keyCode==10)&&!event.altKey&&!event.metaKey&&/select|textarea|input/i.test(target.tagName)){target.blur();if(!ajaxForm(target.form,(button?button+'=1':''))){if(button){target.form[button].click();}else{target.form.submit();}}
return false;}
return true;}
function editingKeydown(event){if((event.keyCode==40||event.keyCode==38)&&event.ctrlKey&&!event.altKey&&!event.metaKey){var target=event.target||event.srcElement;var sibling=(event.keyCode==40?'nextSibling':'previousSibling');var el=target.parentNode.parentNode[sibling];if(el&&(/^tr$/i.test(el.tagName)||(el=el[sibling]))&&/^tr$/i.test(el.tagName)&&(el=el.childNodes[nodePosition(target.parentNode)])&&(el=el.childNodes[nodePosition(target)])){el.focus();}
return false;}
if(event.shiftKey&&!bodyKeydown(event,'insert')){eventStop(event);return false;}
return true;}
function functionChange(select){var input=select.form[select.name.replace(/^function/,'fields')];if(selectValue(select)){if(input.origMaxLength===undefined){input.origMaxLength=input.maxLength;}
input.removeAttribute('maxlength');}else if(input.origMaxLength>=0){input.maxLength=input.origMaxLength;}}
function ajax(url,callback,data){var xmlhttp=(window.XMLHttpRequest?new XMLHttpRequest():(window.ActiveXObject?new ActiveXObject('Microsoft.XMLHTTP'):false));if(xmlhttp){xmlhttp.open((data?'POST':'GET'),url);if(data){xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}
xmlhttp.setRequestHeader('X-Requested-With','XMLHttpRequest');xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){callback(xmlhttp);}};xmlhttp.send(data);}
return xmlhttp;}
function ajaxSetHtml(url){return ajax(url,function(xmlhttp){if(xmlhttp.status){var data=eval('('+xmlhttp.responseText+')');for(var key in data){setHtml(key,data[key]);}}});}
var originalFavicon;function replaceFavicon(href){var favicon=document.getElementById('favicon');if(favicon){favicon.href=href;favicon.parentNode.appendChild(favicon);}}
var ajaxState=0;function ajaxSend(url,data,popState,noscroll){if(!history.pushState){return false;}
var currentState=++ajaxState;onblur=function(){if(!originalFavicon){originalFavicon=(document.getElementById('favicon')||{}).href;}
replaceFavicon(location.pathname+'?file=loader.gif&amp;version=3.3.3');};setHtml('loader','<img src="'+location.pathname+'?file=loader.gif&amp;version=3.3.3" alt="">');return ajax(url,function(xmlhttp){if(currentState==ajaxState){var title=xmlhttp.getResponseHeader('X-AJAX-Title');if(title){document.title=decodeURIComponent(title);}
var redirect=xmlhttp.getResponseHeader('X-AJAX-Redirect');if(redirect){return ajaxSend(redirect,'',popState);}
onblur=function(){};if(originalFavicon){replaceFavicon(originalFavicon);}
if(!xmlhttp.status){setHtml('loader','');}else{if(!popState){if(data||url!=location.href){history.pushState(data,'',url);}}
if(!noscroll&&!/&order/.test(url)){scrollTo(0,0);}
setHtml('content',xmlhttp.responseText);var content=document.getElementById('content');var scripts=content.getElementsByTagName('script');var length=scripts.length;for(var i=0;i<length;i++){var script=document.createElement('script');script.text=scripts[i].text;content.appendChild(script);}
var as=document.getElementById('menu').getElementsByTagName('a');var href=location.href.replace(/(&(sql=|dump=|(select|table)=[^&]*)).*/,'$1');for(var i=0;i<as.length;i++){as[i].className=(href==as[i].href?'active':'');}
var dump=document.getElementById('dump');if(dump){var match=/&(select|table)=([^&]+)/.exec(href);dump.href=dump.href.replace(/[^=]+$/,'')+(match?match[2]:'');}
if(window.jush){jush.highlight_tag('code',0);}}}},data);}
onpopstate=function(event){if((ajaxState||event.state)&&!/#/.test(location.href)){ajaxSend(location.href,(event.state&&confirm(areYouSure)?event.state:''),1);}else{ajaxState++;}};function ajaxForm(form,data,noscroll){if((/&(database|scheme|create|view|sql|user|dump|call)=/.test(location.href)&&!/\./.test(data))||(form.onsubmit&&form.onsubmit()===false)){return false;}
var params=[];for(var i=0;i<form.elements.length;i++){var el=form.elements[i];if(/file/i.test(el.type)&&el.value){return false;}else if(el.name&&(!/checkbox|radio|submit|file/i.test(el.type)||el.checked)){params.push(encodeURIComponent(el.name)+'='+encodeURIComponent(/select/i.test(el.tagName)?selectValue(el):el.value));}}
if(data){params.push(data);}
if(form.method=='post'){return ajaxSend((/\?/.test(form.action)?form.action:location.href),params.join('&'),false,noscroll);}
return ajaxSend((form.action||location.href).replace(/\?.*/,'')+'?'+params.join('&'),'',false,noscroll);}
function selectDblClick(td,event,text){if(/input|textarea/i.test(td.firstChild.tagName)){return;}
var original=td.innerHTML;var input=document.createElement(text?'textarea':'input');input.onkeydown=function(event){if(!event){event=window.event;}
if(event.keyCode==27&&!(event.ctrlKey||event.shiftKey||event.altKey||event.metaKey)){td.innerHTML=original;}};var pos=event.rangeOffset;var value=td.firstChild.alt||td.textContent||td.innerText;input.style.width=Math.max(td.clientWidth-14,20)+'px';if(text){var rows=1;value.replace(/\n/g,function(){rows++;});input.rows=rows;}
if(value=='\u00A0'||td.getElementsByTagName('i').length){value='';}
if(document.selection){var range=document.selection.createRange();range.moveToPoint(event.clientX,event.clientY);var range2=range.duplicate();range2.moveToElementText(td);range2.setEndPoint('EndToEnd',range);pos=range2.text.length;}
td.innerHTML='';td.appendChild(input);input.focus();if(text==2){return ajax(location.href+'&'+encodeURIComponent(td.id)+'=',function(xmlhttp){if(xmlhttp.status){input.value=xmlhttp.responseText;input.name=td.id;}});}
input.value=value;input.name=td.id;input.selectionStart=pos;input.selectionEnd=pos;if(document.selection){var range=document.selection.createRange();range.moveEnd('character',-input.value.length+pos);range.select();}}
function bodyClick(event,db,ns){if(event.button||event.ctrlKey||event.shiftKey||event.altKey||event.metaKey){return;}
if(event.getPreventDefault?event.getPreventDefault():event.returnValue===false||event.defaultPrevented){return false;}
var el=event.target||event.srcElement;if(/^a$/i.test(el.parentNode.tagName)){el=el.parentNode;}
if(/^a$/i.test(el.tagName)&&!/:|#|&download=/i.test(el.getAttribute('href'))&&/[&?]username=/.test(el.href)){var match=/&db=([^&]*)/.exec(el.href);var match2=/&ns=([^&]*)/.exec(el.href);return!(db==(match?match[1]:'')&&ns==(match2?match2[1]:'')&&ajaxSend(el.href));}
if(/^input$/i.test(el.tagName)&&/image|submit/.test(el.type)){return!ajaxForm(el.form,(el.name?encodeURIComponent(el.name)+(el.type=='image'?'.x':'')+'=1':''),el.type=='image');}
return true;}
function eventStop(event){if(event.stopPropagation){event.stopPropagation();}else{event.cancelBubble=true;}}
var jushRoot=location.protocol + '//www.adminer.org/static/';function bodyLoad(version){if(history.state!==undefined){onpopstate(history);}
if(jushRoot){var script=document.createElement('script');script.src=jushRoot+'jush.js';script.onload=function(){if(window.jush){jush.create_links=' target="_blank" rel="noreferrer"';jush.urls.sql_sqlset=jush.urls.sql[0]=jush.urls.sqlset[0]=jush.urls.sqlstatus[0]='http://dev.mysql.com/doc/refman/'+version+'/en/$key';var pgsql='http://www.postgresql.org/docs/'+version+'/static/';jush.urls.pgsql_pgsqlset=jush.urls.pgsql[0]=pgsql+'$key';jush.urls.pgsqlset[0]=pgsql+'runtime-config-$key.html#GUC-$1';jush.style(jushRoot+'jush.css');if(window.jushLinks){jush.custom_links=jushLinks;}
jush.highlight_tag('code',0);}};script.onreadystatechange=function(){if(/^(loaded|complete)$/.test(script.readyState)){script.onload();}};document.body.appendChild(script);}}
function formField(form,name){for(var i=0;i<form.length;i++){if(form[i].name==name){return form[i];}}}
function typePassword(el,disable){try{el.type=(disable?'text':'password');}catch(e){}}
function loginDriver(driver){var trs=driver.parentNode.parentNode.parentNode.rows;for(var i=1;i<trs.length;i++){trs[i].className=(/sqlite/.test(driver.value)?'hidden':'');}}
function textareaKeydown(target,event){if(!event.shiftKey&&!event.altKey&&!event.ctrlKey&&!event.metaKey){if(event.keyCode==9){if(target.setSelectionRange){var start=target.selectionStart;var scrolled=target.scrollTop;target.value=target.value.substr(0,start)+'\t'+target.value.substr(target.selectionEnd);target.setSelectionRange(start+1,start+1);target.scrollTop=scrolled;return false;}else if(target.createTextRange){document.selection.createRange().text='\t';return false;}}
if(event.keyCode==27){var els=target.form.elements;for(var i=1;i<els.length;i++){if(els[i-1]==target){els[i].focus();break;}}
return false;}}
return true;}
var added='.',rowCount;function delimiterEqual(val,a,b){return(val==a+'_'+b||val==a+b||val==a+b.charAt(0).toUpperCase()+b.substr(1));}
function idfEscape(s){return s.replace(/`/,'``');}
function editingNameChange(field){var name=field.name.substr(0,field.name.length-7);var type=formField(field.form,name+'[type]');var opts=type.options;var candidate;var val=field.value;for(var i=opts.length;i--;){var match=/(.+)`(.+)/.exec(opts[i].value);if(!match){if(candidate&&i==opts.length-2&&val==opts[candidate].value.replace(/.+`/,'')&&name=='fields[1]'){return;}
break;}
var table=match[1];var column=match[2];var tables=[table,table.replace(/s$/,''),table.replace(/es$/,'')];for(var j=0;j<tables.length;j++){table=tables[j];if(val==column||val==table||delimiterEqual(val,table,column)||delimiterEqual(val,column,table)){if(candidate){return;}
candidate=i;break;}}}
if(candidate){type.selectedIndex=candidate;type.onchange();}}
function editingAddRow(button,allowed,focus){if(allowed&&rowCount>=allowed){return false;}
var match=/(\d+)(\.\d+)?/.exec(button.name);var x=match[0]+(match[2]?added.substr(match[2].length):added)+'1';var row=button.parentNode.parentNode;var row2=row.cloneNode(true);var tags=row.getElementsByTagName('select');var tags2=row2.getElementsByTagName('select');for(var i=0;i<tags.length;i++){tags2[i].name=tags[i].name.replace(/([0-9.]+)/,x);tags2[i].selectedIndex=tags[i].selectedIndex;}
tags=row.getElementsByTagName('input');tags2=row2.getElementsByTagName('input');var input=tags2[0];for(var i=0;i<tags.length;i++){if(tags[i].name=='auto_increment_col'){tags2[i].value=x;tags2[i].checked=false;}
tags2[i].name=tags[i].name.replace(/([0-9.]+)/,x);if(/\[(orig|field|comment|default)/.test(tags[i].name)){tags2[i].value='';}
if(/\[(has_default)/.test(tags[i].name)){tags2[i].checked=false;}}
tags[0].onchange=function(){editingNameChange(tags[0]);};row.parentNode.insertBefore(row2,row.nextSibling);if(focus){input.onchange=function(){editingNameChange(input);};input.focus();}
added+='0';rowCount++;return true;}
function editingRemoveRow(button){var field=formField(button.form,button.name.replace(/drop_col(.+)/,'fields$1[field]'));field.parentNode.removeChild(field);button.parentNode.parentNode.style.display='none';return true;}
var lastType='';function editingTypeChange(type){var name=type.name.substr(0,type.name.length-6);var text=selectValue(type);for(var i=0;i<type.form.elements.length;i++){var el=type.form.elements[i];if(el.name==name+'[length]'&&!((/(char|binary)$/.test(lastType)&&/(char|binary)$/.test(text))||(/(enum|set)$/.test(lastType)&&/(enum|set)$/.test(text)))){el.value='';}
if(lastType=='timestamp'&&el.name==name+'[has_default]'&&/timestamp/i.test(formField(type.form,name+'[default]').value)){el.checked=false;}
if(el.name==name+'[collation]'){el.className=(/(char|text|enum|set)$/.test(text)?'':'hidden');}
if(el.name==name+'[unsigned]'){el.className=(/(int|float|double|decimal)$/.test(text)?'':'hidden');}
if(el.name==name+'[on_delete]'){el.className=(/`/.test(text)?'':'hidden');}}}
function editingLengthFocus(field){var td=field.parentNode;if(/(enum|set)$/.test(selectValue(td.previousSibling.firstChild))){var edit=document.getElementById('enum-edit');var val=field.value;edit.value=(/^'.+','.+'$/.test(val)?val.substr(1,val.length-2).replace(/','/g,"\n").replace(/''/g,"'"):val);td.appendChild(edit);field.style.display='none';edit.style.display='inline';edit.focus();}}
function editingLengthBlur(edit){var field=edit.parentNode.firstChild;var val=edit.value;field.value=(/\n/.test(val)?"'"+val.replace(/\n+$/,'').replace(/'/g,"''").replace(/\n/g,"','")+"'":val);field.style.display='inline';edit.style.display='none';}
function columnShow(checked,column){var trs=document.getElementById('edit-fields').getElementsByTagName('tr');for(var i=0;i<trs.length;i++){trs[i].getElementsByTagName('td')[column].className=(checked?'':'hidden');}}
function partitionByChange(el){var partitionTable=/RANGE|LIST/.test(selectValue(el));el.form['partitions'].className=(partitionTable||!el.selectedIndex?'hidden':'');document.getElementById('partition-table').className=(partitionTable?'':'hidden');}
function partitionNameChange(el){var row=el.parentNode.parentNode.cloneNode(true);row.firstChild.firstChild.value='';el.parentNode.parentNode.parentNode.appendChild(row);el.onchange=function(){};}
function foreignAddRow(field){field.onchange=function(){};var row=field.parentNode.parentNode.cloneNode(true);var selects=row.getElementsByTagName('select');for(var i=0;i<selects.length;i++){selects[i].name=selects[i].name.replace(/\]/,'1$&');selects[i].selectedIndex=0;}
field.parentNode.parentNode.parentNode.appendChild(row);}
function indexesAddRow(field){field.onchange=function(){};var parent=field.parentNode.parentNode;var row=parent.cloneNode(true);var selects=row.getElementsByTagName('select');for(var i=0;i<selects.length;i++){selects[i].name=selects[i].name.replace(/indexes\[\d+/,'$&1');selects[i].selectedIndex=0;}
var inputs=row.getElementsByTagName('input');for(var i=0;i<inputs.length;i++){inputs[i].name=inputs[i].name.replace(/indexes\[\d+/,'$&1');inputs[i].value='';}
parent.parentNode.appendChild(row);}
function indexesChangeColumn(field,prefix){var columns=field.parentNode.parentNode.getElementsByTagName('select');var names=[];for(var i=0;i<columns.length;i++){var value=selectValue(columns[i]);if(value){names.push(value);}}
field.form[field.name.replace(/\].*/,'][name]')].value=prefix+names.join('_');}
function indexesAddColumn(field,prefix){field.onchange=function(){indexesChangeColumn(field,prefix);};var select=field.form[field.name.replace(/\].*/,'][type]')];if(!select.selectedIndex){select.selectedIndex=3;select.onchange();}
var column=field.parentNode.cloneNode(true);select=column.getElementsByTagName('select')[0];select.name=select.name.replace(/\]\[\d+/,'$&1');select.selectedIndex=0;var input=column.getElementsByTagName('input')[0];input.name=input.name.replace(/\]\[\d+/,'$&1');input.value='';field.parentNode.parentNode.appendChild(column);field.onchange();}
var that,x,y,em,tablePos;function schemaMousedown(el,event){that=el;x=event.clientX-el.offsetLeft;y=event.clientY-el.offsetTop;}
function schemaMousemove(ev){if(that!==undefined){ev=ev||event;var left=(ev.clientX-x)/em;var top=(ev.clientY-y)/em;var divs=that.getElementsByTagName('div');var lineSet={};for(var i=0;i<divs.length;i++){if(divs[i].className=='references'){var div2=document.getElementById((divs[i].id.substr(0,4)=='refs'?'refd':'refs')+divs[i].id.substr(4));var ref=(tablePos[divs[i].title]?tablePos[divs[i].title]:[div2.parentNode.offsetTop/em,0]);var left1=-1;var isTop=true;var id=divs[i].id.replace(/^ref.(.+)-.+/,'$1');if(divs[i].parentNode!=div2.parentNode){left1=Math.min(0,ref[1]-left)-1;divs[i].style.left=left1+'em';divs[i].getElementsByTagName('div')[0].style.width=-left1+'em';var left2=Math.min(0,left-ref[1])-1;div2.style.left=left2+'em';div2.getElementsByTagName('div')[0].style.width=-left2+'em';isTop=(div2.offsetTop+ref[0]*em>divs[i].offsetTop+top*em);}
if(!lineSet[id]){var line=document.getElementById(divs[i].id.replace(/^....(.+)-\d+$/,'refl$1'));var shift=ev.clientY-y-that.offsetTop;line.style.left=(left+left1)+'em';if(isTop){line.style.top=(line.offsetTop+shift)/em+'em';}
if(divs[i].parentNode!=div2.parentNode){line=line.getElementsByTagName('div')[0];line.style.height=(line.offsetHeight+(isTop?-1:1)*shift)/em+'em';}
lineSet[id]=true;}}}
that.style.left=left+'em';that.style.top=top+'em';}}
function schemaMouseup(ev,db){if(that!==undefined){ev=ev||event;tablePos[that.firstChild.firstChild.firstChild.data]=[(ev.clientY-y)/em,(ev.clientX-x)/em];that=undefined;var s='';for(var key in tablePos){s+='_'+key+':'+Math.round(tablePos[key][0]*10000)/10000+'x'+Math.round(tablePos[key][1]*10000)/10000;}
s=encodeURIComponent(s.substr(1));var link=document.getElementById('schema-link');link.href=link.href.replace(/[^=]+$/,'')+s;cookie('adminer_schema-'+db+'='+s,30);}}<?php
}else{header("Content-Type: image/gif");switch($_GET["file"]){case"plus.gif":echo
base64_decode("R0lGODdhEgASAKEAAO7u7gAAAJmZmQAAACwAAAAAEgASAAACIYSPqcvtD00I8cwqKb5v+q8pIAhxlRmhZYi17iPE8kzLBQA7");break;case"cross.gif":echo
base64_decode("R0lGODdhEgASAKEAAO7u7gAAAJmZmQAAACwAAAAAEgASAAACI4SPqcvtDyMKYdZGb355wy6BX3dhlOEx57FK7gtHwkzXNl0AADs=");break;case"up.gif":echo
base64_decode("R0lGODdhEgASAKEAAO7u7gAAAJmZmQAAACwAAAAAEgASAAACIISPqcvtD00IUU4K730T9J5hFTiKEXmaYcW2rgDH8hwXADs=");break;case"down.gif":echo
base64_decode("R0lGODdhEgASAKEAAO7u7gAAAJmZmQAAACwAAAAAEgASAAACIISPqcvtD00I8cwqKb5bV/5cosdMJtmcHca2lQDH8hwXADs=");break;case"arrow.gif":echo
base64_decode("R0lGODlhCAAKAIAAAICAgP///yH5BAEAAAEALAAAAAAIAAoAAAIPBIJplrGLnpQRqtOy3rsAADs=");break;case"loader.gif":echo
base64_decode("R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==");break;}}exit;}function
connection(){global$e;return$e;}function
adminer(){global$b;return$b;}function
idf_unescape($lc){$Ac=substr($lc,-1);return
str_replace($Ac.$Ac,$Ac,substr($lc,1,-1));}function
escape_string($X){return
substr(q($X),1,-1);}function
remove_slashes($Yd,$Tb=false){if(get_magic_quotes_gpc()){while(list($y,$X)=each($Yd)){foreach($X
as$xc=>$W){unset($Yd[$y][$xc]);if(is_array($W)){$Yd[$y][stripslashes($xc)]=$W;$Yd[]=&$Yd[$y][stripslashes($xc)];}else{$Yd[$y][stripslashes($xc)]=($Tb?$W:stripslashes($W));}}}}}function
bracket_escape($lc,$wa=false){static$kf=array(':'=>':1',']'=>':2','['=>':3');return
strtr($lc,($wa?array_flip($kf):$kf));}function
h($Q){return
htmlspecialchars(str_replace("\0","",$Q),ENT_QUOTES);}function
nbsp($Q){return(trim($Q)!=""?h($Q):"&nbsp;");}function
nl_br($Q){return
str_replace("\n","<br>",$Q);}function
checkbox($D,$Y,$Fa,$zc="",$od="",$wc=false){static$t=0;$t++;$J="<input type='checkbox' name='$D' value='".h($Y)."'".($Fa?" checked":"").($od?' onclick="'.h($od).'"':'').($wc?" class='jsonly'":"")." id='checkbox-$t'>";return($zc!=""?"<label for='checkbox-$t'>$J".h($zc)."</label>":$J);}function
optionlist($rd,$we=null,$Bf=false){$J="";foreach($rd
as$xc=>$W){$sd=array($xc=>$W);if(is_array($W)){$J.='<optgroup label="'.h($xc).'">';$sd=$W;}foreach($sd
as$y=>$X){$J.='<option'.($Bf||is_string($y)?' value="'.h($y).'"':'').(($Bf||is_string($y)?(string)$y:$X)===$we?' selected':'').'>'.h($X);}if(is_array($W)){$J.='</optgroup>';}}return$J;}function
html_select($D,$rd,$Y="",$nd=true){if($nd){return"<select name='".h($D)."'".(is_string($nd)?' onchange="'.h($nd).'"':"").">".optionlist($rd,$Y)."</select>";}$J="";foreach($rd
as$y=>$X){$J.="<label><input type='radio' name='".h($D)."' value='".h($y)."'".($y==$Y?" checked":"").">".h($X)."</label>";}return$J;}function
confirm($Wa="",$He=false){return" onclick=\"".($He?"eventStop(event); ":"")."return confirm('".'Are you sure?'.($Wa?" (' + $Wa + ')":"")."');\"";}function
print_fieldset($t,$Fc,$Hf=false,$od=""){echo"<fieldset><legend><a href='#fieldset-$t' onclick=\"".h($od)."return !toggle('fieldset-$t');\">$Fc</a></legend><div id='fieldset-$t'".($Hf?"":" class='hidden'").">\n";}function
bold($Aa){return($Aa?" class='active'":"");}function
odd($J=' class="odd"'){static$s=0;if(!$J){$s=-1;}return($s++%
2?$J:'');}function
js_escape($Q){return
addcslashes($Q,"\r\n'\\/");}function
json_row($y,$X=null){static$Ub=true;if($Ub){echo"{";}if($y!=""){echo($Ub?"":",")."\n\t\"".addcslashes($y,"\r\n\"\\").'": '.(isset($X)?'"'.addcslashes($X,"\r\n\"\\").'"':'undefined');$Ub=false;}else{echo"\n}\n";$Ub=true;}}function
ini_bool($pc){$X=ini_get($pc);return(eregi('^(on|true|yes)$',$X)||(int)$X);}function
sid(){static$J;if(!isset($J)){$J=(SID&&!($_COOKIE&&ini_bool("session.use_cookies")));}return$J;}function
q($Q){global$e;return$e->quote($Q);}function
get_vals($H,$Ma=0){global$e;$J=array();$I=$e->query($H);if(is_object($I)){while($K=$I->fetch_row()){$J[]=$K[$Ma];}}return$J;}function
get_key_vals($H,$f=null){global$e;if(!is_object($f)){$f=$e;}$J=array();$I=$f->query($H);if(is_object($I)){while($K=$I->fetch_row()){$J[$K[0]]=$K[1];}}return$J;}function
get_rows($H,$f=null,$i="<p class='error'>"){global$e;if(!is_object($f)){$f=$e;}$J=array();$I=$f->query($H);if(is_object($I)){while($K=$I->fetch_assoc()){$J[]=$K;}}elseif(!$I&&$e->error&&$i&&defined("PAGE_HEADER")){echo$i.error()."\n";}return$J;}function
unique_array($K,$v){foreach($v
as$u){if(ereg("PRIMARY|UNIQUE",$u["type"])){$J=array();foreach($u["columns"]as$y){if(!isset($K[$y])){continue
2;}$J[$y]=$K[$y];}return$J;}}$J=array();foreach($K
as$y=>$X){if(!preg_match('~^(COUNT\\((\\*|(DISTINCT )?`(?:[^`]|``)+`)\\)|(AVG|GROUP_CONCAT|MAX|MIN|SUM)\\(`(?:[^`]|``)+`\\))$~',$y)){$J[$y]=$X;}}return$J;}function
where($Z){global$x;$J=array();foreach((array)$Z["where"]as$y=>$X){$J[]=idf_escape(bracket_escape($y,1)).(ereg('\\.',$X)||$x=="mssql"?" LIKE ".exact_value(addcslashes($X,"%_\\")):" = ".exact_value($X));}foreach((array)$Z["null"]as$y){$J[]=idf_escape($y)." IS NULL";}return
implode(" AND ",$J);}function
where_check($X){parse_str($X,$Ea);remove_slashes(array(&$Ea));return
where($Ea);}function
where_link($s,$Ma,$Y,$pd="="){return"&where%5B$s%5D%5Bcol%5D=".urlencode($Ma)."&where%5B$s%5D%5Bop%5D=".urlencode((isset($Y)?$pd:"IS NULL"))."&where%5B$s%5D%5Bval%5D=".urlencode($Y);}function
cookie($D,$Y){global$ba;$Dd=array($D,(ereg("\n",$Y)?"":$Y),time()+2592000,preg_replace('~\\?.*~','',$_SERVER["REQUEST_URI"]),"",$ba);if(version_compare(PHP_VERSION,'5.2.0')>=0){$Dd[]=true;}return
call_user_func_array('setcookie',$Dd);}function
restart_session(){if(!ini_bool("session.use_cookies")){session_start();}}function&get_session($y){return$_SESSION[$y][DRIVER][SERVER][$_GET["username"]];}function
set_session($y,$X){$_SESSION[$y][DRIVER][SERVER][$_GET["username"]]=$X;}function
auth_url($nb,$O,$Cf){global$ob;preg_match('~([^?]*)\\??(.*)~',remove_from_uri(implode("|",array_keys($ob))."|username|".session_name()),$B);return"$B[1]?".(sid()?SID."&":"").($nb!="server"||$O!=""?urlencode($nb)."=".urlencode($O)."&":"")."username=".urlencode($Cf).($B[2]?"&$B[2]":"");}function
is_ajax(){return($_SERVER["HTTP_X_REQUESTED_WITH"]=="XMLHttpRequest");}function
redirect($A,$Sc=null){if(isset($Sc)){restart_session();$_SESSION["messages"][preg_replace('~^[^?]*~','',(isset($A)?$A:$_SERVER["REQUEST_URI"]))][]=$Sc;}if(isset($A)){if($A==""){$A=".";}header((is_ajax()?"X-AJAX-Redirect":"Location").": $A");exit;}}function
query_redirect($H,$A,$Sc,$de=true,$Jb=true,$Pb=false){global$e,$i,$b;if($Jb){$Pb=!$e->query($H);}$De="";if($H){$De=$b->messageQuery("$H;");}if($Pb){$i=error().$De;return
false;}if($de){redirect($A,$Sc.$De);}return
true;}function
queries($H=null){global$e;static$be=array();if(!isset($H)){return
implode(";\n",$be);}$be[]=(ereg(';$',$H)?"DELIMITER ;;\n$H;\nDELIMITER ":$H);return$e->query($H);}function
apply_queries($H,$Ve,$Fb='table'){foreach($Ve
as$S){if(!queries("$H ".$Fb($S))){return
false;}}return
true;}function
queries_redirect($A,$Sc,$de){return
query_redirect(queries(),$A,$Sc,$de,false,!$de);}function
remove_from_uri($Cd=""){return
substr(preg_replace("~(?<=[?&])($Cd".(SID?"":"|".session_name()).")=[^&]*&~",'',"$_SERVER[REQUEST_URI]&"),0,-1);}function
pagination($E,$bb){return" ".($E==$bb?$E+1:'<a href="'.h(remove_from_uri("page").($E?"&page=$E":"")).'">'.($E+1)."</a>");}function
get_file($y,$gb=false){$Rb=$_FILES[$y];if(!$Rb||$Rb["error"]){return$Rb["error"];}$J=file_get_contents($gb&&ereg('\\.gz$',$Rb["name"])?"compress.zlib://$Rb[tmp_name]":($gb&&ereg('\\.bz2$',$Rb["name"])?"compress.bzip2://$Rb[tmp_name]":$Rb["tmp_name"]));if($gb){$Ee=substr($J,0,3);if(function_exists("iconv")&&ereg("^\xFE\xFF|^\xFF\xFE",$Ee,$je)){$J=iconv("utf-16","utf-8",$J);}elseif($Ee=="\xEF\xBB\xBF"){$J=substr($J,3);}}return$J;}function
upload_error($i){$Qc=($i==UPLOAD_ERR_INI_SIZE?ini_get("upload_max_filesize"):null);return($i?'Unable to upload a file.'.($Qc?" ".sprintf('Maximum allowed file size is %sB.',$Qc):""):'File does not exist.');}function
repeat_pattern($F,$Gc){return
str_repeat("$F{0,65535}",$Gc/65535)."$F{0,".($Gc
%
65535)."}";}function
is_utf8($X){return(preg_match('~~u',$X)&&!preg_match('~[\\0-\\x8\\xB\\xC\\xE-\\x1F]~',$X));}function
shorten_utf8($Q,$Gc=80,$Le=""){if(!preg_match("(^(".repeat_pattern("[\t\r\n -\x{FFFF}]",$Gc).")($)?)u",$Q,$B)){preg_match("(^(".repeat_pattern("[\t\r\n -~]",$Gc).")($)?)",$Q,$B);}return
h($B[1]).$Le.(isset($B[2])?"":"<i>...</i>");}function
friendly_url($X){return
preg_replace('~[^a-z0-9_]~i','-',$X);}function
hidden_fields($Yd,$mc=array()){while(list($y,$X)=each($Yd)){if(is_array($X)){foreach($X
as$xc=>$W){$Yd[$y."[$xc]"]=$W;}}elseif(!in_array($y,$mc)){echo'<input type="hidden" name="'.h($y).'" value="'.h($X).'">';}}}function
hidden_fields_get(){echo(sid()?'<input type="hidden" name="'.session_name().'" value="'.h(session_id()).'">':''),(SERVER!==null?'<input type="hidden" name="'.DRIVER.'" value="'.h(SERVER).'">':""),'<input type="hidden" name="username" value="'.h($_GET["username"]).'">';}function
column_foreign_keys($S){global$b;$J=array();foreach($b->foreignKeys($S)as$l){foreach($l["source"]as$X){$J[$X][]=$l;}}return$J;}function
enum_input($V,$ta,$j,$Y,$zb=null){global$b;preg_match_all("~'((?:[^']|'')*)'~",$j["length"],$Lc);$J=(isset($zb)?"<label><input type='$V'$ta value='$zb'".((is_array($Y)?in_array($zb,$Y):$Y===0)?" checked":"")."><i>".'empty'."</i></label>":"");foreach($Lc[1]as$s=>$X){$X=stripcslashes(str_replace("''","'",$X));$Fa=(is_int($Y)?$Y==$s+1:(is_array($Y)?in_array($s+1,$Y):$Y===$X));$J.=" <label><input type='$V'$ta value='".($s+1)."'".($Fa?' checked':'').'>'.h($b->editVal($X,$j)).'</label>';}return$J;}function
input($j,$Y,$o){global$sf,$b,$x;$D=h(bracket_escape($j["field"]));echo"<td class='function'>";$le=($x=="mssql"&&$j["auto_increment"]);if($le&&!$_POST["save"]){$o=null;}$p=(isset($_GET["select"])||$le?array("orig"=>'original'):array())+$b->editFunctions($j);$ta=" name='fields[$D]'";if($j["type"]=="enum"){echo
nbsp($p[""])."<td>".$b->editInput($_GET["edit"],$j,$ta,$Y);}else{$Ub=0;foreach($p
as$y=>$X){if($y===""||!$X){break;}$Ub++;}$nd=($Ub?" onchange=\"var f = this.form['function[".h(js_escape(bracket_escape($j["field"])))."]']; if ($Ub > f.selectedIndex) f.selectedIndex = $Ub;\"":"");$ta.=$nd;echo(count($p)>1?html_select("function[$D]",$p,!isset($o)||in_array($o,$p)||isset($p[$o])?$o:"","functionChange(this);"):nbsp(reset($p))).'<td>';$rc=$b->editInput($_GET["edit"],$j,$ta,$Y);if($rc!=""){echo$rc;}elseif($j["type"]=="set"){preg_match_all("~'((?:[^']|'')*)'~",$j["length"],$Lc);foreach($Lc[1]as$s=>$X){$X=stripcslashes(str_replace("''","'",$X));$Fa=(is_int($Y)?($Y>>$s)&1:in_array($X,explode(",",$Y),true));echo" <label><input type='checkbox' name='fields[$D][$s]' value='".(1<<$s)."'".($Fa?' checked':'')."$nd>".h($b->editVal($X,$j)).'</label>';}}elseif(ereg('blob|bytea|raw|file',$j["type"])&&ini_bool("file_uploads")){echo"<input type='file' name='fields-$D'$nd>";}elseif(ereg('text|lob',$j["type"])){echo"<textarea ".($x!="sqlite"||ereg("\n",$Y)?"cols='50' rows='12'":"cols='30' rows='1' style='height: 1.2em;'")."$ta>".h($Y).'</textarea>';}else{$Rc=(!ereg('int',$j["type"])&&preg_match('~^(\\d+)(,(\\d+))?$~',$j["length"],$B)?((ereg("binary",$j["type"])?2:1)*$B[1]+($B[3]?1:0)+($B[2]&&!$j["unsigned"]?1:0)):($sf[$j["type"]]?$sf[$j["type"]]+($j["unsigned"]?0:1):0));echo"<input value='".h($Y)."'".($Rc?" maxlength='$Rc'":"").(ereg('char|binary',$j["type"])&&$Rc>20?" size='40'":"")."$ta>";}}}function
process_input($j){global$b;$lc=bracket_escape($j["field"]);$o=$_POST["function"][$lc];$Y=$_POST["fields"][$lc];if($j["type"]=="enum"){if($Y==-1){return
false;}if($Y==""){return"NULL";}return+$Y;}if($j["auto_increment"]&&$Y==""){return
null;}if($o=="orig"){return($j["on_update"]=="CURRENT_TIMESTAMP"?idf_escape($j["field"]):false);}if($o=="NULL"){return"NULL";}if($j["type"]=="set"){return
array_sum((array)$Y);}if(ereg('blob|bytea|raw|file',$j["type"])&&ini_bool("file_uploads")){$Rb=get_file("fields-$lc");if(!is_string($Rb)){return
false;}return
q($Rb);}return$b->processInput($j,$Y,$o);}function
search_tables(){global$b,$e;$_GET["where"][0]["op"]="LIKE %%";$_GET["where"][0]["val"]=$_POST["query"];$n=false;foreach(table_status()as$S=>$T){$D=$b->tableName($T);if(isset($T["Engine"])&&$D!=""&&(!$_POST["tables"]||in_array($S,$_POST["tables"]))){$I=$e->query("SELECT".limit("1 FROM ".table($S)," WHERE ".implode(" AND ",$b->selectSearchProcess(fields($S),array())),1));if($I->fetch_row()){if(!$n){echo"<ul>\n";$n=true;}echo"<li><a href='".h(ME."select=".urlencode($S)."&where[0][op]=".urlencode($_GET["where"][0]["op"])."&where[0][val]=".urlencode($_GET["where"][0]["val"]))."'>$D</a>\n";}}}echo($n?"</ul>":"<p class='message'>".'No tables.')."\n";}function
dump_headers($kc,$Zc=false){global$b;$J=$b->dumpHeaders($kc,$Zc);$Ad=$_POST["output"];if($Ad!="text"){header("Content-Disposition: attachment; filename=".friendly_url($kc!=""?$kc:(SERVER!=""?SERVER:"localhost")).".$J".($Ad!="file"&&!ereg('[^0-9a-z]',$Ad)?".$Ad":""));}session_write_close();return$J;}function
dump_csv($K){foreach($K
as$y=>$X){if(preg_match("~[\"\n,;\t]~",$X)||$X===""){$K[$y]='"'.str_replace('"','""',$X).'"';}}echo
implode(($_POST["format"]=="csv"?",":($_POST["format"]=="tsv"?"\t":";")),$K)."\r\n";}function
apply_sql_function($o,$Ma){return($o?($o=="unixepoch"?"DATETIME($Ma, '$o')":($o=="count distinct"?"COUNT(DISTINCT ":strtoupper("$o("))."$Ma)"):$Ma);}function
password_file(){$kb=ini_get("upload_tmp_dir");if(!$kb){if(function_exists('sys_get_temp_dir')){$kb=sys_get_temp_dir();}else{$Sb=@tempnam("","");if(!$Sb){return
false;}$kb=dirname($Sb);unlink($Sb);}}$Sb="$kb/adminer.key";$J=@file_get_contents($Sb);if($J){return$J;}$Zb=@fopen($Sb,"w");if($Zb){$J=md5(uniqid(mt_rand(),true));fwrite($Zb,$J);fclose($Zb);}return$J;}function
is_mail($wb){$sa='[-a-z0-9!#$%&\'*+/=?^_`{|}~]';$mb='[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])';$F="$sa+(\\.$sa+)*@($mb?\\.)+$mb";return
preg_match("(^$F(,\\s*$F)*\$)i",$wb);}function
is_url($Q){$mb='[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])';return(preg_match("~^(https?)://($mb?\\.)+$mb(:\\d+)?(/.*)?(\\?.*)?(#.*)?\$~i",$Q,$B)?strtolower($B[1]):"");}global$b,$e,$ob,$ub,$Cb,$i,$p,$ec,$ba,$qc,$x,$ca,$_c,$md,$Je,$U,$mf,$sf,$zf,$ga;if(!isset($_SERVER["REQUEST_URI"])){$_SERVER["REQUEST_URI"]=$_SERVER["ORIG_PATH_INFO"].($_SERVER["QUERY_STRING"]!=""?"?$_SERVER[QUERY_STRING]":"");}$ba=$_SERVER["HTTPS"]&&strcasecmp($_SERVER["HTTPS"],"off");@ini_set("session.use_trans_sid",false);if(!defined("SID")){session_name("adminer_sid");$Dd=array(0,preg_replace('~\\?.*~','',$_SERVER["REQUEST_URI"]),"",$ba);if(version_compare(PHP_VERSION,'5.2.0')>=0){$Dd[]=true;}call_user_func_array('session_set_cookie_params',$Dd);session_start();}remove_slashes(array(&$_GET,&$_POST,&$_COOKIE),$Tb);if(function_exists("set_magic_quotes_runtime")){set_magic_quotes_runtime(false);}@set_time_limit(0);@ini_set("zend.ze1_compatibility_mode",false);@ini_set("precision",20);function
get_lang(){return'en';}function
lang($lf,$fd){$Nd=($fd==1?0:1);return
sprintf($lf[$Nd],$fd);}if(extension_loaded('pdo')){class
Min_PDO
extends
PDO{var$_result,$server_info,$affected_rows,$error;function
__construct(){}function
dsn($rb,$Cf,$Kd,$Ib='auth_error'){set_exception_handler($Ib);parent::__construct($rb,$Cf,$Kd);restore_exception_handler();$this->setAttribute(13,array('Min_PDOStatement'));$this->server_info=$this->getAttribute(4);}function
query($H,$tf=false){$I=parent::query($H);if(!$I){$Db=$this->errorInfo();$this->error=$Db[2];return
false;}$this->store_result($I);return$I;}function
multi_query($H){return$this->_result=$this->query($H);}function
store_result($I=null){if(!$I){$I=$this->_result;}if($I->columnCount()){$I->num_rows=$I->rowCount();return$I;}$this->affected_rows=$I->rowCount();return
true;}function
next_result(){return$this->_result->nextRowset();}function
result($H,$j=0){$I=$this->query($H);if(!$I){return
false;}$K=$I->fetch();return$K[$j];}}class
Min_PDOStatement
extends
PDOStatement{var$_offset=0,$num_rows;function
fetch_assoc(){return$this->fetch(2);}function
fetch_row(){return$this->fetch(3);}function
fetch_field(){$K=(object)$this->getColumnMeta($this->_offset++);$K->orgtable=$K->table;$K->orgname=$K->name;$K->charsetnr=(in_array("blob",$K->flags)?63:0);return$K;}}}$ob=array();$ob=array("server"=>"MySQL")+$ob;if(!defined("DRIVER")){$Qd=array("MySQLi","MySQL","PDO_MySQL");define("DRIVER","server");if(extension_loaded("mysqli")){class
Min_DB
extends
MySQLi{var$extension="MySQLi";function
Min_DB(){parent::init();}function
connect($O,$Cf,$Kd){mysqli_report(MYSQLI_REPORT_OFF);list($ic,$Md)=explode(":",$O,2);$J=@$this->real_connect(($O!=""?$ic:ini_get("mysqli.default_host")),($O.$Cf!=""?$Cf:ini_get("mysqli.default_user")),($O.$Cf.$Kd!=""?$Kd:ini_get("mysqli.default_pw")),null,(is_numeric($Md)?$Md:ini_get("mysqli.default_port")),(!is_numeric($Md)?$Md:null));if($J){if(method_exists($this,'set_charset')){$this->set_charset("utf8");}else{$this->query("SET NAMES utf8");}}return$J;}function
result($H,$j=0){$I=$this->query($H);if(!$I){return
false;}$K=$I->fetch_array();return$K[$j];}function
quote($Q){return"'".$this->escape_string($Q)."'";}}}elseif(extension_loaded("mysql")){class
Min_DB{var$extension="MySQL",$server_info,$affected_rows,$error,$_link,$_result;function
connect($O,$Cf,$Kd){$this->_link=@mysql_connect(($O!=""?$O:ini_get("mysql.default_host")),("$O$Cf"!=""?$Cf:ini_get("mysql.default_user")),("$O$Cf$Kd"!=""?$Kd:ini_get("mysql.default_password")),true,131072);if($this->_link){$this->server_info=mysql_get_server_info($this->_link);if(function_exists('mysql_set_charset')){mysql_set_charset("utf8",$this->_link);}else{$this->query("SET NAMES utf8");}}else{$this->error=mysql_error();}return(bool)$this->_link;}function
quote($Q){return"'".mysql_real_escape_string($Q,$this->_link)."'";}function
select_db($eb){return
mysql_select_db($eb,$this->_link);}function
query($H,$tf=false){$I=@($tf?mysql_unbuffered_query($H,$this->_link):mysql_query($H,$this->_link));if(!$I){$this->error=mysql_error($this->_link);return
false;}if($I===true){$this->affected_rows=mysql_affected_rows($this->_link);$this->info=mysql_info($this->_link);return
true;}return
new
Min_Result($I);}function
multi_query($H){return$this->_result=$this->query($H);}function
store_result(){return$this->_result;}function
next_result(){return
false;}function
result($H,$j=0){$I=$this->query($H);if(!$I||!$I->num_rows){return
false;}return
mysql_result($I->_result,0,$j);}}class
Min_Result{var$num_rows,$_result,$_offset=0;function
Min_Result($I){$this->_result=$I;$this->num_rows=mysql_num_rows($I);}function
fetch_assoc(){return
mysql_fetch_assoc($this->_result);}function
fetch_row(){return
mysql_fetch_row($this->_result);}function
fetch_field(){$J=mysql_fetch_field($this->_result,$this->_offset++);$J->orgtable=$J->table;$J->orgname=$J->name;$J->charsetnr=($J->blob?63:0);return$J;}function
__destruct(){mysql_free_result($this->_result);}}}elseif(extension_loaded("pdo_mysql")){class
Min_DB
extends
Min_PDO{var$extension="PDO_MySQL";function
connect($O,$Cf,$Kd){$this->dsn("mysql:host=".str_replace(":",";unix_socket=",preg_replace('~:(\\d)~',';port=\\1',$O)),$Cf,$Kd);$this->query("SET NAMES utf8");return
true;}function
select_db($eb){return$this->query("USE ".idf_escape($eb));}function
query($H,$tf=false){$this->setAttribute(1000,!$tf);return
parent::query($H,$tf);}}}function
idf_escape($lc){return"`".str_replace("`","``",$lc)."`";}function
table($lc){return
idf_escape($lc);}function
connect(){global$b;$e=new
Min_DB;$ab=$b->credentials();if($e->connect($ab[0],$ab[1],$ab[2])){$e->query("SET sql_quote_show_create = 1");return$e;}$J=$e->error;if(function_exists('iconv')&&!is_utf8($J)&&strlen($M=iconv("windows-1250","utf-8",$J))>strlen($J)){$J=$M;}return$J;}function
get_databases($Vb=true){global$e;$J=&get_session("dbs");if(!isset($J)){if($Vb){restart_session();ob_flush();flush();}$J=get_vals($e->server_info>=5?"SELECT SCHEMA_NAME FROM information_schema.SCHEMATA":"SHOW DATABASES");}return$J;}function
limit($H,$Z,$z,$hd=0,$ye=" "){return" $H$Z".(isset($z)?$ye."LIMIT $z".($hd?" OFFSET $hd":""):"");}function
limit1($H,$Z){return
limit($H,$Z,1);}function
db_collation($h,$c){global$e;$J=null;$Xa=$e->result("SHOW CREATE DATABASE ".idf_escape($h),1);if(preg_match('~ COLLATE ([^ ]+)~',$Xa,$B)){$J=$B[1];}elseif(preg_match('~ CHARACTER SET ([^ ]+)~',$Xa,$B)){$J=$c[$B[1]][-1];}return$J;}function
engines(){$J=array();foreach(get_rows("SHOW ENGINES")as$K){if(ereg("YES|DEFAULT",$K["Support"])){$J[]=$K["Engine"];}}return$J;}function
logged_user(){global$e;return$e->result("SELECT USER()");}function
tables_list(){global$e;return
get_key_vals("SHOW".($e->server_info>=5?" FULL":"")." TABLES");}function
count_tables($g){$J=array();foreach($g
as$h){$J[$h]=count(get_vals("SHOW TABLES IN ".idf_escape($h)));}return$J;}function
table_status($D=""){$J=array();foreach(get_rows("SHOW TABLE STATUS".($D!=""?" LIKE ".q(addcslashes($D,"%_")):""))as$K){if($K["Engine"]=="InnoDB"){$K["Comment"]=preg_replace('~(?:(.+); )?InnoDB free: .*~','\\1',$K["Comment"]);}if(!isset($K["Rows"])){$K["Comment"]="";}if($D!=""){return$K;}$J[$K["Name"]]=$K;}return$J;}function
is_view($T){return!isset($T["Rows"]);}function
fk_support($T){return
eregi("InnoDB|IBMDB2I",$T["Engine"]);}function
fields($S){$J=array();foreach(get_rows("SHOW FULL COLUMNS FROM ".table($S))as$K){preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~',$K["Type"],$B);$J[$K["Field"]]=array("field"=>$K["Field"],"full_type"=>$K["Type"],"type"=>$B[1],"length"=>$B[2],"unsigned"=>ltrim($B[3].$B[4]),"default"=>($K["Default"]!=""||ereg("char",$B[1])?$K["Default"]:null),"null"=>($K["Null"]=="YES"),"auto_increment"=>($K["Extra"]=="auto_increment"),"on_update"=>(eregi('^on update (.+)',$K["Extra"],$B)?$B[1]:""),"collation"=>$K["Collation"],"privileges"=>array_flip(explode(",",$K["Privileges"])),"comment"=>$K["Comment"],"primary"=>($K["Key"]=="PRI"),);}return$J;}function
indexes($S,$f=null){$J=array();foreach(get_rows("SHOW INDEX FROM ".table($S),$f)as$K){$J[$K["Key_name"]]["type"]=($K["Key_name"]=="PRIMARY"?"PRIMARY":($K["Index_type"]=="FULLTEXT"?"FULLTEXT":($K["Non_unique"]?"INDEX":"UNIQUE")));$J[$K["Key_name"]]["columns"][]=$K["Column_name"];$J[$K["Key_name"]]["lengths"][]=$K["Sub_part"];}return$J;}function
foreign_keys($S){global$e,$md;static$F='`(?:[^`]|``)+`';$J=array();$Ya=$e->result("SHOW CREATE TABLE ".table($S),1);if($Ya){preg_match_all("~CONSTRAINT ($F) FOREIGN KEY \\(((?:$F,? ?)+)\\) REFERENCES ($F)(?:\\.($F))? \\(((?:$F,? ?)+)\\)(?: ON DELETE ($md))?(?: ON UPDATE ($md))?~",$Ya,$Lc,PREG_SET_ORDER);foreach($Lc
as$B){preg_match_all("~$F~",$B[2],$Be);preg_match_all("~$F~",$B[5],$Ye);$J[idf_unescape($B[1])]=array("db"=>idf_unescape($B[4]!=""?$B[3]:$B[4]),"table"=>idf_unescape($B[4]!=""?$B[4]:$B[3]),"source"=>array_map('idf_unescape',$Be[0]),"target"=>array_map('idf_unescape',$Ye[0]),"on_delete"=>$B[6],"on_update"=>$B[7],);}}return$J;}function
view($D){global$e;return
array("select"=>preg_replace('~^(?:[^`]|`[^`]*`)*\\s+AS\\s+~isU','',$e->result("SHOW CREATE VIEW ".table($D),1)));}function
collations(){$J=array();foreach(get_rows("SHOW COLLATION")as$K){if($K["Default"]){$J[$K["Charset"]][-1]=$K["Collation"];}else{$J[$K["Charset"]][]=$K["Collation"];}}ksort($J);foreach($J
as$y=>$X){asort($J[$y]);}return$J;}function
information_schema($h){global$e;return($e->server_info>=5&&$h=="information_schema");}function
error(){global$e;return
h(preg_replace('~^You have an error.*syntax to use~U',"Syntax error",$e->error));}function
exact_value($X){return
q($X)." COLLATE utf8_bin";}function
create_database($h,$Ka){set_session("dbs",null);return
queries("CREATE DATABASE ".idf_escape($h).($Ka?" COLLATE ".q($Ka):""));}function
drop_databases($g){set_session("dbs",null);return
apply_queries("DROP DATABASE",$g,'idf_escape');}function
rename_database($D,$Ka){if(create_database($D,$Ka)){$ke=array();foreach(tables_list()as$S=>$V){$ke[]=table($S)." TO ".idf_escape($D).".".table($S);}if(!$ke||queries("RENAME TABLE ".implode(", ",$ke))){queries("DROP DATABASE ".idf_escape(DB));return
true;}}return
false;}function
auto_increment(){$va=" PRIMARY KEY";if($_GET["create"]!=""&&$_POST["auto_increment_col"]){foreach(indexes($_GET["create"])as$u){if(in_array($_POST["fields"][$_POST["auto_increment_col"]]["orig"],$u["columns"],true)){$va="";break;}if($u["type"]=="PRIMARY"){$va=" UNIQUE";}}}return" AUTO_INCREMENT$va";}function
alter_table($S,$D,$k,$Wb,$Pa,$Ab,$Ka,$ua,$Hd){$ra=array();foreach($k
as$j){$ra[]=($j[1]?($S!=""?($j[0]!=""?"CHANGE ".idf_escape($j[0]):"ADD"):" ")." ".implode($j[1]).($S!=""?" $j[2]":""):"DROP ".idf_escape($j[0]));}$ra=array_merge($ra,$Wb);$Fe="COMMENT=".q($Pa).($Ab?" ENGINE=".q($Ab):"").($Ka?" COLLATE ".q($Ka):"").($ua!=""?" AUTO_INCREMENT=$ua":"").$Hd;if($S==""){return
queries("CREATE TABLE ".table($D)." (\n".implode(",\n",$ra)."\n) $Fe");}if($S!=$D){$ra[]="RENAME TO ".table($D);}$ra[]=$Fe;return
queries("ALTER TABLE ".table($S)."\n".implode(",\n",$ra));}function
alter_indexes($S,$ra){foreach($ra
as$y=>$X){$ra[$y]=($X[2]=="DROP"?"\nDROP INDEX ".idf_escape($X[1]):"\nADD $X[0] ".($X[0]=="PRIMARY"?"KEY ":"").($X[1]!=""?idf_escape($X[1])." ":"").$X[2]);}return
queries("ALTER TABLE ".table($S).implode(",",$ra));}function
truncate_tables($Ve){return
apply_queries("TRUNCATE TABLE",$Ve);}function
drop_views($Gf){return
queries("DROP VIEW ".implode(", ",array_map('table',$Gf)));}function
drop_tables($Ve){return
queries("DROP TABLE ".implode(", ",array_map('table',$Ve)));}function
move_tables($Ve,$Gf,$Ye){$ke=array();foreach(array_merge($Ve,$Gf)as$S){$ke[]=table($S)." TO ".idf_escape($Ye).".".table($S);}return
queries("RENAME TABLE ".implode(", ",$ke));}function
copy_tables($Ve,$Gf,$Ye){queries("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'");foreach($Ve
as$S){$D=($Ye==DB?table("copy_$S"):idf_escape($Ye).".".table($S));if(!queries("DROP TABLE IF EXISTS $D")||!queries("CREATE TABLE $D LIKE ".table($S))||!queries("INSERT INTO $D SELECT * FROM ".table($S))){return
false;}}foreach($Gf
as$S){$D=($Ye==DB?table("copy_$S"):idf_escape($Ye).".".table($S));$Ff=view($S);if(!queries("DROP VIEW IF EXISTS $D")||!queries("CREATE VIEW $D AS $Ff[select]")){return
false;}}return
true;}function
trigger($D){if($D==""){return
array();}$L=get_rows("SHOW TRIGGERS WHERE `Trigger` = ".q($D));return
reset($L);}function
triggers($S){$J=array();foreach(get_rows("SHOW TRIGGERS LIKE ".q(addcslashes($S,"%_")))as$K){$J[$K["Trigger"]]=array($K["Timing"],$K["Event"]);}return$J;}function
trigger_options(){return
array("Timing"=>array("BEFORE","AFTER"),"Type"=>array("FOR EACH ROW"),);}function
routine($D,$V){global$e,$Cb,$qc,$sf;$pa=array("bool","boolean","integer","double precision","real","dec","numeric","fixed","national char","national varchar");$rf="((".implode("|",array_merge(array_keys($sf),$pa)).")(?:\\s*\\(((?:[^'\")]*|$Cb)+)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s]+)['\"]?)?";$F="\\s*(".($V=="FUNCTION"?"":$qc).")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$rf";$Xa=$e->result("SHOW CREATE $V ".idf_escape($D),2);preg_match("~\\(((?:$F\\s*,?)*)\\)".($V=="FUNCTION"?"\\s*RETURNS\\s+$rf":"")."\\s*(.*)~is",$Xa,$B);$k=array();preg_match_all("~$F\\s*,?~is",$B[1],$Lc,PREG_SET_ORDER);foreach($Lc
as$Cd){$D=str_replace("``","`",$Cd[2]).$Cd[3];$k[]=array("field"=>$D,"type"=>strtolower($Cd[5]),"length"=>preg_replace_callback("~$Cb~s",'normalize_enum',$Cd[6]),"unsigned"=>strtolower(preg_replace('~\\s+~',' ',trim("$Cd[8] $Cd[7]"))),"full_type"=>$Cd[4],"inout"=>strtoupper($Cd[1]),"collation"=>strtolower($Cd[9]),);}if($V!="FUNCTION"){return
array("fields"=>$k,"definition"=>$B[11]);}return
array("fields"=>$k,"returns"=>array("type"=>$B[12],"length"=>$B[13],"unsigned"=>$B[15],"collation"=>$B[16]),"definition"=>$B[17],"language"=>"SQL",);}function
routines(){return
get_rows("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = ".q(DB));}function
routine_languages(){return
array();}function
begin(){return
queries("BEGIN");}function
insert_into($S,$P){return
queries("INSERT INTO ".table($S)." (".implode(", ",array_keys($P)).")\nVALUES (".implode(", ",$P).")");}function
insert_update($S,$P,$Td){foreach($P
as$y=>$X){$P[$y]="$y = $X";}$_f=implode(", ",$P);return
queries("INSERT INTO ".table($S)." SET $_f ON DUPLICATE KEY UPDATE $_f");}function
last_id(){global$e;return$e->result("SELECT LAST_INSERT_ID()");}function
explain($e,$H){return$e->query("EXPLAIN $H");}function
found_rows($T,$Z){return($Z||$T["Engine"]!="InnoDB"?null:$T["Rows"]);}function
types(){return
array();}function
schemas(){return
array();}function
get_schema(){return"";}function
set_schema($ue){return
true;}function
create_sql($S,$ua){global$e;$J=$e->result("SHOW CREATE TABLE ".table($S),1);if(!$ua){$J=preg_replace('~ AUTO_INCREMENT=\\d+~','',$J);}return$J;}function
truncate_sql($S){return"TRUNCATE ".table($S);}function
use_sql($eb){return"USE ".idf_escape($eb);}function
trigger_sql($S,$R){$J="";foreach(get_rows("SHOW TRIGGERS LIKE ".q(addcslashes($S,"%_")),null,"-- ")as$K){$J.="\n".($R=='CREATE+ALTER'?"DROP TRIGGER IF EXISTS ".idf_escape($K["Trigger"]).";;\n":"")."CREATE TRIGGER ".idf_escape($K["Trigger"])." $K[Timing] $K[Event] ON ".table($K["Table"])." FOR EACH ROW\n$K[Statement];;\n";}return$J;}function
show_variables(){return
get_key_vals("SHOW VARIABLES");}function
process_list(){return
get_rows("SHOW FULL PROCESSLIST");}function
show_status(){return
get_key_vals("SHOW STATUS");}function
support($Qb){global$e;return!ereg("scheme|sequence|type".($e->server_info<5.1?"|event|partitioning".($e->server_info<5?"|view|routine|trigger":""):""),$Qb);}$x="sql";$sf=array();$Je=array();foreach(array('Numbers'=>array("tinyint"=>3,"smallint"=>5,"mediumint"=>8,"int"=>10,"bigint"=>20,"decimal"=>66,"float"=>12,"double"=>21),'Date and time'=>array("date"=>10,"datetime"=>19,"timestamp"=>19,"time"=>10,"year"=>4),'Strings'=>array("char"=>255,"varchar"=>65535,"tinytext"=>255,"text"=>65535,"mediumtext"=>16777215,"longtext"=>4294967295),'Binary'=>array("bit"=>20,"binary"=>255,"varbinary"=>65535,"tinyblob"=>255,"blob"=>65535,"mediumblob"=>16777215,"longblob"=>4294967295),'Lists'=>array("enum"=>65535,"set"=>64),)as$y=>$X){$sf+=$X;$Je[$y]=array_keys($X);}$zf=array("unsigned","zerofill","unsigned zerofill");$qd=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","REGEXP","IN","IS NULL","NOT LIKE","NOT REGEXP","NOT IN","IS NOT NULL","");$p=array("char_length","date","from_unixtime","hex","lower","round","sec_to_time","time_to_sec","upper");$ec=array("avg","count","count distinct","group_concat","max","min","sum");$ub=array(array("char"=>"md5/sha1/password/encrypt/uuid","binary"=>"md5/sha1/hex","date|time"=>"now",),array("int|float|double|decimal"=>"+/-","date"=>"+ interval/- interval","time"=>"addtime/subtime","char|text"=>"concat",));}define("SERVER",$_GET[DRIVER]);define("DB",$_GET["db"]);define("ME",preg_replace('~^[^?]*/([^?]*).*~','\\1',$_SERVER["REQUEST_URI"]).'?'.(sid()?SID.'&':'').(SERVER!==null?DRIVER."=".urlencode(SERVER).'&':'').(isset($_GET["username"])?"username=".urlencode($_GET["username"]).'&':'').(DB!=""?'db='.urlencode(DB).'&'.(isset($_GET["ns"])?"ns=".urlencode($_GET["ns"])."&":""):''));$ga="3.3.3";class
Adminer{var$operators;function
name(){return"<a href='http://www.adminer.org/' id='h1'>Adminer</a>";}function
credentials(){return
array(SERVER,$_GET["username"],get_session("pwds"));}function
permanentLogin(){return
password_file();}function
database(){return
DB;}function
headers(){return
true;}function
head(){return
true;}function
loginForm(){global$ob;echo'<table cellspacing="0">
<tr><th>System<td>',html_select("driver",$ob,DRIVER,"loginDriver(this);"),'<tr><th>Server<td><input name="server" value="',h(SERVER),'" title="hostname[:port]">
<tr><th>Username<td><input id="username" name="username" value="',h($_GET["username"]);?>">
<tr><th>Password<td><input type="password" name="password">
</table>
<script type="text/javascript">
var username = document.getElementById('username');
username.focus();
username.form['driver'].onchange();
</script>
<?php
echo"<p><input type='submit' value='".'Login'."'>\n",checkbox("permanent",1,$_COOKIE["adminer_permanent"],'Permanent login')."\n";}function
login($Jc,$Kd){return
true;}function
tableName($Qe){return
h($Qe["Name"]);}function
fieldName($j,$td=0){return'<span title="'.h($j["full_type"]).'">'.h($j["field"]).'</span>';}function
selectLinks($Qe,$P=""){echo'<p class="tabs">';$Ic=array("select"=>'Select data',"table"=>'Show structure');if(is_view($Qe)){$Ic["view"]='Alter view';}else{$Ic["create"]='Alter table';}if(isset($P)){$Ic["edit"]='New item';}foreach($Ic
as$y=>$X){echo" <a href='".h(ME)."$y=".urlencode($Qe["Name"]).($y=="edit"?$P:"")."'".bold(isset($_GET[$y])).">$X</a>";}echo"\n";}function
foreignKeys($S){return
foreign_keys($S);}function
backwardKeys($S,$Pe){return
array();}function
backwardKeysPrint($xa,$K){}function
selectQuery($H){global$x;return"<p><a href='".h(remove_from_uri("page"))."&amp;page=last' title='".'Last page'."'>&gt;&gt;</a> <code class='jush-$x'>".h(str_replace("\n"," ",$H))."</code> <a href='".h(ME)."sql=".urlencode($H)."'>".'Edit'."</a></p>\n";}function
rowDescription($S){return"";}function
rowDescriptions($L,$Xb){return$L;}function
selectVal($X,$_,$j){$J=($X!="<i>NULL</i>"&&ereg("char|binary",$j["type"])&&!ereg("var",$j["type"])?"<code>$X</code>":$X);if(ereg('blob|bytea|raw|file',$j["type"])&&!is_utf8($X)){$J=lang(array('%d byte','%d bytes'),strlen(html_entity_decode($X,ENT_QUOTES)));}return($_?"<a href='$_'>$J</a>":$J);}function
editVal($X,$j){return(ereg("binary",$j["type"])?reset(unpack("H*",$X)):$X);}function
selectColumnsPrint($N,$d){global$p,$ec;print_fieldset("select",'Select',$N);$s=0;$bc=array('Functions'=>$p,'Aggregation'=>$ec);foreach($N
as$y=>$X){$X=$_GET["columns"][$y];echo"<div>".html_select("columns[$s][fun]",array(-1=>"")+$bc,$X["fun"]),"(<select name='columns[$s][col]'><option>".optionlist($d,$X["col"],true)."</select>)</div>\n";$s++;}echo"<div>".html_select("columns[$s][fun]",array(-1=>"")+$bc,"","this.nextSibling.nextSibling.onchange();"),"(<select name='columns[$s][col]' onchange='selectAddRow(this);'><option>".optionlist($d,null,true)."</select>)</div>\n","</div></fieldset>\n";}function
selectSearchPrint($Z,$d,$v){print_fieldset("search",'Search',$Z);foreach($v
as$s=>$u){if($u["type"]=="FULLTEXT"){echo"(<i>".implode("</i>, <i>",array_map('h',$u["columns"]))."</i>) AGAINST"," <input name='fulltext[$s]' value='".h($_GET["fulltext"][$s])."'>",checkbox("boolean[$s]",1,isset($_GET["boolean"][$s]),"BOOL"),"<br>\n";}}$s=0;foreach((array)$_GET["where"]as$X){if("$X[col]$X[val]"!=""&&in_array($X["op"],$this->operators)){echo"<div><select name='where[$s][col]'><option value=''>(".'anywhere'.")".optionlist($d,$X["col"],true)."</select>",html_select("where[$s][op]",$this->operators,$X["op"]),"<input name='where[$s][val]' value='".h($X["val"])."'></div>\n";$s++;}}echo"<div><select name='where[$s][col]' onchange='selectAddRow(this);'><option value=''>(".'anywhere'.")".optionlist($d,null,true)."</select>",html_select("where[$s][op]",$this->operators,"="),"<input name='where[$s][val]'></div>\n","</div></fieldset>\n";}function
selectOrderPrint($td,$d,$v){print_fieldset("sort",'Sort',$td);$s=0;foreach((array)$_GET["order"]as$y=>$X){if(isset($d[$X])){echo"<div><select name='order[$s]'><option>".optionlist($d,$X,true)."</select>",checkbox("desc[$s]",1,isset($_GET["desc"][$y]),'descending')."</div>\n";$s++;}}echo"<div><select name='order[$s]' onchange='selectAddRow(this);'><option>".optionlist($d,null,true)."</select>","<label><input type='checkbox' name='desc[$s]' value='1'>".'descending'."</label></div>\n";echo"</div></fieldset>\n";}function
selectLimitPrint($z){echo"<fieldset><legend>".'Limit'."</legend><div>";echo"<input name='limit' size='3' value='".h($z)."'>","</div></fieldset>\n";}function
selectLengthPrint($bf){if(isset($bf)){echo"<fieldset><legend>".'Text length'."</legend><div>",'<input name="text_length" size="3" value="'.h($bf).'">',"</div></fieldset>\n";}}function
selectActionPrint(){echo"<fieldset><legend>".'Action'."</legend><div>","<input type='submit' value='".'Select'."'>","</div></fieldset>\n";}function
selectCommandPrint(){return!information_schema(DB);}function
selectImportPrint(){return
true;}function
selectEmailPrint($xb,$d){}function
selectColumnsProcess($d,$v){global$p,$ec;$N=array();$r=array();foreach((array)$_GET["columns"]as$y=>$X){if($X["fun"]=="count"||(isset($d[$X["col"]])&&(!$X["fun"]||in_array($X["fun"],$p)||in_array($X["fun"],$ec)))){$N[$y]=apply_sql_function($X["fun"],(isset($d[$X["col"]])?idf_escape($X["col"]):"*"));if(!in_array($X["fun"],$ec)){$r[]=$N[$y];}}}return
array($N,$r);}function
selectSearchProcess($k,$v){global$x;$J=array();foreach($v
as$s=>$u){if($u["type"]=="FULLTEXT"&&$_GET["fulltext"][$s]!=""){$J[]="MATCH (".implode(", ",array_map('idf_escape',$u["columns"])).") AGAINST (".q($_GET["fulltext"][$s]).(isset($_GET["boolean"][$s])?" IN BOOLEAN MODE":"").")";}}foreach((array)$_GET["where"]as$X){if("$X[col]$X[val]"!=""&&in_array($X["op"],$this->operators)){$Sa=" $X[op]";if(ereg('IN$',$X["op"])){$nc=process_length($X["val"]);$Sa.=" (".($nc!=""?$nc:"NULL").")";}elseif(!$X["op"]){$Sa.=$X["val"];}elseif($X["op"]=="LIKE %%"){$Sa=" LIKE ".$this->processInput($k[$X["col"]],"%$X[val]%");}elseif(!ereg('NULL$',$X["op"])){$Sa.=" ".$this->processInput($k[$X["col"]],$X["val"]);}if($X["col"]!=""){$J[]=idf_escape($X["col"]).$Sa;}else{$La=array();foreach($k
as$D=>$j){if(is_numeric($X["val"])||!ereg('int|float|double|decimal',$j["type"])){$D=idf_escape($D);$La[]=($x=="sql"&&ereg('char|text|enum|set',$j["type"])&&!ereg('^utf8',$j["collation"])?"CONVERT($D USING utf8)":$D);}}$J[]=($La?"(".implode("$Sa OR ",$La)."$Sa)":"0");}}}return$J;}function
selectOrderProcess($k,$v){$J=array();foreach((array)$_GET["order"]as$y=>$X){if(isset($k[$X])||preg_match('~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\\)|COUNT\\(\\*\\))$~',$X)){$J[]=(isset($k[$X])?idf_escape($X):$X).(isset($_GET["desc"][$y])?" DESC":"");}}return$J;}function
selectLimitProcess(){return(isset($_GET["limit"])?$_GET["limit"]:"30");}function
selectLengthProcess(){return(isset($_GET["text_length"])?$_GET["text_length"]:"100");}function
selectEmailProcess($Z,$Xb){return
false;}function
messageQuery($H){global$x;static$Wa=0;restart_session();$t="sql-".($Wa++);$gc=&get_session("queries");if(strlen($H)>1e6){$H=ereg_replace('[\x80-\xFF]+$','',substr($H,0,1e6))."\n...";}$gc[$_GET["db"]][]=$H;return" <a href='#$t' onclick=\"return !toggle('$t');\">".'SQL command'."</a><div id='$t' class='hidden'><pre><code class='jush-$x'>".shorten_utf8($H,1000).'</code></pre><p><a href="'.h(str_replace("db=".urlencode(DB),"db=".urlencode($_GET["db"]),ME).'sql=&history='.(count($gc[$_GET["db"]])-1)).'">'.'Edit'.'</a></div>';}function
editFunctions($j){global$ub;$J=($j["null"]?"NULL/":"");foreach($ub
as$y=>$p){if(!$y||(!isset($_GET["call"])&&(isset($_GET["select"])||where($_GET)))){foreach($p
as$F=>$X){if(!$F||ereg($F,$j["type"])){$J.="/$X";}}if($y&&!ereg('set|blob|bytea|raw|file',$j["type"])){$J.="/=";}}}return
explode("/",$J);}function
editInput($S,$j,$ta,$Y){if($j["type"]=="enum"){return(isset($_GET["select"])?"<label><input type='radio'$ta value='-1' checked><i>".'original'."</i></label> ":"").($j["null"]?"<label><input type='radio'$ta value=''".(isset($Y)||isset($_GET["select"])?"":" checked")."><i>NULL</i></label> ":"").enum_input("radio",$ta,$j,$Y,0);}return"";}function
processInput($j,$Y,$o=""){if($o=="="){return$Y;}$D=$j["field"];$J=($j["type"]=="bit"&&ereg("^([0-9]+|b'[0-1]+')\$",$Y)?$Y:q($Y));if(ereg('^(now|getdate|uuid)$',$o)){$J="$o()";}elseif(ereg('^current_(date|timestamp)$',$o)){$J=$o;}elseif(ereg('^([+-]|\\|\\|)$',$o)){$J=idf_escape($D)." $o $J";}elseif(ereg('^[+-] interval$',$o)){$J=idf_escape($D)." $o ".(preg_match("~^(\\d+|'[0-9.: -]') [A-Z_]+$~i",$Y)?$Y:$J);}elseif(ereg('^(addtime|subtime|concat)$',$o)){$J="$o(".idf_escape($D).", $J)";}elseif(ereg('^(md5|sha1|password|encrypt|hex)$',$o)){$J="$o($J)";}if(ereg("binary",$j["type"])){$J="unhex($J)";}return$J;}function
dumpOutput(){$J=array('text'=>'open','file'=>'save');if(function_exists('gzencode')){$J['gz']='gzip';}if(function_exists('bzcompress')){$J['bz2']='bzip2';}return$J;}function
dumpFormat(){return
array('sql'=>'SQL','csv'=>'CSV,','csv;'=>'CSV;','tsv'=>'TSV');}function
dumpTable($S,$R,$vc=false){if($_POST["format"]!="sql"){echo"\xef\xbb\xbf";if($R){dump_csv(array_keys(fields($S)));}}elseif($R){$Xa=create_sql($S,$_POST["auto_increment"]);if($Xa){if($R=="DROP+CREATE"){echo"DROP ".($vc?"VIEW":"TABLE")." IF EXISTS ".table($S).";\n";}if($vc){$Xa=preg_replace('~^([A-Z =]+) DEFINER=`'.preg_replace('~@(.*)~','`@`(%|\\1)',logged_user()).'`~','\\1',$Xa);}echo($R!="CREATE+ALTER"?$Xa:($vc?substr_replace($Xa," OR REPLACE",6,0):substr_replace($Xa," IF NOT EXISTS",12,0))).";\n\n";}if($R=="CREATE+ALTER"&&!$vc){$H="SELECT COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLLATION_NAME, COLUMN_TYPE, EXTRA, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ".q($S)." ORDER BY ORDINAL_POSITION";echo"DELIMITER ;;
CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
DECLARE _column_name, _collation_name, after varchar(64) DEFAULT '';
DECLARE _column_type, _column_default text;
DECLARE _is_nullable char(3);
DECLARE _extra varchar(30);
DECLARE _column_comment varchar(255);
DECLARE done, set_after bool DEFAULT 0;
DECLARE add_columns text DEFAULT '";$k=array();$oa="";foreach(get_rows($H)as$K){$hb=$K["COLUMN_DEFAULT"];$K["default"]=(isset($hb)?q($hb):"NULL");$K["after"]=q($oa);$K["alter"]=escape_string(idf_escape($K["COLUMN_NAME"])." $K[COLUMN_TYPE]".($K["COLLATION_NAME"]?" COLLATE $K[COLLATION_NAME]":"").(isset($hb)?" DEFAULT ".($hb=="CURRENT_TIMESTAMP"?$hb:$K["default"]):"").($K["IS_NULLABLE"]=="YES"?"":" NOT NULL").($K["EXTRA"]?" $K[EXTRA]":"").($K["COLUMN_COMMENT"]?" COMMENT ".q($K["COLUMN_COMMENT"]):"").($oa?" AFTER ".idf_escape($oa):" FIRST"));echo", ADD $K[alter]";$k[]=$K;$oa=$K["COLUMN_NAME"];}echo"';
DECLARE columns CURSOR FOR $H;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
SET @alter_table = '';
OPEN columns;
REPEAT
FETCH columns INTO _column_name, _column_default, _is_nullable, _collation_name, _column_type, _extra, _column_comment;
IF NOT done THEN
SET set_after = 1;
CASE _column_name";foreach($k
as$K){echo"
WHEN ".q($K["COLUMN_NAME"])." THEN
SET add_columns = REPLACE(add_columns, ', ADD $K[alter]', IF(
_column_default <=> $K[default] AND _is_nullable = '$K[IS_NULLABLE]' AND _collation_name <=> ".(isset($K["COLLATION_NAME"])?"'$K[COLLATION_NAME]'":"NULL")." AND _column_type = ".q($K["COLUMN_TYPE"])." AND _extra = '$K[EXTRA]' AND _column_comment = ".q($K["COLUMN_COMMENT"])." AND after = $K[after]
, '', ', MODIFY $K[alter]'));";}echo"
ELSE
SET @alter_table = CONCAT(@alter_table, ', DROP ', _column_name);
SET set_after = 0;
END CASE;
IF set_after THEN
SET after = _column_name;
END IF;
END IF;
UNTIL done END REPEAT;
CLOSE columns;
IF @alter_table != '' OR add_columns != '' THEN
SET alter_command = CONCAT(alter_command, 'ALTER TABLE ".table($S)."', SUBSTR(CONCAT(add_columns, @alter_table), 2), ';\\n');
END IF;
END;;
DELIMITER ;
CALL adminer_alter(@adminer_alter);
DROP PROCEDURE adminer_alter;
";}}}function
dumpData($S,$R,$H){global$e,$x;$Nc=($x=="sqlite"?0:1048576);if($R){if($_POST["format"]=="sql"&&$R=="TRUNCATE+INSERT"){echo
truncate_sql($S).";\n";}if($_POST["format"]=="sql"){$k=fields($S);}$I=$e->query($H,1);if($I){$sc="";$Ca="";while($K=$I->fetch_assoc()){if($_POST["format"]!="sql"){if($R=="table"){dump_csv(array_keys($K));$R="INSERT";}dump_csv($K);}else{if(!$sc){$sc="INSERT INTO ".table($S)." (".implode(", ",array_map('idf_escape',array_keys($K))).") VALUES";}foreach($K
as$y=>$X){$K[$y]=(isset($X)?(ereg('int|float|double|decimal',$k[$y]["type"])?$X:q($X)):"NULL");}$M=implode(",\t",$K);if($R=="INSERT+UPDATE"){$P=array();foreach($K
as$y=>$X){$P[]=idf_escape($y)." = $X";}echo"$sc ($M) ON DUPLICATE KEY UPDATE ".implode(", ",$P).";\n";}else{$M=($Nc?"\n":" ")."($M)";if(!$Ca){$Ca=$sc.$M;}elseif(strlen($Ca)+4+strlen($M)<$Nc){$Ca.=",$M";}else{echo"$Ca;\n";$Ca=$sc.$M;}}}}if($_POST["format"]=="sql"&&$R!="INSERT+UPDATE"&&$Ca){$Ca.=";\n";echo$Ca;}}elseif($_POST["format"]=="sql"){echo"-- ".str_replace("\n"," ",$e->error)."\n";}}}function
dumpHeaders($kc,$Zc=false){$Ad=$_POST["output"];$Nb=($_POST["format"]=="sql"?"sql":($Zc?"tar":"csv"));header("Content-Type: ".($Ad=="bz2"?"application/x-bzip":($Ad=="gz"?"application/x-gzip":($Nb=="tar"?"application/x-tar":($Nb=="sql"||$Ad!="file"?"text/plain":"text/csv")."; charset=utf-8"))));if($Ad=="bz2"){ob_start('bzcompress',1e6);}if($Ad=="gz"){ob_start('gzencode',1e6);}return$Nb;}function
homepage(){echo'<p>'.($_GET["ns"]==""?'<a href="'.h(ME).'database=">'.'Alter database'."</a>\n":""),(support("scheme")?"<a href='".h(ME)."scheme='>".($_GET["ns"]!=""?'Alter schema':'Create schema')."</a>\n":""),($_GET["ns"]!==""?'<a href="'.h(ME).'schema=">'.'Database schema'."</a>\n":""),(support("privileges")?"<a href='".h(ME)."privileges='>".'Privileges'."</a>\n":"");return
true;}function
navigation($Yc){global$ga,$e,$U,$x,$ob;echo'<h1>
',$this->name(),' <span class="version">',$ga,'</span>
<a href="http://www.adminer.org/#download" id="version">',(version_compare($ga,$_COOKIE["adminer_version"])<0?h($_COOKIE["adminer_version"]):""),'</a>
</h1>
';if($Yc=="auth"){$Ub=true;foreach((array)$_SESSION["pwds"]as$nb=>$_e){foreach($_e
as$O=>$Df){foreach($Df
as$Cf=>$Kd){if(isset($Kd)){if($Ub){echo"<p onclick='eventStop(event);'>\n";$Ub=false;}echo"<a href='".h(auth_url($nb,$O,$Cf))."'>($ob[$nb]) ".h($Cf.($O!=""?"@$O":""))."</a><br>\n";}}}}}else{$g=get_databases();echo'<form action="" method="post">
<p class="logout">
';if(DB==""||!$Yc){echo"<a href='".h(ME)."sql='".bold(isset($_GET["sql"])).">".'SQL command'."</a>\n";if(support("dump")){echo"<a href='".h(ME)."dump=".urlencode(isset($_GET["table"])?$_GET["table"]:$_GET["select"])."' id='dump'".bold(isset($_GET["dump"])).">".'Dump'."</a>\n";}}echo'<input type="submit" name="logout" value="Logout" onclick="eventStop(event);">
<input type="hidden" name="token" value="',$U,'">
</p>
</form>
<form action="">
<p>
';hidden_fields_get();echo($g?html_select("db",array(""=>"(".'database'.")")+$g,DB,"this.form.submit();"):'<input name="db" value="'.h(DB).'">'),'<input type="submit" value="Use"',($g?" class='hidden'":""),' onclick="eventStop(event);">
';if($Yc!="db"&&DB!=""&&$e->select_db(DB)){if($_GET["ns"]!==""&&!$Yc){echo'<p><a href="'.h(ME).'create="'.bold($_GET["create"]==="").">".'Create new table'."</a>\n";$Ve=tables_list();if(!$Ve){echo"<p class='message'>".'No tables.'."\n";}else{$this->tablesPrint($Ve);$Ic=array();foreach($Ve
as$S=>$V){$Ic[]=preg_quote($S,'/');}echo"<script type='text/javascript'>\n","var jushLinks = { $x: [ '".js_escape(ME)."table=\$&', /\\b(".implode("|",$Ic).")\\b/g ] };\n";foreach(array("bac","bra","sqlite_quo","mssql_bra")as$X){echo"jushLinks.$X = jushLinks.$x;\n";}echo"</script>\n";}}}echo(isset($_GET["sql"])?'<input type="hidden" name="sql" value="">':(isset($_GET["schema"])?'<input type="hidden" name="schema" value="">':(isset($_GET["dump"])?'<input type="hidden" name="dump" value="">':""))),"</p></form>\n";}}function
tablesPrint($Ve){echo"<p id='tables'>\n";foreach($Ve
as$S=>$V){echo'<a href="'.h(ME).'select='.urlencode($S).'"'.bold($_GET["select"]==$S).">".'select'."</a> ",'<a href="'.h(ME).'table='.urlencode($S).'"'.bold($_GET["table"]==$S)." title='".'Show structure'."'>".$this->tableName(array("Name"=>$S))."</a><br>\n";}}}$b=(function_exists('adminer_object')?adminer_object():new
Adminer);if(!isset($b->operators)){$b->operators=$qd;}function
page_header($ef,$i="",$Ba=array(),$ff=""){global$ca,$b,$e,$ob;header("Content-Type: text/html; charset=utf-8");if($b->headers()){header("X-Frame-Options: deny");header("X-XSS-Protection: 0");}$gf=$ef.($ff!=""?": ".h($ff):"");$hf=strip_tags($gf.(SERVER!=""&&SERVER!="localhost"?h(" - ".SERVER):"")." - ".$b->name());if(is_ajax()){header("X-AJAX-Title: ".rawurlencode($hf));}else{echo'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en" dir="ltr">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta name="robots" content="noindex">
<title>',$hf,'</title>
<link rel="stylesheet" type="text/css" href="',h(preg_replace("~\\?.*~","",ME))."?file=default.css&amp;version=3.3.3",'">
<script type="text/javascript">
var areYouSure = \'Resend POST data?\';
</script>
<script type="text/javascript" src="',h(preg_replace("~\\?.*~","",ME))."?file=functions.js&amp;version=3.3.3",'"></script>
';if($b->head()){echo'<link rel="shortcut icon" type="image/x-icon" href="',h(preg_replace("~\\?.*~","",ME))."?file=favicon.ico&amp;version=3.3.3",'" id="favicon">
';if(file_exists("adminer.css")){echo'<link rel="stylesheet" type="text/css" href="adminer.css">
';}}echo'
<body class="ltr nojs"',($_POST?"":" onclick=\"return bodyClick(event, '".h(js_escape(DB)."', '".js_escape($_GET["ns"]))."');\"");echo' onkeydown="bodyKeydown(event);" onload="bodyLoad(\'',(is_object($e)?substr($e->server_info,0,3):""),'\');',(isset($_COOKIE["adminer_version"])?"":" verifyVersion();");?>">
<script type="text/javascript">
document.body.className = document.body.className.replace(/(^|\s)nojs(\s|$)/, '$1js$2');
</script>
<div id="content">
<?php
}if(isset($Ba)){$_=substr(preg_replace('~(username|db|ns)=[^&]*&~','',ME),0,-1);echo'<p id="breadcrumb"><a href="'.h($_?$_:".").'">'.$ob[DRIVER].'</a> &raquo; ';$_=substr(preg_replace('~(db|ns)=[^&]*&~','',ME),0,-1);$O=(SERVER!=""?h(SERVER):'Server');if($Ba===false){echo"$O\n";}else{echo"<a href='".($_?h($_):".")."' accesskey='1' title='Alt+Shift+1'>$O</a> &raquo; ";if($_GET["ns"]!=""||(DB!=""&&is_array($Ba))){echo'<a href="'.h($_."&db=".urlencode(DB).(support("scheme")?"&ns=":"")).'">'.h(DB).'</a> &raquo; ';}if(is_array($Ba)){if($_GET["ns"]!=""){echo'<a href="'.h(substr(ME,0,-1)).'">'.h($_GET["ns"]).'</a> &raquo; ';}foreach($Ba
as$y=>$X){$jb=(is_array($X)?$X[1]:$X);if($jb!=""){echo'<a href="'.h(ME."$y=").urlencode(is_array($X)?$X[0]:$X).'">'.h($jb).'</a> &raquo; ';}}}echo"$ef\n";}}echo"<span id='loader'></span>\n","<h2>$gf</h2>\n";restart_session();$Af=preg_replace('~^[^?]*~','',$_SERVER["REQUEST_URI"]);$Wc=$_SESSION["messages"][$Af];if($Wc){echo"<div class='message'>".implode("</div>\n<div class='message'>",$Wc)."</div>\n";unset($_SESSION["messages"][$Af]);}$g=&get_session("dbs");if(DB!=""&&$g&&!in_array(DB,$g,true)){$g=null;}if($i){echo"<div class='error'>$i</div>\n";}define("PAGE_HEADER",1);}function
page_footer($Yc=""){global$b;if(!is_ajax()){echo'</div>
<div id="menu">
';$b->navigation($Yc);echo'</div>
';}}function
int32($C){while($C>=2147483648){$C-=4294967296;}while($C<=-2147483649){$C+=4294967296;}return(int)$C;}function
long2str($W,$If){$M='';foreach($W
as$X){$M.=pack('V',$X);}if($If){return
substr($M,0,end($W));}return$M;}function
str2long($M,$If){$W=array_values(unpack('V*',str_pad($M,4*ceil(strlen($M)/4),"\0")));if($If){$W[]=strlen($M);}return$W;}function
xxtea_mx($Mf,$Lf,$Ne,$xc){return
int32((($Mf>>5&0x7FFFFFF)^$Lf<<2)+(($Lf>>3&0x1FFFFFFF)^$Mf<<4))^int32(($Ne^$Lf)+($xc^$Mf));}function
encrypt_string($Ie,$y){if($Ie==""){return"";}$y=array_values(unpack("V*",pack("H*",md5($y))));$W=str2long($Ie,true);$C=count($W)-1;$Mf=$W[$C];$Lf=$W[0];$G=floor(6+52/($C+1));$Ne=0;while($G-->0){$Ne=int32($Ne+0x9E3779B9);$tb=$Ne>>2&3;for($Bd=0;$Bd<$C;$Bd++){$Lf=$W[$Bd+1];$ad=xxtea_mx($Mf,$Lf,$Ne,$y[$Bd&3^$tb]);$Mf=int32($W[$Bd]+$ad);$W[$Bd]=$Mf;}$Lf=$W[0];$ad=xxtea_mx($Mf,$Lf,$Ne,$y[$Bd&3^$tb]);$Mf=int32($W[$C]+$ad);$W[$C]=$Mf;}return
long2str($W,false);}function
decrypt_string($Ie,$y){if($Ie==""){return"";}$y=array_values(unpack("V*",pack("H*",md5($y))));$W=str2long($Ie,false);$C=count($W)-1;$Mf=$W[$C];$Lf=$W[0];$G=floor(6+52/($C+1));$Ne=int32($G*0x9E3779B9);while($Ne){$tb=$Ne>>2&3;for($Bd=$C;$Bd>0;$Bd--){$Mf=$W[$Bd-1];$ad=xxtea_mx($Mf,$Lf,$Ne,$y[$Bd&3^$tb]);$Lf=int32($W[$Bd]-$ad);$W[$Bd]=$Lf;}$Mf=$W[$C];$ad=xxtea_mx($Mf,$Lf,$Ne,$y[$Bd&3^$tb]);$Lf=int32($W[0]-$ad);$W[0]=$Lf;$Ne=int32($Ne-0x9E3779B9);}return
long2str($W,true);}$e='';$U=$_SESSION["token"];if(!$_SESSION["token"]){$_SESSION["token"]=rand(1,1e6);}$Ld=array();if($_COOKIE["adminer_permanent"]){foreach(explode(" ",$_COOKIE["adminer_permanent"])as$X){list($y)=explode(":",$X);$Ld[$y]=$X;}}if(isset($_POST["server"])){session_regenerate_id();$_SESSION["pwds"][$_POST["driver"]][$_POST["server"]][$_POST["username"]]=$_POST["password"];if($_POST["permanent"]){$y=base64_encode($_POST["driver"])."-".base64_encode($_POST["server"])."-".base64_encode($_POST["username"]);$Vd=$b->permanentLogin();$Ld[$y]="$y:".base64_encode($Vd?encrypt_string($_POST["password"],$Vd):"");cookie("adminer_permanent",implode(" ",$Ld));}if(count($_POST)==($_POST["permanent"]?5:4)||DRIVER!=$_POST["driver"]||SERVER!=$_POST["server"]||$_GET["username"]!==$_POST["username"]){redirect(auth_url($_POST["driver"],$_POST["server"],$_POST["username"]));}}elseif($_POST["logout"]){if($U&&$_POST["token"]!=$U){page_header('Logout','Invalid CSRF token. Send the form again.');page_footer("db");exit;}else{foreach(array("pwds","dbs","queries")as$y){set_session($y,null);}$y=base64_encode(DRIVER)."-".base64_encode(SERVER)."-".base64_encode($_GET["username"]);if($Ld[$y]){unset($Ld[$y]);cookie("adminer_permanent",implode(" ",$Ld));}redirect(substr(preg_replace('~(username|db|ns)=[^&]*&~','',ME),0,-1),'Logout successful.');}}elseif($Ld&&!$_SESSION["pwds"]){session_regenerate_id();$Vd=$b->permanentLogin();foreach($Ld
as$y=>$X){list(,$Ha)=explode(":",$X);list($nb,$O,$Cf)=array_map('base64_decode',explode("-",$y));$_SESSION["pwds"][$nb][$O][$Cf]=decrypt_string(base64_decode($Ha),$Vd);}}function
auth_error($Hb=null){global$e,$b,$U;$Ae=session_name();$i="";if(!$_COOKIE[$Ae]&&$_GET[$Ae]&&ini_bool("session.use_only_cookies")){$i='Session support must be enabled.';}elseif(isset($_GET["username"])){if(($_COOKIE[$Ae]||$_GET[$Ae])&&!$U){$i='Session expired, please login again.';}else{$Kd=&get_session("pwds");if(isset($Kd)){$i=h($Hb?$Hb->getMessage():(is_string($e)?$e:'Invalid credentials.'));$Kd=null;}}}page_header('Login',$i,null);echo"<form action='' method='post' onclick='eventStop(event);'>\n";$b->loginForm();echo"<div>";hidden_fields($_POST,array("driver","server","username","password","permanent"));echo"</div>\n","</form>\n";page_footer("auth");}if(isset($_GET["username"])){if(!class_exists("Min_DB")){unset($_SESSION["pwds"][DRIVER]);page_header('No extension',sprintf('None of the supported PHP extensions (%s) are available.',implode(", ",$Qd)),false);page_footer("auth");exit;}$e=connect();}if(is_string($e)||!$b->login($_GET["username"],get_session("pwds"))){auth_error();exit;}$U=$_SESSION["token"];if(isset($_POST["server"])&&$_POST["token"]){$_POST["token"]=$U;}$i=($_POST?($_POST["token"]==$U?"":'Invalid CSRF token. Send the form again.'):($_SERVER["REQUEST_METHOD"]!="POST"?"":sprintf('Too big POST data. Reduce the data or increase the %s configuration directive.','"post_max_size"')));function
connect_error(){global$e,$U,$i,$ob;$g=array();if(DB!=""){page_header('Database'.": ".h(DB),'Invalid database.',true);}else{if($_POST["db"]&&!$i){queries_redirect(substr(ME,0,-1),'Databases have been dropped.',drop_databases($_POST["db"]));}page_header('Select database',$i,false);echo"<p><a href='".h(ME)."database='>".'Create new database'."</a>\n";foreach(array('privileges'=>'Privileges','processlist'=>'Process list','variables'=>'Variables','status'=>'Status',)as$y=>$X){if(support($y)){echo"<a href='".h(ME)."$y='>$X</a>\n";}}echo"<p>".sprintf('%s version: %s through PHP extension %s',$ob[DRIVER],"<b>$e->server_info</b>","<b>$e->extension</b>")."\n","<p>".sprintf('Logged as: %s',"<b>".h(logged_user())."</b>")."\n";if($_GET["refresh"]){set_session("dbs",null);}$g=get_databases();if($g){$ve=support("scheme");$c=collations();echo"<form action='' method='post'>\n","<table cellspacing='0' class='checkable' onclick='tableClick(event);'>\n","<thead><tr><td>&nbsp;<th>".'Database'."<td>".'Collation'."<td>".'Tables'."</thead>\n";foreach($g
as$h){$oe=h(ME)."db=".urlencode($h);echo"<tr".odd()."><td>".checkbox("db[]",$h,in_array($h,(array)$_POST["db"])),"<th><a href='$oe'>".h($h)."</a>","<td><a href='$oe".($ve?"&amp;ns=":"")."&amp;database=' title='".'Alter database'."'>".nbsp(db_collation($h,$c))."</a>","<td align='right'><a href='$oe&amp;schema=' id='tables-".h($h)."' title='".'Database schema'."'>?</a>","\n";}echo"</table>\n","<script type='text/javascript'>tableCheck();</script>\n","<p><input type='submit' name='drop' value='".'Drop'."'".confirm("formChecked(this, /db/)",1).">\n";echo"<input type='hidden' name='token' value='$U'>\n","<a href='".h(ME)."refresh=1' onclick='eventStop(event);'>".'Refresh'."</a>\n","</form>\n";}}page_footer("db");if($g){echo"<script type='text/javascript'>ajaxSetHtml('".js_escape(ME)."script=connect');</script>\n";}}if(isset($_GET["status"])){$_GET["variables"]=$_GET["status"];}if(!(DB!=""?$e->select_db(DB):isset($_GET["sql"])||isset($_GET["dump"])||isset($_GET["database"])||isset($_GET["processlist"])||isset($_GET["privileges"])||isset($_GET["user"])||isset($_GET["variables"])||$_GET["script"]=="connect")){if(DB!=""){set_session("dbs",null);}connect_error();exit;}function
select($I,$f=null,$jc=""){$Ic=array();$v=array();$d=array();$_a=array();$sf=array();odd('');for($s=0;$K=$I->fetch_row();$s++){if(!$s){echo"<table cellspacing='0' class='nowrap'>\n","<thead><tr>";for($w=0;$w<count($K);$w++){$j=$I->fetch_field();$D=$j->name;$vd=$j->orgtable;$ud=$j->orgname;if($jc){$Ic[$w]=($D=="table"?"table=":($D=="possible_keys"?"indexes=":null));}elseif($vd!=""){if(!isset($v[$vd])){$v[$vd]=array();foreach(indexes($vd,$f)as$u){if($u["type"]=="PRIMARY"){$v[$vd]=array_flip($u["columns"]);break;}}$d[$vd]=$v[$vd];}if(isset($d[$vd][$ud])){unset($d[$vd][$ud]);$v[$vd][$ud]=$w;$Ic[$w]=$vd;}}if($j->charsetnr==63){$_a[$w]=true;}$sf[$w]=$j->type;$D=h($D);echo"<th".($vd!=""||$j->name!=$ud?" title='".h(($vd!=""?"$vd.":"").$ud)."'":"").">".($jc?"<a href='$jc".strtolower($D)."' target='_blank' rel='noreferrer'>$D</a>":$D);}echo"</thead>\n";}echo"<tr".odd().">";foreach($K
as$y=>$X){if(!isset($X)){$X="<i>NULL</i>";}elseif($_a[$y]&&!is_utf8($X)){$X="<i>".lang(array('%d byte','%d bytes'),strlen($X))."</i>";}elseif(!strlen($X)){$X="&nbsp;";}else{$X=h($X);if($sf[$y]==254){$X="<code>$X</code>";}}if(isset($Ic[$y])&&!$d[$Ic[$y]]){if($jc){$_=$Ic[$y].urlencode($K[array_search("table=",$Ic)]);}else{$_="edit=".urlencode($Ic[$y]);foreach($v[$Ic[$y]]as$Ia=>$w){$_.="&where".urlencode("[".bracket_escape($Ia)."]")."=".urlencode($K[$w]);}}$X="<a href='".h(ME.$_)."'>$X</a>";}echo"<td>$X";}}echo($s?"</table>":"<p class='message'>".'No rows.')."\n";}function
referencable_primary($xe){$J=array();foreach(table_status()as$Re=>$S){if($Re!=$xe&&fk_support($S)){foreach(fields($Re)as$j){if($j["primary"]){if($J[$Re]){unset($J[$Re]);break;}$J[$Re]=$j;}}}}return$J;}function
textarea($D,$Y,$L=10,$La=80){echo"<textarea name='$D' rows='$L' cols='$La' class='sqlarea' spellcheck='false' wrap='off' onkeydown='return textareaKeydown(this, event);'>";if(is_array($Y)){foreach($Y
as$X){echo
h($X)."\n\n\n";}}else{echo
h($Y);}echo"</textarea>";}function
format_time($Ee,$_b){return" <span class='time'>(".sprintf('%.3f s',max(0,array_sum(explode(" ",$_b))-array_sum(explode(" ",$Ee)))).")</span>";}function
edit_type($y,$j,$c,$m=array()){global$Je,$sf,$zf,$md;echo'<td><select name="',$y,'[type]" class="type" onfocus="lastType = selectValue(this);" onchange="editingTypeChange(this);">',optionlist((!$j["type"]||isset($sf[$j["type"]])?array():array($j["type"]))+$Je+($m?array('Foreign keys'=>$m):array()),$j["type"]),'</select>
<td><input name="',$y,'[length]" value="',h($j["length"]),'" size="3" onfocus="editingLengthFocus(this);"><td class="options">',"<select name='$y"."[collation]'".(ereg('(char|text|enum|set)$',$j["type"])?"":" class='hidden'").'><option value="">('.'collation'.')'.optionlist($c,$j["collation"]).'</select>',($zf?"<select name='$y"."[unsigned]'".(!$j["type"]||ereg('(int|float|double|decimal)$',$j["type"])?"":" class='hidden'").'><option>'.optionlist($zf,$j["unsigned"]).'</select>':''),($m?"<select name='$y"."[on_delete]'".(ereg("`",$j["type"])?"":" class='hidden'")."><option value=''>(".'ON DELETE'.")".optionlist(explode("|",$md),$j["on_delete"])."</select> ":" ");}function
process_length($Gc){global$Cb;return(preg_match("~^\\s*(?:$Cb)(?:\\s*,\\s*(?:$Cb))*\\s*\$~",$Gc)&&preg_match_all("~$Cb~",$Gc,$Lc)?implode(",",$Lc[0]):preg_replace('~[^0-9,+-]~','',$Gc));}function
process_type($j,$Ja="COLLATE"){global$zf;return" $j[type]".($j["length"]!=""?"(".process_length($j["length"]).")":"").(ereg('int|float|double|decimal',$j["type"])&&in_array($j["unsigned"],$zf)?" $j[unsigned]":"").(ereg('char|text|enum|set',$j["type"])&&$j["collation"]?" $Ja ".q($j["collation"]):"");}function
process_field($j,$qf){return
array(idf_escape($j["field"]),process_type($qf),($j["null"]?" NULL":" NOT NULL"),(isset($j["default"])?" DEFAULT ".(($j["type"]=="timestamp"&&eregi('^CURRENT_TIMESTAMP$',$j["default"]))||($j["type"]=="bit"&&ereg("^([0-9]+|b'[0-1]+')\$",$j["default"]))?$j["default"]:q($j["default"])):""),($j["on_update"]?" ON UPDATE $j[on_update]":""),(support("comment")&&$j["comment"]!=""?" COMMENT ".q($j["comment"]):""),($j["auto_increment"]?auto_increment():null),);}function
type_class($V){foreach(array('char'=>'text','date'=>'time|year','binary'=>'blob','enum'=>'set',)as$y=>$X){if(ereg("$y|$X",$V)){return" class='$y'";}}}function
edit_fields($k,$c,$V="TABLE",$qa=0,$m=array(),$Qa=false){global$qc;echo'<thead><tr class="wrap">
';if($V=="PROCEDURE"){echo'<td>&nbsp;';}echo'<th>',($V=="TABLE"?'Column name':'Parameter name'),'<td>Type<textarea id="enum-edit" rows="4" cols="12" wrap="off" style="display: none;" onblur="editingLengthBlur(this);"></textarea>
<td>Length
<td>Options
';if($V=="TABLE"){echo'<td>NULL
<td><input type="radio" name="auto_increment_col" value=""><acronym title="Auto Increment">AI</acronym>
<td',($_POST["defaults"]?"":" class='hidden'"),'>Default values
',(support("comment")?"<td".($Qa?"":" class='hidden'").">".'Comment':"");}echo'<td>',"<input type='image' name='add[".(support("move_col")?0:count($k))."]' src='".h(preg_replace("~\\?.*~","",ME))."?file=plus.gif&amp;version=3.3.3' alt='+' title='".'Add next'."'>",'<script type="text/javascript">row_count = ',count($k),';</script>
</thead>
<tbody onkeydown="return editingKeydown(event);">
';foreach($k
as$s=>$j){$s++;$wd=$j[($_POST?"orig":"field")];$lb=(isset($_POST["add"][$s-1])||(isset($j["field"])&&!$_POST["drop_col"][$s]))&&(support("drop_col")||$wd=="");echo'<tr',($lb?"":" style='display: none;'"),'>
',($V=="PROCEDURE"?"<td>".html_select("fields[$s][inout]",explode("|",$qc),$j["inout"]):""),'<th>';if($lb){echo'<input name="fields[',$s,'][field]" value="',h($j["field"]),'" onchange="',($j["field"]!=""||count($k)>1?"":"editingAddRow(this, $qa); "),'editingNameChange(this);" maxlength="64">';}echo'<input type="hidden" name="fields[',$s,'][orig]" value="',h($wd),'">
';edit_type("fields[$s]",$j,$c,$m);if($V=="TABLE"){echo'<td>',checkbox("fields[$s][null]",1,$j["null"]),'<td><input type="radio" name="auto_increment_col" value="',$s,'"';if($j["auto_increment"]){echo' checked';}?> onclick="var field = this.form['fields[' + this.value + '][field]']; if (!field.value) { field.value = 'id'; field.onchange(); }">
<td<?php echo($_POST["defaults"]?"":" class='hidden'"),'>',checkbox("fields[$s][has_default]",1,$j["has_default"]),'<input name="fields[',$s,'][default]" value="',h($j["default"]),'" onchange="this.previousSibling.checked = true;">
',(support("comment")?"<td".($Qa?"":" class='hidden'")."><input name='fields[$s][comment]' value='".h($j["comment"])."' maxlength='255'>":"");}echo"<td>",(support("move_col")?"<input type='image' name='add[$s]' src='".h(preg_replace("~\\?.*~","",ME))."?file=plus.gif&amp;version=3.3.3' alt='+' title='".'Add next'."' onclick='return !editingAddRow(this, $qa, 1);'>&nbsp;"."<input type='image' name='up[$s]' src='".h(preg_replace("~\\?.*~","",ME))."?file=up.gif&amp;version=3.3.3' alt='^' title='".'Move up'."'>&nbsp;"."<input type='image' name='down[$s]' src='".h(preg_replace("~\\?.*~","",ME))."?file=down.gif&amp;version=3.3.3' alt='v' title='".'Move down'."'>&nbsp;":""),($wd==""||support("drop_col")?"<input type='image' name='drop_col[$s]' src='".h(preg_replace("~\\?.*~","",ME))."?file=cross.gif&amp;version=3.3.3' alt='x' title='".'Remove'."' onclick='return !editingRemoveRow(this);'>":""),"\n";}}function
process_fields(&$k){ksort($k);$hd=0;if($_POST["up"]){$Ac=0;foreach($k
as$y=>$j){if(key($_POST["up"])==$y){unset($k[$y]);array_splice($k,$Ac,0,array($j));break;}if(isset($j["field"])){$Ac=$hd;}$hd++;}}if($_POST["down"]){$n=false;foreach($k
as$y=>$j){if(isset($j["field"])&&$n){unset($k[key($_POST["down"])]);array_splice($k,$hd,0,array($n));break;}if(key($_POST["down"])==$y){$n=$j;}$hd++;}}$k=array_values($k);if($_POST["add"]){array_splice($k,key($_POST["add"]),0,array(array()));}}function
normalize_enum($B){return"'".str_replace("'","''",addcslashes(stripcslashes(str_replace($B[0][0].$B[0][0],$B[0][0],substr($B[0],1,-1))),'\\'))."'";}function
grant($q,$Xd,$d,$ld){if(!$Xd){return
true;}if($Xd==array("ALL PRIVILEGES","GRANT OPTION")){return($q=="GRANT"?queries("$q ALL PRIVILEGES$ld WITH GRANT OPTION"):queries("$q ALL PRIVILEGES$ld")&&queries("$q GRANT OPTION$ld"));}return
queries("$q ".preg_replace('~(GRANT OPTION)\\([^)]*\\)~','\\1',implode("$d, ",$Xd).$d).$ld);}function
drop_create($pb,$Xa,$A,$Vc,$Tc,$Uc,$D){if($_POST["drop"]){return
query_redirect($pb,$A,$Vc,true,!$_POST["dropped"]);}$qb=$D!=""&&($_POST["dropped"]||queries($pb));$Za=queries($Xa);if(!queries_redirect($A,($D!=""?$Tc:$Uc),$Za)&&$qb){redirect(null,$Vc);}return$qb;}function
tar_file($Sb,$Ta){$J=pack("a100a8a8a8a12a12",$Sb,644,0,0,decoct(strlen($Ta)),decoct(time()));$Ga=8*32;for($s=0;$s<strlen($J);$s++){$Ga+=ord($J{$s});}$J.=sprintf("%06o",$Ga)."\0 ";return$J.str_repeat("\0",512-strlen($J)).$Ta.str_repeat("\0",511-(strlen($Ta)+511)%
512);}session_cache_limiter("");if(!ini_bool("session.use_cookies")||@ini_set("session.use_cookies",false)!==false){session_write_close();}$md="RESTRICT|CASCADE|SET NULL|NO ACTION";$Cb="'(?:''|[^'\\\\]|\\\\.)*+'";$qc="IN|OUT|INOUT";if(isset($_GET["select"])&&($_POST["edit"]||$_POST["clone"])&&!$_POST["save"]){$_GET["edit"]=$_GET["select"];}if(isset($_GET["callf"])){$_GET["call"]=$_GET["callf"];}if(isset($_GET["function"])){$_GET["procedure"]=$_GET["function"];}if(isset($_GET["download"])){$a=$_GET["download"];header("Content-Type: application/octet-stream");header("Content-Disposition: attachment; filename=".friendly_url("$a-".implode("_",$_GET["where"])).".".friendly_url($_GET["field"]));echo$e->result("SELECT".limit(idf_escape($_GET["field"])." FROM ".table($a)," WHERE ".where($_GET),1));exit;}elseif(isset($_GET["table"])){$a=$_GET["table"];$k=fields($a);if(!$k){$i=error();}$T=($k?table_status($a):array());page_header(($k&&is_view($T)?'View':'Table').": ".h($a),$i);$b->selectLinks($T);$Pa=$T["Comment"];if($Pa!=""){echo"<p>".'Comment'.": ".h($Pa)."\n";}if($k){echo"<table cellspacing='0'>\n","<thead><tr><th>".'Column'."<td>".'Type'.(support("comment")?"<td>".'Comment':"")."</thead>\n";foreach($k
as$j){echo"<tr".odd()."><th>".h($j["field"]),"<td title='".h($j["collation"])."'>".h($j["full_type"]).($j["null"]?" <i>NULL</i>":"").($j["auto_increment"]?" <i>".'Auto Increment'."</i>":""),(isset($j["default"])?" [<b>".h($j["default"])."</b>]":""),(support("comment")?"<td>".nbsp($j["comment"]):""),"\n";}echo"</table>\n";if(!is_view($T)){echo"<h3>".'Indexes'."</h3>\n";$v=indexes($a);if($v){echo"<table cellspacing='0'>\n";foreach($v
as$D=>$u){ksort($u["columns"]);$Ud=array();foreach($u["columns"]as$y=>$X){$Ud[]="<i>".h($X)."</i>".($u["lengths"][$y]?"(".$u["lengths"][$y].")":"");}echo"<tr title='".h($D)."'><th>$u[type]<td>".implode(", ",$Ud)."\n";}echo"</table>\n";}echo'<p><a href="'.h(ME).'indexes='.urlencode($a).'">'.'Alter indexes'."</a>\n";if(fk_support($T)){echo"<h3>".'Foreign keys'."</h3>\n";$m=foreign_keys($a);if($m){echo"<table cellspacing='0'>\n","<thead><tr><th>".'Source'."<td>".'Target'."<td>".'ON DELETE'."<td>".'ON UPDATE'.($x!="sqlite"?"<td>&nbsp;":"")."</thead>\n";foreach($m
as$D=>$l){echo"<tr title='".h($D)."'>","<th><i>".implode("</i>, <i>",array_map('h',$l["source"]))."</i>","<td><a href='".h($l["db"]!=""?preg_replace('~db=[^&]*~',"db=".urlencode($l["db"]),ME):($l["ns"]!=""?preg_replace('~ns=[^&]*~',"ns=".urlencode($l["ns"]),ME):ME))."table=".urlencode($l["table"])."'>".($l["db"]!=""?"<b>".h($l["db"])."</b>.":"").($l["ns"]!=""?"<b>".h($l["ns"])."</b>.":"").h($l["table"])."</a>","(<i>".implode("</i>, <i>",array_map('h',$l["target"]))."</i>)","<td>".nbsp($l["on_delete"])."\n","<td>".nbsp($l["on_update"])."\n";if($x!="sqlite"){echo'<td><a href="'.h(ME.'foreign='.urlencode($a).'&name='.urlencode($D)).'">'.'Alter'.'</a>';}}echo"</table>\n";}if($x!="sqlite"){echo'<p><a href="'.h(ME).'foreign='.urlencode($a).'">'.'Add foreign key'."</a>\n";}}if(support("trigger")){echo"<h3>".'Triggers'."</h3>\n";$pf=triggers($a);if($pf){echo"<table cellspacing='0'>\n";foreach($pf
as$y=>$X){echo"<tr valign='top'><td>$X[0]<td>$X[1]<th>".h($y)."<td><a href='".h(ME.'trigger='.urlencode($a).'&name='.urlencode($y))."'>".'Alter'."</a>\n";}echo"</table>\n";}echo'<p><a href="'.h(ME).'trigger='.urlencode($a).'">'.'Add trigger'."</a>\n";}}}}elseif(isset($_GET["schema"])){page_header('Database schema',"",array(),DB.($_GET["ns"]?".$_GET[ns]":""));$Se=array();$Te=array();$D="adminer_schema";$ea=($_GET["schema"]?$_GET["schema"]:$_COOKIE[($_COOKIE["$D-".DB]?"$D-".DB:$D)]);preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~',$ea,$Lc,PREG_SET_ORDER);foreach($Lc
as$s=>$B){$Se[$B[1]]=array($B[2],$B[3]);$Te[]="\n\t'".js_escape($B[1])."': [ $B[2], $B[3] ]";}$if=0;$za=-1;$ue=array();$he=array();$Ec=array();foreach(table_status()as$T){if(!isset($T["Engine"])){continue;}$Nd=0;$ue[$T["Name"]]["fields"]=array();foreach(fields($T["Name"])as$D=>$j){$Nd+=1.25;$j["pos"]=$Nd;$ue[$T["Name"]]["fields"][$D]=$j;}$ue[$T["Name"]]["pos"]=($Se[$T["Name"]]?$Se[$T["Name"]]:array($if,0));foreach($b->foreignKeys($T["Name"])as$X){if(!$X["db"]){$Cc=$za;if($Se[$T["Name"]][1]||$Se[$X["table"]][1]){$Cc=min(floatval($Se[$T["Name"]][1]),floatval($Se[$X["table"]][1]))-1;}else{$za-=.1;}while($Ec[(string)$Cc]){$Cc-=.0001;}$ue[$T["Name"]]["references"][$X["table"]][(string)$Cc]=array($X["source"],$X["target"]);$he[$X["table"]][$T["Name"]][(string)$Cc]=$X["target"];$Ec[(string)$Cc]=true;}}$if=max($if,$ue[$T["Name"]]["pos"][0]+2.5+$Nd);}echo'<div id="schema" style="height: ',$if,'em;">
<script type="text/javascript">
tablePos = {',implode(",",$Te)."\n",'};
em = document.getElementById(\'schema\').offsetHeight / ',$if,';
document.onmousemove = schemaMousemove;
document.onmouseup = function (ev) {
schemaMouseup(ev, \'',js_escape(DB),'\');
};
</script>
';foreach($ue
as$D=>$S){echo"<div class='table' style='top: ".$S["pos"][0]."em; left: ".$S["pos"][1]."em;' onmousedown='schemaMousedown(this, event);'>",'<a href="'.h(ME).'table='.urlencode($D).'"><b>'.h($D)."</b></a><br>\n";foreach($S["fields"]as$j){$X='<span'.type_class($j["type"]).' title="'.h($j["full_type"].($j["null"]?" NULL":'')).'">'.h($j["field"]).'</span>';echo($j["primary"]?"<i>$X</i>":$X)."<br>\n";}foreach((array)$S["references"]as$Ze=>$ie){foreach($ie
as$Cc=>$ee){$Dc=$Cc-$Se[$D][1];$s=0;foreach($ee[0]as$Be){echo"<div class='references' title='".h($Ze)."' id='refs$Cc-".($s++)."' style='left: $Dc"."em; top: ".$S["fields"][$Be]["pos"]."em; padding-top: .5em;'><div style='border-top: 1px solid Gray; width: ".(-$Dc)."em;'></div></div>\n";}}}foreach((array)$he[$D]as$Ze=>$ie){foreach($ie
as$Cc=>$d){$Dc=$Cc-$Se[$D][1];$s=0;foreach($d
as$Ye){echo"<div class='references' title='".h($Ze)."' id='refd$Cc-".($s++)."' style='left: $Dc"."em; top: ".$S["fields"][$Ye]["pos"]."em; height: 1.25em; background: url(".h(preg_replace("~\\?.*~","",ME))."?file=arrow.gif) no-repeat right center;&amp;version=3.3.3'><div style='height: .5em; border-bottom: 1px solid Gray; width: ".(-$Dc)."em;'></div></div>\n";}}}echo"</div>\n";}foreach($ue
as$D=>$S){foreach((array)$S["references"]as$Ze=>$ie){foreach($ie
as$Cc=>$ee){$Xc=$if;$Pc=-10;foreach($ee[0]as$y=>$Be){$Od=$S["pos"][0]+$S["fields"][$Be]["pos"];$Pd=$ue[$Ze]["pos"][0]+$ue[$Ze]["fields"][$ee[1][$y]]["pos"];$Xc=min($Xc,$Od,$Pd);$Pc=max($Pc,$Od,$Pd);}echo"<div class='references' id='refl$Cc' style='left: $Cc"."em; top: $Xc"."em; padding: .5em 0;'><div style='border-right: 1px solid Gray; margin-top: 1px; height: ".($Pc-$Xc)."em;'></div></div>\n";}}}echo'</div>
<p><a href="',h(ME."schema=".urlencode($ea)),'" id="schema-link">Permanent link</a>
';}elseif(isset($_GET["dump"])){$a=$_GET["dump"];if($_POST){$Va="";foreach(array("output","format","db_style","routines","events","table_style","auto_increment","triggers","data_style")as$y){$Va.="&$y=".urlencode($_POST[$y]);}cookie("adminer_export",substr($Va,1));$Nb=dump_headers(($a!=""?$a:DB),(DB==""||count((array)$_POST["tables"]+(array)$_POST["data"])>1));$uc=($_POST["format"]=="sql");if($uc){echo"-- Adminer $ga ".$ob[DRIVER]." dump
".($x!="sql"?"":"SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = ".q($e->result("SELECT @@time_zone")).";
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
");}$R=$_POST["db_style"];$g=array(DB);if(DB==""){$g=$_POST["databases"];if(is_string($g)){$g=explode("\n",rtrim(str_replace("\r","",$g),"\n"));}}foreach((array)$g
as$h){if($e->select_db($h)){if($uc&&ereg('CREATE',$R)&&($Xa=$e->result("SHOW CREATE DATABASE ".idf_escape($h),1))){if($R=="DROP+CREATE"){echo"DROP DATABASE IF EXISTS ".idf_escape($h).";\n";}echo($R=="CREATE+ALTER"?preg_replace('~^CREATE DATABASE ~','\\0IF NOT EXISTS ',$Xa):$Xa).";\n";}if($uc){if($R){echo
use_sql($h).";\n\n";}if(in_array("CREATE+ALTER",array($R,$_POST["table_style"]))){echo"SET @adminer_alter = '';\n\n";}$_d="";if($_POST["routines"]){foreach(array("FUNCTION","PROCEDURE")as$pe){foreach(get_rows("SHOW $pe STATUS WHERE Db = ".q($h),null,"-- ")as$K){$_d.=($R!='DROP+CREATE'?"DROP $pe IF EXISTS ".idf_escape($K["Name"]).";;\n":"").$e->result("SHOW CREATE $pe ".idf_escape($K["Name"]),2).";;\n\n";}}}if($_POST["events"]){foreach(get_rows("SHOW EVENTS",null,"-- ")as$K){$_d.=($R!='DROP+CREATE'?"DROP EVENT IF EXISTS ".idf_escape($K["Name"]).";;\n":"").$e->result("SHOW CREATE EVENT ".idf_escape($K["Name"]),3).";;\n\n";}}if($_d){echo"DELIMITER ;;\n\n$_d"."DELIMITER ;\n\n";}}if($_POST["table_style"]||$_POST["data_style"]){$Gf=array();foreach(table_status()as$T){$S=(DB==""||in_array($T["Name"],(array)$_POST["tables"]));$cb=(DB==""||in_array($T["Name"],(array)$_POST["data"]));if($S||$cb){if(!is_view($T)){if($Nb=="tar"){ob_start();}$b->dumpTable($T["Name"],($S?$_POST["table_style"]:""));if($cb){$b->dumpData($T["Name"],$_POST["data_style"],"SELECT * FROM ".table($T["Name"]));}if($uc&&$_POST["triggers"]&&$S&&($pf=trigger_sql($T["Name"],$_POST["table_style"]))){echo"\nDELIMITER ;;\n$pf\nDELIMITER ;\n";}if($Nb=="tar"){echo
tar_file((DB!=""?"":"$h/")."$T[Name].csv",ob_get_clean());}elseif($uc){echo"\n";}}elseif($uc){$Gf[]=$T["Name"];}}}foreach($Gf
as$Ff){$b->dumpTable($Ff,$_POST["table_style"],true);}if($Nb=="tar"){echo
pack("x512");}}if($R=="CREATE+ALTER"&&$uc){$H="SELECT TABLE_NAME, ENGINE, TABLE_COLLATION, TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE()";echo"DELIMITER ;;
CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN
DECLARE _table_name, _engine, _table_collation varchar(64);
DECLARE _table_comment varchar(64);
DECLARE done bool DEFAULT 0;
DECLARE tables CURSOR FOR $H;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN tables;
REPEAT
FETCH tables INTO _table_name, _engine, _table_collation, _table_comment;
IF NOT done THEN
CASE _table_name";foreach(get_rows($H)as$K){$Pa=q($K["ENGINE"]=="InnoDB"?preg_replace('~(?:(.+); )?InnoDB free: .*~','\\1',$K["TABLE_COMMENT"]):$K["TABLE_COMMENT"]);echo"
WHEN ".q($K["TABLE_NAME"])." THEN
".(isset($K["ENGINE"])?"IF _engine != '$K[ENGINE]' OR _table_collation != '$K[TABLE_COLLATION]' OR _table_comment != $Pa THEN
ALTER TABLE ".idf_escape($K["TABLE_NAME"])." ENGINE=$K[ENGINE] COLLATE=$K[TABLE_COLLATION] COMMENT=$Pa;
END IF":"BEGIN END").";";}echo"
ELSE
SET alter_command = CONCAT(alter_command, 'DROP TABLE `', REPLACE(_table_name, '`', '``'), '`;\\n');
END CASE;
END IF;
UNTIL done END REPEAT;
CLOSE tables;
END;;
DELIMITER ;
CALL adminer_alter(@adminer_alter);
DROP PROCEDURE adminer_alter;
";}if(in_array("CREATE+ALTER",array($R,$_POST["table_style"]))&&$uc){echo"SELECT @adminer_alter;\n";}}}if($uc){echo"-- ".$e->result("SELECT NOW()")."\n";}exit;}page_header('Export',"",($_GET["export"]!=""?array("table"=>$_GET["export"]):array()),DB);echo'
<form action="" method="post">
<table cellspacing="0">
';$fb=array('','USE','DROP+CREATE','CREATE');$Ue=array('','DROP+CREATE','CREATE');$db=array('','TRUNCATE+INSERT','INSERT');if($x=="sql"){$fb[]='CREATE+ALTER';$Ue[]='CREATE+ALTER';$db[]='INSERT+UPDATE';}parse_str($_COOKIE["adminer_export"],$K);if(!$K){$K=array("output"=>"text","format"=>"sql","db_style"=>(DB!=""?"":"CREATE"),"table_style"=>"DROP+CREATE","data_style"=>"INSERT");}if(!isset($K["events"])){$K["routines"]=$K["events"]=($_GET["dump"]=="");$K["triggers"]=$K["table_style"];}echo"<tr><th>".'Output'."<td>".html_select("output",$b->dumpOutput(),$K["output"],0)."\n";echo"<tr><th>".'Format'."<td>".html_select("format",$b->dumpFormat(),$K["format"],0)."\n";echo($x=="sqlite"?"":"<tr><th>".'Database'."<td>".html_select('db_style',$fb,$K["db_style"]).(support("routine")?checkbox("routines",1,$K["routines"],'Routines'):"").(support("event")?checkbox("events",1,$K["events"],'Events'):"")),"<tr><th>".'Tables'."<td>".html_select('table_style',$Ue,$K["table_style"]).checkbox("auto_increment",1,$K["auto_increment"],'Auto Increment').(support("trigger")?checkbox("triggers",1,$K["triggers"],'Triggers'):""),"<tr><th>".'Data'."<td>".html_select('data_style',$db,$K["data_style"]),'</table>
<p><input type="submit" value="Export">
<table cellspacing="0">
';$Sd=array();if(DB!=""){$Fa=($a!=""?"":" checked");echo"<thead><tr>","<th style='text-align: left;'><label><input type='checkbox' id='check-tables'$Fa onclick='formCheck(this, /^tables\\[/);'>".'Tables'."</label>","<th style='text-align: right;'><label>".'Data'."<input type='checkbox' id='check-data'$Fa onclick='formCheck(this, /^data\\[/);'></label>","</thead>\n";$Gf="";foreach(table_status()as$T){$D=$T["Name"];$Rd=ereg_replace("_.*","",$D);$Fa=($a==""||$a==(substr($a,-1)=="%"?"$Rd%":$D));$Ud="<tr><td>".checkbox("tables[]",$D,$Fa,$D,"formUncheck('check-tables');");if(is_view($T)){$Gf.="$Ud\n";}else{echo"$Ud<td align='right'><label>".($T["Engine"]=="InnoDB"&&$T["Rows"]?"~ ":"").$T["Rows"].checkbox("data[]",$D,$Fa,"","formUncheck('check-data');")."</label>\n";}$Sd[$Rd]++;}echo$Gf;}else{echo"<thead><tr><th style='text-align: left;'><label><input type='checkbox' id='check-databases'".($a==""?" checked":"")." onclick='formCheck(this, /^databases\\[/);'>".'Database'."</label></thead>\n";$g=get_databases();if($g){foreach($g
as$h){if(!information_schema($h)){$Rd=ereg_replace("_.*","",$h);echo"<tr><td>".checkbox("databases[]",$h,$a==""||$a=="$Rd%",$h,"formUncheck('check-databases');")."</label>\n";$Sd[$Rd]++;}}}else{echo"<tr><td><textarea name='databases' rows='10' cols='20'></textarea>";}}echo'</table>
</form>
';$Ub=true;foreach($Sd
as$y=>$X){if($y!=""&&$X>1){echo($Ub?"<p>":" ")."<a href='".h(ME)."dump=".urlencode("$y%")."'>".h($y)."</a>";$Ub=false;}}}elseif(isset($_GET["privileges"])){page_header('Privileges');$I=$e->query("SELECT User, Host FROM mysql.".(DB==""?"user":"db WHERE ".q(DB)." LIKE Db")." ORDER BY Host, User");$q=$I;if(!$I){$I=$e->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1) AS User, SUBSTRING_INDEX(CURRENT_USER, '@', -1) AS Host");}echo"<form action=''><p>\n";hidden_fields_get();echo"<input type='hidden' name='db' value='".h(DB)."'>\n",($q?"":"<input type='hidden' name='grant' value=''>\n"),"<table cellspacing='0'>\n","<thead><tr><th>".'Username'."<th>".'Server'."<th>&nbsp;</thead>\n";while($K=$I->fetch_assoc()){echo'<tr'.odd().'><td>'.h($K["User"])."<td>".h($K["Host"]).'<td><a href="'.h(ME.'user='.urlencode($K["User"]).'&host='.urlencode($K["Host"])).'">'.'Edit'."</a>\n";}if(!$q||DB!=""){echo"<tr".odd()."><td><input name='user'><td><input name='host' value='localhost'><td><input type='submit' value='".'Edit'."'>\n";}echo"</table>\n","</form>\n",'<p><a href="'.h(ME).'user=">'.'Create user'."</a>";}elseif(isset($_GET["sql"])){if(!$i&&$_POST["export"]){dump_headers("sql");$b->dumpTable("","");$b->dumpData("","table",$_POST["query"]);exit;}restart_session();$hc=&get_session("queries");$gc=&$hc[DB];if(!$i&&$_POST["clear"]){$gc=array();redirect(remove_from_uri("history"));}page_header('SQL command',$i);if(!$i&&$_POST){$Zb=false;$H=$_POST["query"];if($_POST["webfile"]){$Zb=@fopen((file_exists("adminer.sql")?"adminer.sql":(file_exists("adminer.sql.gz")?"compress.zlib://adminer.sql.gz":"compress.bzip2://adminer.sql.bz2")),"rb");$H=($Zb?fread($Zb,1e6):false);}elseif($_FILES&&$_FILES["sql_file"]["error"]!=4){$H=get_file("sql_file",true);}if(is_string($H)){if(function_exists('memory_get_usage')){@ini_set("memory_limit",max(ini_get("memory_limit"),2*strlen($H)+memory_get_usage()+8e6));}if($H!=""&&strlen($H)<1e6){$G=$H.(ereg(';$',$H)?"":";");if(!$gc||end($gc)!=$G){$gc[]=$G;}}$Ce="(?:\\s|/\\*.*\\*/|(?:#|-- )[^\n]*\n|--\n)";if(!ini_bool("session.use_cookies")){session_write_close();}$ib=";";$hd=0;$zb=true;$f=connect();if(is_object($f)&&DB!=""){$f->select_db(DB);}$Oa=0;$Eb=array();$Ed='[\'"'.($x=="sql"?'`#':($x=="sqlite"?'`[':($x=="mssql"?'[':''))).']|/\\*|-- |$'.($x=="pgsql"?'|\\$[^$]*\\$':'');$jf=microtime();parse_str($_COOKIE["adminer_export"],$ka);$sb=$b->dumpFormat();unset($sb["sql"]);while($H!=""){if(!$hd&&preg_match("~^$Ce*DELIMITER\\s+(.+)~i",$H,$B)){$ib=$B[1];$H=substr($H,strlen($B[0]));}else{preg_match('('.preg_quote($ib)."|$Ed)",$H,$B,PREG_OFFSET_CAPTURE,$hd);$n=$B[0][0];if(!$n&&$Zb&&!feof($Zb)){$H.=fread($Zb,1e5);}else{$hd=$B[0][1]+strlen($n);if(!$n&&rtrim($H)==""){break;}if($n&&$n!=$ib){while(preg_match('('.($n=='/*'?'\\*/':($n=='['?']':(ereg('^-- |^#',$n)?"\n":preg_quote($n)."|\\\\."))).'|$)s',$H,$B,PREG_OFFSET_CAPTURE,$hd)){$M=$B[0][0];$hd=$B[0][1]+strlen($M);if(!$M&&$Zb&&!feof($Zb)){$hd-=strlen($n);$H.=fread($Zb,1e5);}elseif($M[0]!="\\"){break;}}}else{$zb=false;$G=substr($H,0,$B[0][1]);$Oa++;$Ud="<pre id='sql-$Oa'><code class='jush-$x'>".shorten_utf8(trim($G),1000)."</code></pre>\n";if(!$_POST["only_errors"]){echo$Ud;ob_flush();flush();}$Ee=microtime();if($e->multi_query($G)&&is_object($f)&&preg_match("~^$Ce*USE\\b~isU",$G)){$f->query($G);}do{$I=$e->store_result();$_b=microtime();$cf=format_time($Ee,$_b).(strlen($G)<1000?" <a href='".h(ME)."sql=".urlencode(trim($G))."'>".'Edit'."</a>":"");if($e->error){echo($_POST["only_errors"]?$Ud:""),"<p class='error'>".'Error in query'.": ".error()."\n";$Eb[]=" <a href='#sql-$Oa'>$Oa</a>";if($_POST["error_stops"]){break
2;}}elseif(is_object($I)){select($I,$f);if(!$_POST["only_errors"]){echo"<form action='' method='post'>\n","<p>".($I->num_rows?lang(array('%d row','%d rows'),$I->num_rows):"").$cf;$t="export-$Oa";$Mb=", <a href='#$t' onclick=\"return !toggle('$t');\">".'Export'."</a><span id='$t' class='hidden'>: ".html_select("output",$b->dumpOutput(),$ka["output"])." ".html_select("format",$sb,$ka["format"])."<input type='hidden' name='query' value='".h($G)."'>"." <input type='submit' name='export' value='".'Export'."' onclick='eventStop(event);'><input type='hidden' name='token' value='$U'></span>\n";if($f&&preg_match("~^($Ce|\\()*SELECT\\b~isU",$G)&&($Lb=explain($f,$G))){$t="explain-$Oa";echo", <a href='#$t' onclick=\"return !toggle('$t');\">EXPLAIN</a>$Mb","<div id='$t' class='hidden'>\n";select($Lb,$f,($x=="sql"?"http://dev.mysql.com/doc/refman/".substr($e->server_info,0,3)."/en/explain-output.html#explain_":""));echo"</div>\n";}else{echo$Mb;}echo"</form>\n";}}else{if(preg_match("~^$Ce*(CREATE|DROP|ALTER)$Ce+(DATABASE|SCHEMA)\\b~isU",$G)){restart_session();set_session("dbs",null);session_write_close();}if(!$_POST["only_errors"]){echo"<p class='message' title='".h($e->info)."'>".lang(array('Query executed OK, %d row affected.','Query executed OK, %d rows affected.'),$e->affected_rows)."$cf\n";}}$Ee=$_b;}while($e->next_result());$H=substr($H,$hd);$hd=0;}}}}if($zb){echo"<p class='message'>".'No commands to execute.'."\n";}elseif($_POST["only_errors"]){echo"<p class='message'>".lang(array('%d query executed OK.','%d queries executed OK.'),$Oa-count($Eb)).format_time($jf,microtime())."\n";}elseif($Eb&&$Oa>1){echo"<p class='error'>".'Error in query'.": ".implode("",$Eb)."\n";}}else{echo"<p class='error'>".upload_error($H)."\n";}}echo'
<form action="" method="post" enctype="multipart/form-data" id="form">
<p>';$G=$_GET["sql"];if($_POST){$G=$_POST["query"];}elseif($_GET["history"]=="all"){$G=$gc;}elseif($_GET["history"]!=""){$G=$gc[$_GET["history"]];}textarea("query",$G,20);echo($_POST?"":"<script type='text/javascript'>document.getElementsByTagName('textarea')[0].focus();</script>\n"),"<p>".(ini_bool("file_uploads")?'File upload'.': <input type="file" name="sql_file"'.($_FILES&&$_FILES["sql_file"]["error"]!=4?'':' onchange="this.form[\'only_errors\'].checked = true;"').'> (&lt; '.ini_get("upload_max_filesize").'B)':'File uploads are disabled.'),'<p>
<input type="submit" value="Execute" title="Ctrl+Enter">
<input type="hidden" name="token" value="',$U,'">
',checkbox("error_stops",1,$_POST["error_stops"],'Stop on error')."\n",checkbox("only_errors",1,$_POST["only_errors"],'Show only errors')."\n";print_fieldset("webfile",'From server',$_POST["webfile"],"document.getElementById('form')['only_errors'].checked = true; ");$Ra=array();foreach(array("gz"=>"zlib","bz2"=>"bz2")as$y=>$X){if(extension_loaded($X)){$Ra[]=".$y";}}echo
sprintf('Webserver file %s',"<code>adminer.sql".($Ra?"[".implode("|",$Ra)."]":"")."</code>"),' <input type="submit" name="webfile" value="'.'Run file'.'">',"</div></fieldset>\n";if($gc){print_fieldset("history",'History',$_GET["history"]!="");foreach($gc
as$y=>$X){echo'<a href="'.h(ME."sql=&history=$y").'">'.'Edit'."</a> <code class='jush-$x'>".shorten_utf8(ltrim(str_replace("\n"," ",str_replace("\r","",preg_replace('~^(#|-- ).*~m','',$X)))),80,"</code>")."<br>\n";}echo"<input type='submit' name='clear' value='".'Clear'."'>\n","<a href='".h(ME."sql=&history=all")."'>".'Edit all'."</a>\n","</div></fieldset>\n";}echo'
</form>
';}elseif(isset($_GET["edit"])){$a=$_GET["edit"];$Z=(isset($_GET["select"])?(count($_POST["check"])==1?where_check($_POST["check"][0]):""):where($_GET));$_f=(isset($_GET["select"])?$_POST["edit"]:$Z);$k=fields($a);foreach($k
as$D=>$j){if(!isset($j["privileges"][$_f?"update":"insert"])||$b->fieldName($j)==""){unset($k[$D]);}}if($_POST&&!$i&&!isset($_GET["select"])){$A=$_POST["referer"];if($_POST["insert"]){$A=($_f?null:$_SERVER["REQUEST_URI"]);}elseif(!ereg('^.+&select=.+$',$A)){$A=ME."select=".urlencode($a);}if(isset($_POST["delete"])){query_redirect("DELETE".limit1("FROM ".table($a)," WHERE $Z"),$A,'Item has been deleted.');}else{$P=array();foreach($k
as$D=>$j){$X=process_input($j);if($X!==false&&$X!==null){$P[idf_escape($D)]=($_f?"\n".idf_escape($D)." = $X":$X);}}if($_f){if(!$P){redirect($A);}query_redirect("UPDATE".limit1(table($a)." SET".implode(",",$P),"\nWHERE $Z"),$A,'Item has been updated.');}else{$I=insert_into($a,$P);$Bc=($I?last_id():0);queries_redirect($A,sprintf('Item%s has been inserted.',($Bc?" $Bc":"")),$I);}}}$Re=$b->tableName(table_status($a));page_header(($_f?'Edit':'Insert'),$i,array("select"=>array($a,$Re)),$Re);$K=null;if($_POST["save"]){$K=(array)$_POST["fields"];}elseif($Z){$N=array();foreach($k
as$D=>$j){if(isset($j["privileges"]["select"])){$N[]=($_POST["clone"]&&$j["auto_increment"]?"'' AS ":(ereg("enum|set",$j["type"])?"1*".idf_escape($D)." AS ":"")).idf_escape($D);}}$K=array();if($N){$L=get_rows("SELECT".limit(implode(", ",$N)." FROM ".table($a)," WHERE $Z",(isset($_GET["select"])?2:1)));$K=(isset($_GET["select"])&&count($L)!=1?null:reset($L));}}if($K===false){echo"<p class='error'>".'No rows.'."\n";}echo'
<form action="" method="post" enctype="multipart/form-data" id="form">
';if($k){echo"<table cellspacing='0' onkeydown='return editingKeydown(event);'>\n";foreach($k
as$D=>$j){echo"<tr><th>".$b->fieldName($j);$hb=$_GET["set"][bracket_escape($D)];$Y=(isset($K)?($K[$D]!=""&&ereg("enum|set",$j["type"])?(is_array($K[$D])?array_sum($K[$D]):+$K[$D]):$K[$D]):(!$_f&&$j["auto_increment"]?"":(isset($_GET["select"])?false:(isset($hb)?$hb:$j["default"]))));if(!$_POST["save"]&&is_string($Y)){$Y=$b->editVal($Y,$j);}$o=($_POST["save"]?(string)$_POST["function"][$D]:($_f&&$j["on_update"]=="CURRENT_TIMESTAMP"?"now":($Y===false?null:(isset($Y)?'':'NULL'))));if($j["type"]=="timestamp"&&$Y=="CURRENT_TIMESTAMP"){$Y="";$o="now";}input($j,$Y,$o);echo"\n";}echo"</table>\n";}echo'<p>
';if($k){echo"<input type='submit' value='".'Save'."'>\n";if(!isset($_GET["select"])){echo"<input type='submit' name='insert' value='".($_f?'Save and continue edit':'Save and insert next')."' title='Ctrl+Shift+Enter'>\n";}}echo($_f?"<input type='submit' name='delete' value='".'Delete'."' onclick=\"return confirm('".'Are you sure?'."');\">\n":($_POST||!$k?"":"<script type='text/javascript'>document.getElementById('form').getElementsByTagName('td')[1].firstChild.focus();</script>\n"));if(isset($_GET["select"])){hidden_fields(array("check"=>(array)$_POST["check"],"clone"=>$_POST["clone"],"all"=>$_POST["all"]));}echo'<input type="hidden" name="referer" value="',h(isset($_POST["referer"])?$_POST["referer"]:$_SERVER["HTTP_REFERER"]),'">
<input type="hidden" name="save" value="1">
<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["create"])){$a=$_GET["create"];$Fd=array('HASH','LINEAR HASH','KEY','LINEAR KEY','RANGE','LIST');$ge=referencable_primary($a);$m=array();foreach($ge
as$Re=>$j){$m[str_replace("`","``",$Re)."`".str_replace("`","``",$j["field"])]=$Re;}$yd=array();$zd=array();if($a!=""){$yd=fields($a);$zd=table_status($a);}if($_POST&&!$_POST["fields"]){$_POST["fields"]=array();}if($_POST&&!$i&&!$_POST["add"]&&!$_POST["drop_col"]&&!$_POST["up"]&&!$_POST["down"]){if($_POST["drop"]){query_redirect("DROP TABLE ".table($a),substr(ME,0,-1),'Table has been dropped.');}else{$k=array();$Wb=array();ksort($_POST["fields"]);$xd=reset($yd);$oa="FIRST";foreach($_POST["fields"]as$y=>$j){$l=$m[$j["type"]];$qf=(isset($l)?$ge[$l]:$j);if($j["field"]!=""){if(!$j["has_default"]){$j["default"]=null;}$hb=eregi_replace(" *on update CURRENT_TIMESTAMP","",$j["default"]);if($hb!=$j["default"]){$j["on_update"]="CURRENT_TIMESTAMP";$j["default"]=$hb;}if($y==$_POST["auto_increment_col"]){$j["auto_increment"]=true;}$Zd=process_field($j,$qf);if($Zd!=process_field($xd,$xd)){$k[]=array($j["orig"],$Zd,$oa);}if(isset($l)){$Wb[idf_escape($j["field"])]=($a!=""?"ADD":" ")." FOREIGN KEY (".idf_escape($j["field"]).") REFERENCES ".table($m[$j["type"]])." (".idf_escape($qf["field"]).")".(ereg("^($md)\$",$j["on_delete"])?" ON DELETE $j[on_delete]":"");}$oa="AFTER ".idf_escape($j["field"]);}elseif($j["orig"]!=""){$k[]=array($j["orig"]);}if($j["orig"]!=""){$xd=next($yd);}}$Hd="";if(in_array($_POST["partition_by"],$Fd)){$Id=array();if($_POST["partition_by"]=='RANGE'||$_POST["partition_by"]=='LIST'){foreach(array_filter($_POST["partition_names"])as$y=>$X){$Y=$_POST["partition_values"][$y];$Id[]="\nPARTITION ".idf_escape($X)." VALUES ".($_POST["partition_by"]=='RANGE'?"LESS THAN":"IN").($Y!=""?" ($Y)":" MAXVALUE");}}$Hd.="\nPARTITION BY $_POST[partition_by]($_POST[partition])".($Id?" (".implode(",",$Id)."\n)":($_POST["partitions"]?" PARTITIONS ".(+$_POST["partitions"]):""));}elseif($a!=""&&support("partitioning")){$Hd.="\nREMOVE PARTITIONING";}$Sc='Table has been altered.';if($a==""){cookie("adminer_engine",$_POST["Engine"]);$Sc='Table has been created.';}queries_redirect(ME."table=".urlencode($_POST["name"]),$Sc,alter_table($a,$_POST["name"],$k,$Wb,$_POST["Comment"],($_POST["Engine"]&&$_POST["Engine"]!=$zd["Engine"]?$_POST["Engine"]:""),($_POST["Collation"]&&$_POST["Collation"]!=$zd["Collation"]?$_POST["Collation"]:""),($_POST["Auto_increment"]!=""?+$_POST["Auto_increment"]:""),$Hd));}}page_header(($a!=""?'Alter table':'Create table'),$i,array("table"=>$a),$a);$K=array("Engine"=>$_COOKIE["adminer_engine"],"fields"=>array(array("field"=>"","type"=>(isset($sf["int"])?"int":(isset($sf["integer"])?"integer":"")))),"partition_names"=>array(""),);if($_POST){$K=$_POST;if($K["auto_increment_col"]){$K["fields"][$K["auto_increment_col"]]["auto_increment"]=true;}process_fields($K["fields"]);}elseif($a!=""){$K=$zd;$K["name"]=$a;$K["fields"]=array();if(!$_GET["auto_increment"]){$K["Auto_increment"]="";}foreach($yd
as$j){$j["has_default"]=isset($j["default"]);if($j["on_update"]){$j["default"].=" ON UPDATE $j[on_update]";}$K["fields"][]=$j;}if(support("partitioning")){$ac="FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = ".q(DB)." AND TABLE_NAME = ".q($a);$I=$e->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $ac ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");list($K["partition_by"],$K["partitions"],$K["partition"])=$I->fetch_row();$K["partition_names"]=array();$K["partition_values"]=array();foreach(get_rows("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $ac AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION")as$se){$K["partition_names"][]=$se["PARTITION_NAME"];$K["partition_values"][]=$se["PARTITION_DESCRIPTION"];}$K["partition_names"][]="";}}$c=collations();$Me=floor(extension_loaded("suhosin")?(min(ini_get("suhosin.request.max_vars"),ini_get("suhosin.post.max_vars"))-13)/10:0);if($Me&&count($K["fields"])>$Me){echo"<p class='error'>".h(sprintf('Maximum number of allowed fields exceeded. Please increase %s and %s.','suhosin.post.max_vars','suhosin.request.max_vars'))."\n";}$Bb=engines();foreach($Bb
as$Ab){if(!strcasecmp($Ab,$K["Engine"])){$K["Engine"]=$Ab;break;}}echo'
<form action="" method="post" id="form">
<p>
Table name: <input name="name" maxlength="64" value="',h($K["name"]),'">
';if($a==""&&!$_POST){?><script type='text/javascript'>document.getElementById('form')['name'].focus();</script><?php }echo($Bb?html_select("Engine",array(""=>"(".'engine'.")")+$Bb,$K["Engine"]):""),' ',($c&&!ereg("sqlite|mssql",$x)?html_select("Collation",array(""=>"(".'collation'.")")+$c,$K["Collation"]):""),' <input type="submit" value="Save">
<table cellspacing="0" id="edit-fields" class="nowrap">
';$Qa=($_POST?$_POST["comments"]:$K["Comment"]!="");if(!$_POST&&!$Qa){foreach($K["fields"]as$j){if($j["comment"]!=""){$Qa=true;break;}}}edit_fields($K["fields"],$c,"TABLE",$Me,$m,$Qa);echo'</table>
<p>
Auto Increment: <input name="Auto_increment" size="6" value="',h($K["Auto_increment"]),'">
<label class="jsonly"><input type="checkbox" name="defaults" value="1"',($_POST["defaults"]?" checked":""),' onclick="columnShow(this.checked, 5);">Default values</label>
',(support("comment")?checkbox("comments",1,$Qa,'Comment',"columnShow(this.checked, 6); toggle('Comment'); if (this.checked) this.form['Comment'].focus();",true).' <input id="Comment" name="Comment" value="'.h($K["Comment"]).'" maxlength="60"'.($Qa?'':' class="hidden"').'>':''),'<p>
<input type="submit" value="Save">
';if($_GET["create"]!=""){echo'<input type="submit" name="drop" value="Drop"',confirm(),'>';}echo'<input type="hidden" name="token" value="',$U,'">
';if(support("partitioning")){$Gd=ereg('RANGE|LIST',$K["partition_by"]);print_fieldset("partition",'Partition by',$K["partition_by"]);echo'<p>
',html_select("partition_by",array(-1=>"")+$Fd,$K["partition_by"],"partitionByChange(this);"),'(<input name="partition" value="',h($K["partition"]),'">)
Partitions: <input name="partitions" size="2" value="',h($K["partitions"]),'"',($Gd||!$K["partition_by"]?" class='hidden'":""),'>
<table cellspacing="0" id="partition-table"',($Gd?"":" class='hidden'"),'>
<thead><tr><th>Partition name<th>Values</thead>
';foreach($K["partition_names"]as$y=>$X){echo'<tr>','<td><input name="partition_names[]" value="'.h($X).'"'.($y==count($K["partition_names"])-1?' onchange="partitionNameChange(this);"':'').'>','<td><input name="partition_values[]" value="'.h($K["partition_values"][$y]).'">';}echo'</table>
</div></fieldset>
';}echo'</form>
';}elseif(isset($_GET["indexes"])){$a=$_GET["indexes"];$oc=array("PRIMARY","UNIQUE","INDEX");$T=table_status($a);if(eregi("MyISAM|M?aria",$T["Engine"])){$oc[]="FULLTEXT";}$v=indexes($a);if($x=="sqlite"){unset($oc[0]);unset($v[""]);}if($_POST&&!$i&&!$_POST["add"]){$ra=array();foreach($_POST["indexes"]as$u){$D=$u["name"];if(in_array($u["type"],$oc)){$d=array();$Hc=array();$P=array();ksort($u["columns"]);foreach($u["columns"]as$y=>$Ma){if($Ma!=""){$Gc=$u["lengths"][$y];$P[]=idf_escape($Ma).($Gc?"(".(+$Gc).")":"");$d[]=$Ma;$Hc[]=($Gc?$Gc:null);}}if($d){$Kb=$v[$D];if($Kb){ksort($Kb["columns"]);ksort($Kb["lengths"]);if($u["type"]==$Kb["type"]&&array_values($Kb["columns"])===$d&&(!$Kb["lengths"]||array_values($Kb["lengths"])===$Hc)){unset($v[$D]);continue;}}$ra[]=array($u["type"],$D,"(".implode(", ",$P).")");}}}foreach($v
as$D=>$Kb){$ra[]=array($Kb["type"],$D,"DROP");}if(!$ra){redirect(ME."table=".urlencode($a));}queries_redirect(ME."table=".urlencode($a),'Indexes have been altered.',alter_indexes($a,$ra));}page_header('Indexes',$i,array("table"=>$a),$a);$k=array_keys(fields($a));$K=array("indexes"=>$v);if($_POST){$K=$_POST;if($_POST["add"]){foreach($K["indexes"]as$y=>$u){if($u["columns"][count($u["columns"])]!=""){$K["indexes"][$y]["columns"][]="";}}$u=end($K["indexes"]);if($u["type"]||array_filter($u["columns"],'strlen')||array_filter($u["lengths"],'strlen')){$K["indexes"][]=array("columns"=>array(1=>""));}}}else{foreach($K["indexes"]as$y=>$u){$K["indexes"][$y]["name"]=$y;$K["indexes"][$y]["columns"][]="";}$K["indexes"][]=array("columns"=>array(1=>""));}echo'
<form action="" method="post">
<table cellspacing="0" class="nowrap">
<thead><tr><th>Index Type<th>Column (length)<th>Name</thead>
';$w=1;foreach($K["indexes"]as$u){echo"<tr><td>".html_select("indexes[$w][type]",array(-1=>"")+$oc,$u["type"],($w==count($K["indexes"])?"indexesAddRow(this);":1))."<td>";ksort($u["columns"]);$s=1;foreach($u["columns"]as$y=>$Ma){echo"<span>".html_select("indexes[$w][columns][$s]",array(-1=>"")+$k,$Ma,($s==count($u["columns"])?"indexesAddColumn":"indexesChangeColumn")."(this, '".js_escape($x=="sql"?"":$_GET["indexes"]."_")."');"),"<input name='indexes[$w][lengths][$s]' size='2' value='".h($u["lengths"][$y])."'> </span>";$s++;}echo"<td><input name='indexes[$w][name]' value='".h($u["name"])."'>\n";$w++;}echo'</table>
<p>
<input type="submit" value="Save">
<noscript><p><input type="submit" name="add" value="Add next"></noscript>
<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["database"])){if($_POST&&!$i&&!isset($_POST["add_x"])){restart_session();if($_POST["drop"]){$_GET["db"]="";queries_redirect(remove_from_uri("db|database"),'Database has been dropped.',drop_databases(array(DB)));}elseif(DB!==$_POST["name"]){if(DB!=""){$_GET["db"]=$_POST["name"];queries_redirect(preg_replace('~db=[^&]*&~','',ME)."db=".urlencode($_POST["name"]),'Database has been renamed.',rename_database($_POST["name"],$_POST["collation"]));}else{$g=explode("\n",str_replace("\r","",$_POST["name"]));$Ke=true;$Ac="";foreach($g
as$h){if(count($g)==1||$h!=""){if(!create_database($h,$_POST["collation"])){$Ke=false;}$Ac=$h;}}queries_redirect(ME."db=".urlencode($Ac),'Database has been created.',$Ke);}}else{if(!$_POST["collation"]){redirect(substr(ME,0,-1));}query_redirect("ALTER DATABASE ".idf_escape($_POST["name"]).(eregi('^[a-z0-9_]+$',$_POST["collation"])?" COLLATE $_POST[collation]":""),substr(ME,0,-1),'Database has been altered.');}}page_header(DB!=""?'Alter database':'Create database',$i,array(),DB);$c=collations();$D=DB;$Ja=null;if($_POST){$D=$_POST["name"];$Ja=$_POST["collation"];}elseif(DB!=""){$Ja=db_collation(DB,$c);}elseif($x=="sql"){foreach(get_vals("SHOW GRANTS")as$q){if(preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~',$q,$B)&&$B[1]){$D=stripcslashes(idf_unescape("`$B[2]`"));break;}}}echo'
<form action="" method="post">
<p>
',($_POST["add_x"]||strpos($D,"\n")?'<textarea id="name" name="name" rows="10" cols="40">'.h($D).'</textarea><br>':'<input id="name" name="name" value="'.h($D).'" maxlength="64">')."\n".($c?html_select("collation",array(""=>"(".'collation'.")")+$c,$Ja):"");?>
<script type='text/javascript'>document.getElementById('name').focus();</script>
<input type="submit" value="Save">
<?php
if(DB!=""){echo"<input type='submit' name='drop' value='".'Drop'."'".confirm().">\n";}elseif(!$_POST["add_x"]&&$_GET["db"]==""){echo"<input type='image' name='add' src='".h(preg_replace("~\\?.*~","",ME))."?file=plus.gif&amp;version=3.3.3' alt='+' title='".'Add next'."'>\n";}echo'<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["call"])){$da=$_GET["call"];page_header('Call'.": ".h($da),$i);$pe=routine($da,(isset($_GET["callf"])?"FUNCTION":"PROCEDURE"));$nc=array();$_d=array();foreach($pe["fields"]as$s=>$j){if(substr($j["inout"],-3)=="OUT"){$_d[$s]="@".idf_escape($j["field"])." AS ".idf_escape($j["field"]);}if(!$j["inout"]||substr($j["inout"],0,2)=="IN"){$nc[]=$s;}}if(!$i&&$_POST){$Da=array();foreach($pe["fields"]as$y=>$j){if(in_array($y,$nc)){$X=process_input($j);if($X===false){$X="''";}if(isset($_d[$y])){$e->query("SET @".idf_escape($j["field"])." = $X");}}$Da[]=(isset($_d[$y])?"@".idf_escape($j["field"]):$X);}$H=(isset($_GET["callf"])?"SELECT":"CALL")." ".idf_escape($da)."(".implode(", ",$Da).")";echo"<p><code class='jush-$x'>".h($H)."</code> <a href='".h(ME)."sql=".urlencode($H)."'>".'Edit'."</a>\n";if(!$e->multi_query($H)){echo"<p class='error'>".error()."\n";}else{$f=connect();if(is_object($f)){$f->select_db(DB);}do{$I=$e->store_result();if(is_object($I)){select($I,$f);}else{echo"<p class='message'>".lang(array('Routine has been called, %d row affected.','Routine has been called, %d rows affected.'),$e->affected_rows)."\n";}}while($e->next_result());if($_d){select($e->query("SELECT ".implode(", ",$_d)));}}}echo'
<form action="" method="post">
';if($nc){echo"<table cellspacing='0'>\n";foreach($nc
as$y){$j=$pe["fields"][$y];$D=$j["field"];echo"<tr><th>".$b->fieldName($j);$Y=$_POST["fields"][$D];if($Y!=""){if($j["type"]=="enum"){$Y=+$Y;}if($j["type"]=="set"){$Y=array_sum($Y);}}input($j,$Y,(string)$_POST["function"][$D]);echo"\n";}echo"</table>\n";}echo'<p>
<input type="submit" value="Call">
<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["foreign"])){$a=$_GET["foreign"];if($_POST&&!$i&&!$_POST["add"]&&!$_POST["change"]&&!$_POST["change-js"]){if($_POST["drop"]){query_redirect("ALTER TABLE ".table($a)."\nDROP ".($x=="sql"?"FOREIGN KEY ":"CONSTRAINT ").idf_escape($_GET["name"]),ME."table=".urlencode($a),'Foreign key has been dropped.');}else{$Be=array_filter($_POST["source"],'strlen');ksort($Be);$Ye=array();foreach($Be
as$y=>$X){$Ye[$y]=$_POST["target"][$y];}query_redirect("ALTER TABLE ".table($a).($_GET["name"]!=""?"\nDROP FOREIGN KEY ".idf_escape($_GET["name"]).",":"")."\nADD FOREIGN KEY (".implode(", ",array_map('idf_escape',$Be)).") REFERENCES ".table($_POST["table"])." (".implode(", ",array_map('idf_escape',$Ye)).")".(ereg("^($md)\$",$_POST["on_delete"])?" ON DELETE $_POST[on_delete]":"").(ereg("^($md)\$",$_POST["on_update"])?" ON UPDATE $_POST[on_update]":""),ME."table=".urlencode($a),($_GET["name"]!=""?'Foreign key has been altered.':'Foreign key has been created.'));$i='Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exist.'."<br>$i";}}page_header('Foreign key',$i,array("table"=>$a),$a);$K=array("table"=>$a,"source"=>array(""));if($_POST){$K=$_POST;ksort($K["source"]);if($_POST["add"]){$K["source"][]="";}elseif($_POST["change"]||$_POST["change-js"]){$K["target"]=array();}}elseif($_GET["name"]!=""){$m=foreign_keys($a);$K=$m[$_GET["name"]];$K["source"][]="";}$Be=array_keys(fields($a));$Ye=($a===$K["table"]?$Be:array_keys(fields($K["table"])));$fe=array();foreach(table_status()as$D=>$T){if(fk_support($T)){$fe[]=$D;}}echo'
<form action="" method="post">
<p>
';if($K["db"]==""&&$K["ns"]==""){echo'Target table:
',html_select("table",$fe,$K["table"],"this.form['change-js'].value = '1'; if (!ajaxForm(this.form)) this.form.submit();"),'<input type="hidden" name="change-js" value="">
<noscript><p><input type="submit" name="change" value="Change"></noscript>
<table cellspacing="0">
<thead><tr><th>Source<th>Target</thead>
';$w=0;foreach($K["source"]as$y=>$X){echo"<tr>","<td>".html_select("source[".(+$y)."]",array(-1=>"")+$Be,$X,($w==count($K["source"])-1?"foreignAddRow(this);":1)),"<td>".html_select("target[".(+$y)."]",$Ye,$K["target"][$y]);$w++;}echo'</table>
<p>
ON DELETE: ',html_select("on_delete",array(-1=>"")+explode("|",$md),$K["on_delete"]),' ON UPDATE: ',html_select("on_update",array(-1=>"")+explode("|",$md),$K["on_update"]),'<p>
<input type="submit" value="Save">
<noscript><p><input type="submit" name="add" value="Add column"></noscript>
';}if($_GET["name"]!=""){echo'<input type="submit" name="drop" value="Drop"',confirm(),'>';}echo'<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["view"])){$a=$_GET["view"];$qb=false;if($_POST&&!$i){$qb=drop_create("DROP VIEW ".table($a),"CREATE VIEW ".table($_POST["name"])." AS\n$_POST[select]",($_POST["drop"]?substr(ME,0,-1):ME."table=".urlencode($_POST["name"])),'View has been dropped.','View has been altered.','View has been created.',$a);}page_header(($a!=""?'Alter view':'Create view'),$i,array("table"=>$a),$a);$K=$_POST;if(!$K&&$a!=""){$K=view($a);$K["name"]=$a;}echo'
<form action="" method="post">
<p>Name: <input name="name" value="',h($K["name"]),'" maxlength="64">
<p>';textarea("select",$K["select"]);echo'<p>
';if($qb){echo'<input type="hidden" name="dropped" value="1">';}echo'<input type="submit" value="Save">
';if($_GET["view"]!=""){echo'<input type="submit" name="drop" value="Drop"',confirm(),'>';}echo'<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["event"])){$aa=$_GET["event"];$tc=array("YEAR","QUARTER","MONTH","DAY","HOUR","MINUTE","WEEK","SECOND","YEAR_MONTH","DAY_HOUR","DAY_MINUTE","DAY_SECOND","HOUR_MINUTE","HOUR_SECOND","MINUTE_SECOND");$Ge=array("ENABLED"=>"ENABLE","DISABLED"=>"DISABLE","SLAVESIDE_DISABLED"=>"DISABLE ON SLAVE");if($_POST&&!$i){if($_POST["drop"]){query_redirect("DROP EVENT ".idf_escape($aa),substr(ME,0,-1),'Event has been dropped.');}elseif(in_array($_POST["INTERVAL_FIELD"],$tc)&&isset($Ge[$_POST["STATUS"]])){$te="\nON SCHEDULE ".($_POST["INTERVAL_VALUE"]?"EVERY ".q($_POST["INTERVAL_VALUE"])." $_POST[INTERVAL_FIELD]".($_POST["STARTS"]?" STARTS ".q($_POST["STARTS"]):"").($_POST["ENDS"]?" ENDS ".q($_POST["ENDS"]):""):"AT ".q($_POST["STARTS"]))." ON COMPLETION".($_POST["ON_COMPLETION"]?"":" NOT")." PRESERVE";queries_redirect(substr(ME,0,-1),($aa!=""?'Event has been altered.':'Event has been created.'),queries(($aa!=""?"ALTER EVENT ".idf_escape($aa).$te.($aa!=$_POST["EVENT_NAME"]?"\nRENAME TO ".idf_escape($_POST["EVENT_NAME"]):""):"CREATE EVENT ".idf_escape($_POST["EVENT_NAME"]).$te)."\n".$Ge[$_POST["STATUS"]]." COMMENT ".q($_POST["EVENT_COMMENT"]).rtrim(" DO\n$_POST[EVENT_DEFINITION]",";").";"));}}page_header(($aa!=""?'Alter event'.": ".h($aa):'Create event'),$i);$K=$_POST;if(!$K&&$aa!=""){$L=get_rows("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = ".q(DB)." AND EVENT_NAME = ".q($aa));$K=reset($L);}echo'
<form action="" method="post">
<table cellspacing="0">
<tr><th>Name<td><input name="EVENT_NAME" value="',h($K["EVENT_NAME"]),'" maxlength="64">
<tr><th>Start<td><input name="STARTS" value="',h("$K[EXECUTE_AT]$K[STARTS]"),'">
<tr><th>End<td><input name="ENDS" value="',h($K["ENDS"]),'">
<tr><th>Every<td><input name="INTERVAL_VALUE" value="',h($K["INTERVAL_VALUE"]),'" size="6"> ',html_select("INTERVAL_FIELD",$tc,$K["INTERVAL_FIELD"]),'<tr><th>Status<td>',html_select("STATUS",$Ge,$K["STATUS"]),'<tr><th>Comment<td><input name="EVENT_COMMENT" value="',h($K["EVENT_COMMENT"]),'" maxlength="64">
<tr><th>&nbsp;<td>',checkbox("ON_COMPLETION","PRESERVE",$K["ON_COMPLETION"]=="PRESERVE",'On completion preserve'),'</table>
<p>';textarea("EVENT_DEFINITION",$K["EVENT_DEFINITION"]);echo'<p>
<input type="submit" value="Save">
';if($aa!=""){echo'<input type="submit" name="drop" value="Drop"',confirm(),'>';}echo'<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["procedure"])){$da=$_GET["procedure"];$pe=(isset($_GET["function"])?"FUNCTION":"PROCEDURE");$qe=routine_languages();$qb=false;if($_POST&&!$i&&!$_POST["add"]&&!$_POST["drop_col"]&&!$_POST["up"]&&!$_POST["down"]){$P=array();$k=(array)$_POST["fields"];ksort($k);foreach($k
as$j){if($j["field"]!=""){$P[]=(ereg("^($qc)\$",$j["inout"])?"$j[inout] ":"").idf_escape($j["field"]).process_type($j,"CHARACTER SET");}}$qb=drop_create("DROP $pe ".idf_escape($da),"CREATE $pe ".idf_escape($_POST["name"])." (".implode(", ",$P).")".(isset($_GET["function"])?" RETURNS".process_type($_POST["returns"],"CHARACTER SET"):"").(in_array($_POST["language"],$qe)?" LANGUAGE $_POST[language]":"").rtrim("\n$_POST[definition]",";").";",substr(ME,0,-1),'Routine has been dropped.','Routine has been altered.','Routine has been created.',$da);}page_header(($da!=""?(isset($_GET["function"])?'Alter function':'Alter procedure').": ".h($da):(isset($_GET["function"])?'Create function':'Create procedure')),$i);$c=get_vals("SHOW CHARACTER SET");sort($c);$K=array("fields"=>array());if($_POST){$K=$_POST;$K["fields"]=(array)$K["fields"];process_fields($K["fields"]);}elseif($da!=""){$K=routine($da,$pe);$K["name"]=$da;}echo'
<form action="" method="post" id="form">
<p>Name: <input name="name" value="',h($K["name"]),'" maxlength="64">
',($qe?'Language'.": ".html_select("language",$qe,$K["language"]):""),'<table cellspacing="0" class="nowrap">
';edit_fields($K["fields"],$c,$pe);if(isset($_GET["function"])){echo"<tr><td>".'Return type';edit_type("returns",$K["returns"],$c);}echo'</table>
<p>';textarea("definition",$K["definition"]);echo'<p>
<input type="submit" value="Save">
';if($da!=""){echo'<input type="submit" name="drop" value="Drop"',confirm(),'>';}if($qb){echo'<input type="hidden" name="dropped" value="1">';}echo'<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["trigger"])){$a=$_GET["trigger"];$of=trigger_options();$nf=array("INSERT","UPDATE","DELETE");$qb=false;if($_POST&&!$i&&in_array($_POST["Timing"],$of["Timing"])&&in_array($_POST["Event"],$nf)&&in_array($_POST["Type"],$of["Type"])){$df=" $_POST[Timing] $_POST[Event]";$ld=" ON ".table($a);$qb=drop_create("DROP TRIGGER ".idf_escape($_GET["name"]).($x=="pgsql"?$ld:""),"CREATE TRIGGER ".idf_escape($_POST["Trigger"]).($x=="mssql"?$ld.$df:$df.$ld).rtrim(" $_POST[Type]\n$_POST[Statement]",";").";",ME."table=".urlencode($a),'Trigger has been dropped.','Trigger has been altered.','Trigger has been created.',$_GET["name"]);}page_header(($_GET["name"]!=""?'Alter trigger'.": ".h($_GET["name"]):'Create trigger'),$i,array("table"=>$a));$K=$_POST;if(!$K){$K=trigger($_GET["name"])+array("Trigger"=>$a."_bi");}echo'
<form action="" method="post" id="form">
<table cellspacing="0">
<tr><th>Time<td>',html_select("Timing",$of["Timing"],$K["Timing"],"if (/^".preg_quote($a,"/")."_[ba][iud]$/.test(this.form['Trigger'].value)) this.form['Trigger'].value = '".js_escape($a)."_' + selectValue(this).charAt(0).toLowerCase() + selectValue(this.form['Event']).charAt(0).toLowerCase();"),'<tr><th>Event<td>',html_select("Event",$nf,$K["Event"],"this.form['Timing'].onchange();"),'<tr><th>Type<td>',html_select("Type",$of["Type"],$K["Type"]),'</table>
<p>Name: <input name="Trigger" value="',h($K["Trigger"]),'" maxlength="64">
<p>';textarea("Statement",$K["Statement"]);echo'<p>
<input type="submit" value="Save">
';if($_GET["name"]!=""){echo'<input type="submit" name="drop" value="Drop"',confirm(),'>';}if($qb){echo'<input type="hidden" name="dropped" value="1">';}echo'<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["user"])){$fa=$_GET["user"];$Xd=array(""=>array("All privileges"=>""));foreach(get_rows("SHOW PRIVILEGES")as$K){foreach(explode(",",($K["Privilege"]=="Grant option"?"":$K["Context"]))as$Ua){$Xd[$Ua][$K["Privilege"]]=$K["Comment"];}}$Xd["Server Admin"]+=$Xd["File access on server"];$Xd["Databases"]["Create routine"]=$Xd["Procedures"]["Create routine"];unset($Xd["Procedures"]["Create routine"]);$Xd["Columns"]=array();foreach(array("Select","Insert","Update","References")as$X){$Xd["Columns"][$X]=$Xd["Tables"][$X];}unset($Xd["Server Admin"]["Usage"]);foreach($Xd["Tables"]as$y=>$X){unset($Xd["Databases"][$y]);}$cd=array();if($_POST){foreach($_POST["objects"]as$y=>$X){$cd[$X]=(array)$cd[$X]+(array)$_POST["grants"][$y];}}$cc=array();$jd="";if(isset($_GET["host"])&&($I=$e->query("SHOW GRANTS FOR ".q($fa)."@".q($_GET["host"])))){while($K=$I->fetch_row()){if(preg_match('~GRANT (.*) ON (.*) TO ~',$K[0],$B)&&preg_match_all('~ *([^(,]*[^ ,(])( *\\([^)]+\\))?~',$B[1],$Lc,PREG_SET_ORDER)){foreach($Lc
as$X){if($X[1]!="USAGE"){$cc["$B[2]$X[2]"][$X[1]]=true;}if(ereg(' WITH GRANT OPTION',$K[0])){$cc["$B[2]$X[2]"]["GRANT OPTION"]=true;}}}if(preg_match("~ IDENTIFIED BY PASSWORD '([^']+)~",$K[0],$B)){$jd=$B[1];}}}if($_POST&&!$i){$kd=(isset($_GET["host"])?q($fa)."@".q($_GET["host"]):"''");$dd=q($_POST["user"])."@".q($_POST["host"]);$Jd=q($_POST["pass"]);if($_POST["drop"]){query_redirect("DROP USER $kd",ME."privileges=",'User has been dropped.');}else{$Za=false;if($kd!=$dd){$Za=queries(($e->server_info<5?"GRANT USAGE ON *.* TO":"CREATE USER")." $dd IDENTIFIED BY".($_POST["hashed"]?" PASSWORD":"")." $Jd");$i=!$Za;}elseif($_POST["pass"]!=$jd||!$_POST["hashed"]){queries("SET PASSWORD FOR $dd = ".($_POST["hashed"]?$Jd:"PASSWORD($Jd)"));}if(!$i){$me=array();foreach($cd
as$gd=>$q){if(isset($_GET["grant"])){$q=array_filter($q);}$q=array_keys($q);if(isset($_GET["grant"])){$me=array_diff(array_keys(array_filter($cd[$gd],'strlen')),$q);}elseif($kd==$dd){$id=array_keys((array)$cc[$gd]);$me=array_diff($id,$q);$q=array_diff($q,$id);unset($cc[$gd]);}if(preg_match('~^(.+)\\s*(\\(.*\\))?$~U',$gd,$B)&&(!grant("REVOKE",$me,$B[2]," ON $B[1] FROM $dd")||!grant("GRANT",$q,$B[2]," ON $B[1] TO $dd"))){$i=true;break;}}}if(!$i&&isset($_GET["host"])){if($kd!=$dd){queries("DROP USER $kd");}elseif(!isset($_GET["grant"])){foreach($cc
as$gd=>$me){if(preg_match('~^(.+)(\\(.*\\))?$~U',$gd,$B)){grant("REVOKE",array_keys($me),$B[2]," ON $B[1] FROM $dd");}}}}queries_redirect(ME."privileges=",(isset($_GET["host"])?'User has been altered.':'User has been created.'),!$i);if($Za){$e->query("DROP USER $dd");}}}page_header((isset($_GET["host"])?'Username'.": ".h("$fa@$_GET[host]"):'Create user'),$i,array("privileges"=>array('','Privileges')));if($_POST){$K=$_POST;$cc=$cd;}else{$K=$_GET+array("host"=>$e->result("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', -1)"));$K["pass"]=$jd;if($jd!=""){$K["hashed"]=true;}$cc[DB!=""&&!isset($_GET["host"])?idf_escape(addcslashes(DB,"%_")).".*":""]=array();}echo'<form action="" method="post">
<table cellspacing="0">
<tr><th>Server<td><input name="host" maxlength="60" value="',h($K["host"]),'">
<tr><th>Username<td><input name="user" maxlength="16" value="',h($K["user"]),'">
<tr><th>Password<td><input id="pass" name="pass" value="',h($K["pass"]),'">
';if(!$K["hashed"]){echo'<script type="text/javascript">typePassword(document.getElementById(\'pass\'));</script>';}echo
checkbox("hashed",1,$K["hashed"],'Hashed',"typePassword(this.form['pass'], this.checked);"),'</table>
';echo"<table cellspacing='0'>\n","<thead><tr><th colspan='2'><a href='http://dev.mysql.com/doc/refman/".substr($e->server_info,0,3)."/en/grant.html#priv_level' target='_blank' rel='noreferrer'>".'Privileges'."</a>";$s=0;foreach($cc
as$gd=>$q){echo'<th>'.($gd!="*.*"?"<input name='objects[$s]' value='".h($gd)."' size='10'>":"<input type='hidden' name='objects[$s]' value='*.*' size='10'>*.*");$s++;}echo"</thead>\n";foreach(array(""=>"","Server Admin"=>'Server',"Databases"=>'Database',"Tables"=>'Table',"Columns"=>'Column',"Procedures"=>'Routine',)as$Ua=>$jb){foreach((array)$Xd[$Ua]as$Wd=>$Pa){echo"<tr".odd()."><td".($jb?">$jb<td":" colspan='2'").' lang="en" title="'.h($Pa).'">'.h($Wd);$s=0;foreach($cc
as$gd=>$q){$D="'grants[$s][".h(strtoupper($Wd))."]'";$Y=$q[strtoupper($Wd)];if($Ua=="Server Admin"&&$gd!=(isset($cc["*.*"])?"*.*":"")){echo"<td>&nbsp;";}elseif(isset($_GET["grant"])){echo"<td><select name=$D><option><option value='1'".($Y?" selected":"").">".'Grant'."<option value='0'".($Y=="0"?" selected":"").">".'Revoke'."</select>";}else{echo"<td align='center'><input type='checkbox' name=$D value='1'".($Y?" checked":"").($Wd=="All privileges"?" id='grants-$s-all'":($Wd=="Grant option"?"":" onclick=\"if (this.checked) formUncheck('grants-$s-all');\"")).">";}$s++;}}}echo"</table>\n",'<p>
<input type="submit" value="Save">
';if(isset($_GET["host"])){echo'<input type="submit" name="drop" value="Drop"',confirm(),'>';}echo'<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["processlist"])){if(support("kill")&&$_POST&&!$i){$yc=0;foreach((array)$_POST["kill"]as$X){if(queries("KILL ".(+$X))){$yc++;}}queries_redirect(ME."processlist=",lang(array('%d process has been killed.','%d processes have been killed.'),$yc),$yc||!$_POST["kill"]);}page_header('Process list',$i);echo'
<form action="" method="post">
<table cellspacing="0" onclick="tableClick(event);" class="nowrap checkable">
';$s=-1;foreach(process_list()as$s=>$K){if(!$s){echo"<thead><tr lang='en'>".(support("kill")?"<th>&nbsp;":"")."<th>".implode("<th>",array_keys($K))."</thead>\n";}echo"<tr".odd().">".(support("kill")?"<td>".checkbox("kill[]",$K["Id"],0):"");foreach($K
as$y=>$X){echo"<td>".(($x=="sql"?$y=="Info"&&$X!="":$y=="current_query"&&$X!="<IDLE>")?"<code class='jush-$x'>".shorten_utf8($X,100,"</code>").' <a href="'.h(ME.($K["db"]!=""?"db=".urlencode($K["db"])."&":"")."sql=".urlencode($X)).'">'.'Edit'.'</a>':nbsp($X));}echo"\n";}echo'</table>
<script type=\'text/javascript\'>tableCheck();</script>
<p>
';if(support("kill")){echo($s+1)."/".sprintf('%d in total',$e->result("SELECT @@max_connections")),"<p><input type='submit' value='".'Kill'."'>\n";}echo'<input type="hidden" name="token" value="',$U,'">
</form>
';}elseif(isset($_GET["select"])){$a=$_GET["select"];$T=table_status($a);$v=indexes($a);$k=fields($a);$m=column_foreign_keys($a);if($T["Oid"]=="t"){$v[]=array("type"=>"PRIMARY","columns"=>array("oid"));}parse_str($_COOKIE["adminer_import"],$la);$ne=array();$d=array();$bf=null;foreach($k
as$y=>$j){$D=$b->fieldName($j);if(isset($j["privileges"]["select"])&&$D!=""){$d[$y]=html_entity_decode(strip_tags($D));if(ereg('text|lob',$j["type"])){$bf=$b->selectLengthProcess();}}$ne+=$j["privileges"];}list($N,$r)=$b->selectColumnsProcess($d,$v);$Z=$b->selectSearchProcess($k,$v);$td=$b->selectOrderProcess($k,$v);$z=$b->selectLimitProcess();$ac=($N?implode(", ",$N):($T["Oid"]=="t"?"oid, ":"")."*")."\nFROM ".table($a);$dc=($r&&count($r)<count($N)?"\nGROUP BY ".implode(", ",$r):"").($td?"\nORDER BY ".implode(", ",$td):"");if($_GET["val"]&&is_ajax()){header("Content-Type: text/plain; charset=utf-8");foreach($_GET["val"]as$wf=>$K){echo$e->result("SELECT".limit(idf_escape(key($K))." FROM ".table($a)," WHERE ".where_check($wf).($Z?" AND ".implode(" AND ",$Z):"").($td?" ORDER BY ".implode(", ",$td):""),1));}exit;}if($_POST&&!$i){$Kf="(".implode(") OR (",array_map('where_check',(array)$_POST["check"])).")";$Td=$yf=null;foreach($v
as$u){if($u["type"]=="PRIMARY"){$Td=array_flip($u["columns"]);$yf=($N?$Td:array());break;}}foreach((array)$yf
as$y=>$X){if(in_array(idf_escape($y),$N)){unset($yf[$y]);}}if($_POST["export"]){cookie("adminer_import","output=".urlencode($_POST["output"])."&format=".urlencode($_POST["format"]));dump_headers($a);$b->dumpTable($a,"");if(!is_array($_POST["check"])||$yf===array()){$Jf=$Z;if(is_array($_POST["check"])){$Jf[]="($Kf)";}$H="SELECT $ac".($Jf?"\nWHERE ".implode(" AND ",$Jf):"").$dc;}else{$uf=array();foreach($_POST["check"]as$X){$uf[]="(SELECT".limit($ac,"\nWHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($X).$dc,1).")";}$H=implode(" UNION ALL ",$uf);}$b->dumpData($a,"table",$H);exit;}if(!$b->selectEmailProcess($Z,$m)){if($_POST["save"]||$_POST["delete"]){$I=true;$ma=0;$H=table($a);$P=array();if(!$_POST["delete"]){foreach($d
as$D=>$X){$X=process_input($k[$D]);if($X!==null){if($_POST["clone"]){$P[idf_escape($D)]=($X!==false?$X:idf_escape($D));}elseif($X!==false){$P[]=idf_escape($D)." = $X";}}}$H.=($_POST["clone"]?" (".implode(", ",array_keys($P)).")\nSELECT ".implode(", ",$P)."\nFROM ".table($a):" SET\n".implode(",\n",$P));}if($_POST["delete"]||$P){$Na="UPDATE";if($_POST["delete"]){$Na="DELETE";$H="FROM $H";}if($_POST["clone"]){$Na="INSERT";$H="INTO $H";}if($_POST["all"]||($yf===array()&&$_POST["check"])||count($r)<count($N)){$I=queries($Na." $H".($_POST["all"]?($Z?"\nWHERE ".implode(" AND ",$Z):""):"\nWHERE $Kf"));$ma=$e->affected_rows;}else{foreach((array)$_POST["check"]as$X){$I=queries($Na.limit1($H,"\nWHERE ".where_check($X)));if(!$I){break;}$ma+=$e->affected_rows;}}}queries_redirect(remove_from_uri("page"),lang(array('%d item has been affected.','%d items have been affected.'),$ma),$I);}elseif(!$_POST["import"]){if(!$_POST["val"]){$i='Double click on a value to modify it.';}else{$I=true;$ma=0;foreach($_POST["val"]as$wf=>$K){$P=array();foreach($K
as$y=>$X){$y=bracket_escape($y,1);$P[]=idf_escape($y)." = ".(ereg('char|text',$k[$y]["type"])||$X!=""?$b->processInput($k[$y],$X):"NULL");}$H=table($a)." SET ".implode(", ",$P);$Jf=" WHERE ".where_check($wf).($Z?" AND ".implode(" AND ",$Z):"");$I=queries("UPDATE".(count($r)<count($N)?" $H$Jf":limit1($H,$Jf)));if(!$I){break;}$ma+=$e->affected_rows;}queries_redirect(remove_from_uri(),lang(array('%d item has been affected.','%d items have been affected.'),$ma),$I);}}elseif(is_string($Rb=get_file("csv_file",true))){cookie("adminer_import","output=".urlencode($la["output"])."&format=".urlencode($_POST["separator"]));$I=true;$La=array_keys($k);preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~',$Rb,$Lc);$ma=count($Lc[0]);begin();$ye=($_POST["separator"]=="csv"?",":($_POST["separator"]=="tsv"?"\t":";"));foreach($Lc[0]as$y=>$X){preg_match_all("~((\"[^\"]*\")+|[^$ye]*)$ye~",$X.$ye,$Mc);if(!$y&&!array_diff($Mc[1],$La)){$La=$Mc[1];$ma--;}else{$P=array();foreach($Mc[1]as$s=>$Ia){$P[idf_escape($La[$s])]=($Ia==""&&$k[$La[$s]]["null"]?"NULL":q(str_replace('""','"',preg_replace('~^"|"$~','',$Ia))));}$I=insert_update($a,$P,$Td);if(!$I){break;}}}if($I){queries("COMMIT");}queries_redirect(remove_from_uri("page"),lang(array('%d row has been imported.','%d rows have been imported.'),$ma),$I);queries("ROLLBACK");}else{$i=upload_error($Rb);}}}$Re=$b->tableName($T);page_header('Select'.": $Re",$i);session_write_close();$P=null;if(isset($ne["insert"])){$P="";foreach((array)$_GET["where"]as$X){if(count($m[$X["col"]])==1&&($X["op"]=="="||(!$X["op"]&&!ereg('[_%]',$X["val"])))){$P.="&set".urlencode("[".bracket_escape($X["col"])."]")."=".urlencode($X["val"]);}}}$b->selectLinks($T,$P);if(!$d){echo"<p class='error'>".'Unable to select the table'.($k?".":": ".error())."\n";}else{echo"<form action='' id='form'>\n","<div style='display: none;'>";hidden_fields_get();echo(DB!=""?'<input type="hidden" name="db" value="'.h(DB).'">'.(isset($_GET["ns"])?'<input type="hidden" name="ns" value="'.h($_GET["ns"]).'">':""):"");echo'<input type="hidden" name="select" value="'.h($a).'">',"</div>\n";$b->selectColumnsPrint($N,$d);$b->selectSearchPrint($Z,$d,$v);$b->selectOrderPrint($td,$d,$v);$b->selectLimitPrint($z);$b->selectLengthPrint($bf);$b->selectActionPrint();echo"</form>\n";$E=$_GET["page"];if($E=="last"){$Yb=$e->result("SELECT COUNT(*) FROM ".table($a).($Z?" WHERE ".implode(" AND ",$Z):""));$E=floor(max(0,$Yb-1)/$z);}$H="SELECT".limit((+$z&&$r&&count($r)<count($N)&&$x=="sql"?"SQL_CALC_FOUND_ROWS ":"").$ac,($Z?"\nWHERE ".implode(" AND ",$Z):"").$dc,($z!=""?+$z:null),($E?$z*$E:0),"\n");echo$b->selectQuery($H);$I=$e->query($H);if(!$I){echo"<p class='error'>".error()."\n";}else{if($x=="mssql"){$I->seek($z*$E);}$yb=array();echo"<form action='' method='post' enctype='multipart/form-data'>\n";$L=array();while($K=$I->fetch_assoc()){if($E&&$x=="oracle"){unset($K["RNUM"]);}$L[]=$K;}if($_GET["page"]!="last"){$Yb=(+$z&&$r&&count($r)<count($N)?($x=="sql"?$e->result(" SELECT FOUND_ROWS()"):$e->result("SELECT COUNT(*) FROM ($H) x")):count($L));}if(!$L){echo"<p class='message'>".'No rows.'."\n";}else{$ya=$b->backwardKeys($a,$Re);echo"<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' onkeydown='return editingKeydown(event);'>\n","<thead><tr>".(!$r&&$N?"":"<td><input type='checkbox' id='all-page' onclick='formCheck(this, /check/);'> <a href='".h($_GET["modify"]?remove_from_uri("modify"):$_SERVER["REQUEST_URI"]."&modify=1")."'>".'edit'."</a>");$bd=array();$p=array();reset($N);$ce=1;foreach($L[0]as$y=>$X){if($T["Oid"]!="t"||$y!="oid"){$X=$_GET["columns"][key($N)];$j=$k[$N?($X?$X["col"]:current($N)):$y];$D=($j?$b->fieldName($j,$ce):"*");if($D!=""){$ce++;$bd[$y]=$D;$Ma=idf_escape($y);echo'<th><a href="'.h(remove_from_uri('(order|desc)[^=]*|page').'&order%5B0%5D='.urlencode($y).($td[0]==$Ma||$td[0]==$y||(!$td&&count($r)<count($N)&&$r[0]==$Ma)?'&desc%5B0%5D=1':'')).'">'.(!$N||$X?apply_sql_function($X["fun"],$D):h(current($N)))."</a>";}$p[$y]=$X["fun"];next($N);}}$Hc=array();if($_GET["modify"]){foreach($L
as$K){foreach($K
as$y=>$X){$Hc[$y]=max($Hc[$y],min(40,strlen(utf8_decode($X))));}}}echo($ya?"<th>".'Relations':"")."</thead>\n";foreach($b->rowDescriptions($L,$m)as$C=>$K){$vf=unique_array($L[$C],$v);$wf="";foreach($vf
as$y=>$X){$wf.="&".(isset($X)?urlencode("where[".bracket_escape($y)."]")."=".urlencode($X):"null%5B%5D=".urlencode($y));}echo"<tr".odd().">".(!$r&&$N?"":"<td>".checkbox("check[]",substr($wf,1),in_array(substr($wf,1),(array)$_POST["check"]),"","this.form['all'].checked = false; formUncheck('all-page');").(count($r)<count($N)||information_schema(DB)?"":" <a href='".h(ME."edit=".urlencode($a).$wf)."'>".'edit'."</a>"));foreach($K
as$y=>$X){if(isset($bd[$y])){$j=$k[$y];if($X!=""&&(!isset($yb[$y])||$yb[$y]!="")){$yb[$y]=(is_mail($X)?$bd[$y]:"");}$_="";$X=$b->editVal($X,$j);if(!isset($X)){$X="<i>NULL</i>";}else{if(ereg('blob|bytea|raw|file',$j["type"])&&$X!=""){$_=h(ME.'download='.urlencode($a).'&field='.urlencode($y).$wf);}if($X===""){$X="&nbsp;";}elseif($bf!=""&&ereg('text|blob',$j["type"])&&is_utf8($X)){$X=shorten_utf8($X,max(0,+$bf));}else{$X=h($X);}if(!$_){foreach((array)$m[$y]as$l){if(count($m[$y])==1||end($l["source"])==$y){$_="";foreach($l["source"]as$s=>$Be){$_.=where_link($s,$l["target"][$s],$L[$C][$Be]);}$_=h(($l["db"]!=""?preg_replace('~([?&]db=)[^&]+~','\\1'.urlencode($l["db"]),ME):ME).'select='.urlencode($l["table"]).$_);if(count($l["source"])==1){break;}}}}if($y=="COUNT(*)"){$_=h(ME."select=".urlencode($a));$s=0;foreach((array)$_GET["where"]as$W){if(!array_key_exists($W["col"],$vf)){$_.=h(where_link($s++,$W["col"],$W["val"],$W["op"]));}}foreach($vf
as$xc=>$W){$_.=h(where_link($s++,$xc,$W));}}}if(!$_){if(is_mail($X)){$_="mailto:$X";}if($ae=is_url($K[$y])){$_=($ae=="http"&&$ba?$K[$y]:"$ae://www.adminer.org/redirect/?url=".urlencode($K[$y]));}}$t=h("val[$wf][".bracket_escape($y)."]");$Y=$_POST["val"][$wf][bracket_escape($y)];$fc=h(isset($Y)?$Y:$K[$y]);$Kc=strpos($X,"<i>...</i>");$vb=is_utf8($X)&&$L[$C][$y]==$K[$y]&&!$p[$y];$af=ereg('text|lob',$j["type"]);echo(($_GET["modify"]&&$vb)||isset($Y)?"<td>".($af?"<textarea name='$t' cols='30' rows='".(substr_count($K[$y],"\n")+1)."'>$fc</textarea>":"<input name='$t' value='$fc' size='$Hc[$y]'>"):"<td id='$t' ondblclick=\"".($vb?"selectDblClick(this, event".($Kc?", 2":($af?", 1":"")).")":"alert('".h('Use edit link to modify this value.')."')").";\">".$b->selectVal($X,$_,$j));}}if($ya){echo"<td>";}$b->backwardKeysPrint($ya,$L[$C]);echo"</tr>\n";}echo"</table>\n",(!$r&&$N?"":"<script type='text/javascript'>tableCheck();</script>\n");}if($L||$E){$Gb=true;if($_GET["page"]!="last"&&+$z&&count($r)>=count($N)&&($Yb>=$z||$E)){$Yb=found_rows($T,$Z);if($Yb<max(1e4,2*($E+1)*$z)){ob_flush();flush();$Yb=$e->result("SELECT COUNT(*) FROM ".table($a).($Z?" WHERE ".implode(" AND ",$Z):""));}else{$Gb=false;}}echo"<p class='pages'>";if(+$z&&$Yb>$z){$Oc=floor(($Yb-1)/$z);echo'<a href="'.h(remove_from_uri("page"))."\" onclick=\"pageClick(this.href, +prompt('".'Page'."', '".($E+1)."'), event); return false;\">".'Page'."</a>:",pagination(0,$E).($E>5?" ...":"");for($s=max(1,$E-4);$s<min($Oc,$E+5);$s++){echo
pagination($s,$E);}echo($E+5<$Oc?" ...":"").($Gb?pagination($Oc,$E):' <a href="'.h(remove_from_uri()."&page=last").'">'.'last'."</a>");}echo" (".($Gb?"":"~ ").lang(array('%d row','%d rows'),$Yb).") ".checkbox("all",1,0,'whole result')."\n";if($b->selectCommandPrint()){echo'<fieldset><legend>Edit</legend><div>
<input type="submit" value="Save"',($_GET["modify"]?'':' title="'.'Double click on a value to modify it.'.'" class="jsonly"');?>>
<input type="submit" name="edit" value="Edit">
<input type="submit" name="clone" value="Clone">
<input type="submit" name="delete" value="Delete" onclick="return confirm('Are you sure? (' + (this.form['all'].checked ? <?php echo$Yb,' : formChecked(this, /check/)) + \')\');">
</div></fieldset>
';}print_fieldset("export",'Export');$Ad=$b->dumpOutput();echo($Ad?html_select("output",$Ad,$la["output"])." ":""),html_select("format",$b->dumpFormat(),$la["format"])," <input type='submit' name='export' value='".'Export'."' onclick='eventStop(event);'>\n","</div></fieldset>\n";}if($b->selectImportPrint()){print_fieldset("import",'Import',!$L);echo"<input type='file' name='csv_file'> ",html_select("separator",array("csv"=>"CSV,","csv;"=>"CSV;","tsv"=>"TSV"),$la["format"],1);echo" <input type='submit' name='import' value='".'Import'."'>","<input type='hidden' name='token' value='$U'>\n","</div></fieldset>\n";}$b->selectEmailPrint(array_filter($yb,'strlen'),$d);echo"</form>\n";}}}elseif(isset($_GET["variables"])){$Fe=isset($_GET["status"]);page_header($Fe?'Status':'Variables');$Ef=($Fe?show_status():show_variables());if(!$Ef){echo"<p class='message'>".'No rows.'."\n";}else{echo"<table cellspacing='0'>\n";foreach($Ef
as$y=>$X){echo"<tr>","<th><code class='jush-".$x.($Fe?"status":"set")."'>".h($y)."</code>","<td>".nbsp($X);}echo"</table>\n";}}elseif(isset($_GET["script"])){header("Content-Type: text/javascript; charset=utf-8");if($_GET["script"]=="db"){$Oe=array("Data_length"=>0,"Index_length"=>0,"Data_free"=>0);foreach(table_status()as$T){$t=js_escape($T["Name"]);json_row("Comment-$t",nbsp($T["Comment"]));if(!is_view($T)){foreach(array("Engine","Collation")as$y){json_row("$y-$t",nbsp($T[$y]));}foreach($Oe+array("Auto_increment"=>0,"Rows"=>0)as$y=>$X){if($T[$y]!=""){$X=number_format($T[$y],0,'.',',');json_row("$y-$t",($y=="Rows"&&$T["Engine"]=="InnoDB"&&$X?"~ $X":$X));if(isset($Oe[$y])){$Oe[$y]+=($T["Engine"]!="InnoDB"||$y!="Data_free"?$T[$y]:0);}}elseif(array_key_exists($y,$T)){json_row("$y-$t");}}}}foreach($Oe
as$y=>$X){json_row("sum-$y",number_format($X,0,'.',','));}json_row("");}else{foreach(count_tables(get_databases())as$h=>$X){json_row("tables-".js_escape($h),$X);}json_row("");}exit;}else{$Xe=array_merge((array)$_POST["tables"],(array)$_POST["views"]);if($Xe&&!$i&&!$_POST["search"]){$I=true;$Sc="";if($x=="sql"&&count($_POST["tables"])>1&&($_POST["drop"]||$_POST["truncate"]||$_POST["copy"])){queries("SET foreign_key_checks = 0");}if($_POST["truncate"]){if($_POST["tables"]){$I=truncate_tables($_POST["tables"]);}$Sc='Tables have been truncated.';}elseif($_POST["move"]){$I=move_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Sc='Tables have been moved.';}elseif($_POST["copy"]){$I=copy_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Sc='Tables have been copied.';}elseif($_POST["drop"]){if($_POST["views"]){$I=drop_views($_POST["views"]);}if($I&&$_POST["tables"]){$I=drop_tables($_POST["tables"]);}$Sc='Tables have been dropped.';}elseif($_POST["tables"]&&($I=queries(($_POST["optimize"]?"OPTIMIZE":($_POST["check"]?"CHECK":($_POST["repair"]?"REPAIR":"ANALYZE")))." TABLE ".implode(", ",array_map('idf_escape',$_POST["tables"]))))){while($K=$I->fetch_assoc()){$Sc.="<b>".h($K["Table"])."</b>: ".h($K["Msg_text"])."<br>";}}queries_redirect(substr(ME,0,-1),$Sc,$I);}page_header(($_GET["ns"]==""?'Database'.": ".h(DB):'Schema'.": ".h($_GET["ns"])),$i,true);if($b->homepage()){if($_GET["ns"]!==""){echo"<h3>".'Tables and views'."</h3>\n";$We=tables_list();if(!$We){echo"<p class='message'>".'No tables.'."\n";}else{echo"<form action='' method='post'>\n","<p>".'Search data in tables'.": <input name='query' value='".h($_POST["query"])."'> <input type='submit' name='search' value='".'Search'."'>\n";if($_POST["search"]&&$_POST["query"]!=""){search_tables();}echo"<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);'>\n",'<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^(tables|views)\[/);">','<th>'.'Table','<td>'.'Engine','<td>'.'Collation','<td>'.'Data Length','<td>'.'Index Length','<td>'.'Data Free','<td>'.'Auto Increment','<td>'.'Rows',(support("comment")?'<td>'.'Comment':''),"</thead>\n";foreach($We
as$D=>$V){$Ff=(isset($V)&&!eregi("table",$V));echo'<tr'.odd().'><td>'.checkbox(($Ff?"views[]":"tables[]"),$D,in_array($D,$Xe,true),"","formUncheck('check-all');"),'<th><a href="'.h(ME).'table='.urlencode($D).'" title="'.'Show structure'.'">'.h($D).'</a>';if($Ff){echo'<td colspan="6"><a href="'.h(ME)."view=".urlencode($D).'" title="'.'Alter view'.'">'.'View'.'</a>','<td align="right"><a href="'.h(ME)."select=".urlencode($D).'" title="'.'Select data'.'">?</a>';}else{foreach(array("Engine"=>array(),"Collation"=>array(),"Data_length"=>array("create",'Alter table'),"Index_length"=>array("indexes",'Alter indexes'),"Data_free"=>array("edit",'New item'),"Auto_increment"=>array("auto_increment=1&create",'Alter table'),"Rows"=>array("select",'Select data'),)as$y=>$_){echo($_?"<td align='right'><a href='".h(ME."$_[0]=").urlencode($D)."' id='$y-".h($D)."' title='$_[1]'>?</a>":"<td id='$y-".h($D)."'>&nbsp;");}}echo(support("comment")?"<td id='Comment-".h($D)."'>&nbsp;":"");}echo"<tr><td>&nbsp;<th>".sprintf('%d in total',count($We)),"<td>".nbsp($x=="sql"?$e->result("SELECT @@storage_engine"):""),"<td>".nbsp(db_collation(DB,collations()));foreach(array("Data_length","Index_length","Data_free")as$y){echo"<td align='right' id='sum-$y'>&nbsp;";}echo"</table>\n","<script type='text/javascript'>tableCheck();</script>\n";if(!information_schema(DB)){echo"<p>".($x=="sql"?"<input type='submit' value='".'Analyze'."'> <input type='submit' name='optimize' value='".'Optimize'."'> <input type='submit' name='check' value='".'Check'."'> <input type='submit' name='repair' value='".'Repair'."'> ":"")."<input type='submit' name='truncate' value='".'Truncate'."'".confirm("formChecked(this, /tables/)")."> <input type='submit' name='drop' value='".'Drop'."'".confirm("formChecked(this, /tables|views/)",1).">\n";$g=(support("scheme")?schemas():get_databases());if(count($g)!=1&&$x!="sqlite"){$h=(isset($_POST["target"])?$_POST["target"]:(support("scheme")?$_GET["ns"]:DB));echo"<p>".'Move to other database'.": ",($g?html_select("target",$g,$h):'<input name="target" value="'.h($h).'">')," <input type='submit' name='move' value='".'Move'."' onclick='eventStop(event);'>",(support("copy")?" <input type='submit' name='copy' value='".'Copy'."' onclick='eventStop(event);'>":""),"\n";}echo"<input type='hidden' name='token' value='$U'>\n";}echo"</form>\n";}echo'<p><a href="'.h(ME).'create=">'.'Create table'."</a>\n";if(support("view")){echo'<a href="'.h(ME).'view=">'.'Create view'."</a>\n";}if(support("routine")){echo"<h3>".'Routines'."</h3>\n";$re=routines();if($re){echo"<table cellspacing='0'>\n",'<thead><tr><th>'.'Name'.'<td>'.'Type'.'<td>'.'Return type'."<td>&nbsp;</thead>\n";odd('');foreach($re
as$K){echo'<tr'.odd().'>','<th><a href="'.h(ME).($K["ROUTINE_TYPE"]!="PROCEDURE"?'callf=':'call=').urlencode($K["ROUTINE_NAME"]).'">'.h($K["ROUTINE_NAME"]).'</a>','<td>'.h($K["ROUTINE_TYPE"]),'<td>'.h($K["DTD_IDENTIFIER"]),'<td><a href="'.h(ME).($K["ROUTINE_TYPE"]!="PROCEDURE"?'function=':'procedure=').urlencode($K["ROUTINE_NAME"]).'">'.'Alter'."</a>";}echo"</table>\n";}echo'<p>'.(support("procedure")?'<a href="'.h(ME).'procedure=">'.'Create procedure'.'</a> ':'').'<a href="'.h(ME).'function=">'.'Create function'."</a>\n";}if(support("event")){echo"<h3>".'Events'."</h3>\n";$L=get_rows("SHOW EVENTS");if($L){echo"<table cellspacing='0'>\n","<thead><tr><th>".'Name'."<td>".'Schedule'."<td>".'Start'."<td>".'End'."</thead>\n";foreach($L
as$K){echo"<tr>",'<th><a href="'.h(ME).'event='.urlencode($K["Name"]).'">'.h($K["Name"])."</a>","<td>".($K["Execute at"]?'At given time'."<td>".$K["Execute at"]:'Every'." ".$K["Interval value"]." ".$K["Interval field"]."<td>$K[Starts]"),"<td>$K[Ends]";}echo"</table>\n";}echo'<p><a href="'.h(ME).'event=">'.'Create event'."</a>\n";}if($We){echo"<script type='text/javascript'>ajaxSetHtml('".js_escape(ME)."script=db');</script>\n";}}}}page_footer();

View File

@@ -0,0 +1,58 @@
/* CSS by Brade - www.bradezone.com */
*{margin:0;padding:0}
body{font:13px/18px Helvetica,Arial,sans-serif;background:#fff;color:#333}
/* generic */
a,a:visited{color:#06c;text-decoration:none;border-bottom:1px dotted}
a:hover{border-bottom:1px solid #06c;background:#06c;color:#fff}
p{padding-bottom:4px;margin-bottom:4px}
h1{font-size:18px;font-weight:bold;padding-bottom:0px;height:40px;padding:0 0 8px 0;color:#666;border:0}
h2{font:32px Georgia,serif;padding:10px 0 8px;margin:0;background:transparent;border:0;color:#333}
h3{font-size:18px;font-weight:bold;padding:4px 0;margin:0}
form#form{overflow:hidden}
fieldset{float:left;min-height:48px;padding:0 4px 4px 4px;border:1px solid #ccc;margin-bottom:8px;margin-right:4px}
fieldset div{margin-top:4px}
input,select,textarea{font:13px Helvetica,Arial,sans-serif;color:#555;border:1px solid #999;padding:3px}
input[type=submit]{background:#ccc;padding:2px;cursor:pointer;color:#333}
input[type=submit]:hover{background:#bbb}
input[type=image],input[type=checkbox]{border:0;padding:0}
label input[type=checkbox],td input[type=radio],td span select{margin-right:4px}
select{border:1px solid #999;padding:2px}
fieldset select{margin-right:4px}
option{padding:0 5px}
optgroup{font-size:11px}
code{background:#eee;padding:2px 4px;font:16px/20px Courier,monospace}
code a:hover{background:transparent}
table{margin:4px 0 8px;border:1px solid #ccc;font-size:inherit}
tbody tr:hover td,tbody tr:hover th{background:#eee}
thead tr:hover td,thead tr:hover th{background:#ddd}
th,td{text-align:left;padding:2px 4px;vertical-align:top;font-weight:normal;border:1px dotted #ccc;border-width:0 0 0 1px;
margin:0;background:inherit}
thead th,thead td{white-space:nowrap;font-weight:bold;background:#ddd;border-color:#ddd}
th:first-child,td:first-child{border-color:transparent;white-space:nowrap}
td[align=right]{text-align:right}
table code{font-size:13px;line-height:18px}
.hidden{display:none}
.error,.message{padding:0;background:transparent;font-weight:bold}
.error{color:#c00}
.message{color:#090}
/* specific */
#content{margin:0 0 0 320px;padding:50px 20px 40px 0;height:100%}
#content:after{content:'.';clear:both;height:0;overflow:hidden;display:block}
#lang{background:#333;color:#fff;position:fixed;top:0;left:0;width:100%;padding:0 20px 0 40px;line-height:40px;height:40px}
#lang select{border-color:#333}
#menu{background:#eee;position:fixed;top:60px;bottom:20px;overflow:auto;left:20px;width:240px;padding:10px 15px;
border:5px solid #ccc;margin:0}
#menu a{color:#333;margin-right:4px}
#menu a:hover{background:#333;color:#fff;border-color:#333}
#menu a.h1,#menu a.h1:hover{display:block;height:0;width:175px;padding:40px 0 0 0;overflow:hidden;float:left;border:0;margin:0;
outline:0;background:url(http://www.bradezone.com/random/adminer_logo.gif) no-repeat;line-height:32px}
#menu p{white-space:nowrap;border:0;padding:0 0 4px 0;margin:0 0 4px 0}
#breadcrumb{background:#333;color:#fff;position:fixed;top:0;left:320px;width:100%;line-height:40px;padding:0;z-index:1;margin:0}
#breadcrumb a{color:#ff9}
#breadcrumb a:hover{background:transparent;color:#ff9;border-color:#ff9}
#schema .table{padding:4px 8px;background:#f3f3f3}
/* IE hacks */
*+html th:first-child,*+html td:first-child{border-color:inherit;white-space:inherit}
* html #lang,* html #menu,* html #breadcrumb{position:absolute}
* html #lang{padding-top:10px;height:30px}
* html form#form{height:100%}

View File

@@ -0,0 +1,78 @@
<!DOCTYPE html>
<body>
<?php
// ------------------------------------
// backupOpenFiles by Matt Pass
// Will backups open files in ICE coder
// ------------------------------------
// If we have no post data for the 1st item, set a form up ready to post back
if (!isset($_POST['fileName1'])) {
echo '<form name="zipFiles" id="zipFiles" action="index.php" method="POST">'.PHP_EOL;
for ($i=1;$i<=10;$i++) {
echo '<input type="hidden" name="fileName'.$i.'" id="fName'.$i.'" value="" style="display: none">'.PHP_EOL;
echo '<textarea name="fileContent'.$i.'" id="fContent'.$i.'" style="display: none"></textarea>'.PHP_EOL;
}
echo '</form>'.PHP_EOL;
?>
<script>
// Populate values for file names & contents
for (i=1;i<=top.ICEcoder.openFiles.length;i++) {
document.getElementById('fName'+i).value = top.ICEcoder.openFiles[i-1];
document.getElementById('fContent'+i).value = top.ICEcoder.content.contentWindow['cM'+i].getValue();
}
if (top.ICEcoder.openFiles.length>0) {
document.zipFiles.submit();
}
</script>
<?php
;} else {
// Folder name & filename of the zip
$zipItSaveLocation = '../../backups/';
$zipItFileName = time().'.zip';
// Make the dir if it doesn't exist
if (!is_dir($zipItSaveLocation)) {
mkdir($zipItSaveLocation, 0777);
}
// Start a class
Class zipIt {
public function zipFilesUp($zipName='') {
// OK, if we've got at least one file to add
if($_POST['fileName1']!=="") {
$zip = new ZipArchive();
// Return if we have a problem creating/overwriting our zip
if($zip->open($zipName,$overwriteZip ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
// Otherwise, we're OK to add our string into a new file (incl dirs) in the zip, so do that
for($i=1;$i<=10;$i++) {
$fName = 'fileName'.$i;
if($_POST[$fName]!=="") {
$zip->addFromString(ltrim($_POST[$fName],"/"), $_POST['fileContent'.$i]);
}
}
$zip->close();
// We've been successful, so return with a positive response
return file_exists($zipName);
} else {
// If we had 0 files, return
return false;
}
}
}
// Trigger the class
$zipItDoZip = new zipIt();
$zipItAddToZip = $zipItDoZip->zipFilesUp($zipItSaveLocation.$zipItFileName);
;};
?>
</body>
</html>