function getPointer(e) {
if (is_ie) {
DocX = event.clientX + document.body.scrollLeft;
DocY = event.clientY + document.body.scrollTop;
} else {
DocX = e.pageX;
DocY = e.pageY;
}
}
function loadHistory(filename){
cExecute('./index.php?menuaction=filemanager.uifilemanager.history&file='+base64_encode(filename)+"&path="+base64_encode(currentPath),draw_window);
}
function loadPermissions(data){
var permission = parseInt(data);
var ACL_READ = 1;
var ACL_ADD = 2;
var ACL_EDIT = 4;
var ACL_DELETE = 8;
var ACL_PRIVATE = 16;
permissions['read']=(permission & ACL_READ);
permissions['add']=(permission & ACL_ADD);
permissions['edit']=(permission & ACL_EDIT);
permissions['delete']=(permission & ACL_DELETE);
permissions['private']=(permission & ACL_PRIVATE);
toolbar.load();
}
function close_window(){
var menu = document.getElementById('dwindow');
if (menu != null)
menu.style.visibility = 'hidden'
}
function draw_window(htmlData){
var menu = document.getElementById('dwindow');
headerWin = '
';
if (!menu){
menu = document.createElement('DIV');
menu.id = "dwindow";
menu.style.left = 200;
menu.style.width = "400px";
menu.style.top = DocY;
menu.className = 'menubox';
menu.style.zIndex='1';
menu.innerHTML = headerWin+htmlData;
document.getElementById('tdAppbox').appendChild(menu);
}
else{
menu.innerHTML = headerWin+htmlData;
menu.style.visibility = 'visible';
}
}
function draw_menu(id,elements){
var menu = document.getElementById('menu_newFile'+id);
if (menu == null){
menu = document.createElement('DIV');
menu.id = "menu_newFile"+id;
menu.style.left = DocX;
menu.style.top = DocY;
for(j in elements)
{
var link = document.createElement( 'A' );
if (typeof(elements[j]['img']) != 'undefined'){
var img = document.createElement( 'IMG' );
img.src = elements[j]['img'];
link.appendChild(img);
}
link.href = elements[j]['url'];
link.appendChild( document.createTextNode( elements[j]['text'] ) );
menu.appendChild(link);
menu.appendChild(document.createElement( 'BR' ));
}
menu.onmouseout = function () { menuTimeout = setTimeout("document.getElementById('menu_newFile"+id+"').style.visibility = 'hidden'",50);}
menu.onmouseover = function () { clearTimeout(menuTimeout); };
menu.className = 'menubox';
menu.style.zIndex='1';
document.getElementById('divAppboxHeader').appendChild(menu);
}
menu.style.visibility = 'visible';
}
function resizeDiv(){
defaultHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
document.getElementById('fmFileWindow').style.height = defaultHeight-170;
document.getElementById('content_folders').style.height = defaultHeight - (is_ie ? 230 : 215);
}
var headerMsgLock = false;
var labelBefore = "";
function write_msg (message){
connector.hideProgressBar();
if (headerMsgLock){
setTimeout('write_msg("'+message+'");', 300);
return;
}
headerMsgLock = true;
headerDiv = document.getElementById("divAppboxHeader");
labelBefore = headerDiv.innerHTML;
headerDiv.innerHTML = '';
setTimeout('headerMsgLock = false; document.getElementById("divAppboxHeader").innerHTML = labelBefore;', 3000);
}
function write_error (message){
connector.hideProgressBar();
if (headerMsgLock){
setTimeout('write_error("'+message+'");', 300);
return;
}
headerMsgLock = true;
headerDiv = document.getElementById("divAppboxHeader");
labelBefore = headerDiv.innerHTML;
headerDiv.innerHTML = '';
setTimeout('headerMsgLock = false; document.getElementById("divAppboxHeader").innerHTML = labelBefore;', 3000);
}
function displayMessages(){
var messages = document.getElementById("allMessages");
for (i=0; i < messages.childNodes.length; i++){
if (messages.childNodes[i].innerHTML.indexOf(get_lang('Error:')) == 0)
write_error(messages.childNodes[i].innerHTML);
else
write_msg(messages.childNodes[i].innerHTML);
}
}
function loadPreferences(){
preferencesEl = document.getElementById('userPreferences');
preferences = unserialize(preferencesEl.value);
preferencesEl.parentNode.removeChild(preferencesEl);
}
function reloadFiles(newCriteria){
if (newCriteria == criteria)
order_type = (order_type=='1'?'0':'1')
else
criteria = newCriteria;
toolbar.control('reload');
}
function initDrawApi(){
loadPreferences();
currentPath = document.getElementById('currentPath').value;
toolbar.control('reload');
document.getElementById('divAppboxHeader').innerHTML = title_app;
displayMessages();
resizeDiv();
window.onresize = resizeDiv;
document.body.style.overflow = "hidden";
}
function folderList(){
this.td = '';
}
folderList.prototype.init = function(){
this.element = document.getElementById('fmFileWindow');
}
folderList.prototype.clear = function(){
this.element.innerHTML = "";
}
folderList.prototype.drawSearch = function(data){
var fl = folderList;
var files = unserialize(data);
if (files == null)
{
alert(get_lang('No results found'));
return
}
toolbar.clear();
fl.init();
fl.clear();
var newpage;
var sp_hd = ' | | | ';
newpage += fl.td+sp_hd+' id="name">'+get_lang('file name')+sp_tl;
newpage += fl.td+sp_hd+' id="folder">'+get_lang('folder')+sp_tl;
if (preferences.mime_type =='1')
newpage += fl.td+sp_hd+' id="mime">'+get_lang('mime type')+sp_tl;
if (preferences.size =='1')
newpage += fl.td+sp_hd+' id="size">'+get_lang('size')+''+sp_tl;
if (preferences.created =='1')
newpage += fl.td+sp_hd+' id="created">'+get_lang('created')+''+sp_tl;
if (preferences.modified =='1')
newpage += fl.td+sp_hd+' id="modified">'+get_lang('modified')+''+sp_tl;
if (preferences.createdby_id =='1')
newpage += fl.td+sp_hd+' id="creatdby">'+get_lang('created by')+''+sp_tl;
if (preferences.modifiedby_id =='1')
newpage += fl.td+sp_hd+' id="modifdby">'+get_lang('modified by')+''+sp_tl;
if (preferences.comment =='1')
newpage += fl.td+sp_hd+' id="comm">'+get_lang('comment')+''+sp_tl;
if (preferences.version =='1') newpage += fl.td+sp_hd+' id="vers">'+get_lang('version')+''+sp_tl+'';
for (var i=0; i < files.length; i++)
{
newpage += ''+fl.td;
newpage += '';
newpage += ' | | ';
newpage += fl.td+'
';
newpage += ''+files[i].name+' ';
newpage += fl.td+files[i].directory+'';
if (preferences.mime_type =='1') newpage += fl.td+files[i].mime_type+'';
if (preferences.size =='1') newpage += fl.td+borkb(files[i].size)+'';
if (preferences.created =='1') newpage += fl.td+files[i].created+'';
if (preferences.modified =='1') newpage += fl.td+files[i].modified+'';
if (preferences.createdby_id =='1') newpage += fl.td+files[i].createdby_id+'';
if (preferences.modifiedby_id =='1') newpage += fl.td+files[i].modifiedby_id+'';
if (preferences.comment =='1') newpage += fl.td+''+files[i].comment+'';
if (preferences.version =='1') newpage += fl.td+''+files[i].version+'
';
}
fl.element.innerHTML = newpage;
fl.drawStripes();
}
folderList.prototype.createLine = function(file){
var fl = folderList;
retBuff = fl.td;
retBuff += '';
if (permissions['private']) {
retBuff += '![]() | ';
}
else
retBuff += ' | ';
switch (file.mime)
{
case 'text/html':
retBuff += '!['+get_lang('export')+' '+get_lang('export')+']('+templatePath+'images/button_export.png) | ';
break;
case 'application/zip':
retBuff += '!['+get_lang('unarchive')+' '+get_lang('unarchive')+']('+templatePath+'images/button_export.png) | '
break;
default:
retBuff += ' | ';
}
retBuff += fl.td+'
';
if((file.mime).toUpperCase().indexOf('IMAGE') == 0)
var mousefunc = 'draw_card(\''+file.name+'\')'
else
var mousefunc = 'hide_preview()';
retBuff += ''+file.name+' ';
if (preferences.mime_type =='1') retBuff += fl.td+file.mime+'';
if (preferences.size =='1') retBuff += fl.td+borkb(file.size)+'';
var now = new Date();
var dtString = "";
if (preferences.created =='1') {
var created = new Date();
created.setTime(file.creatd*1000);
if (now.getTime() - created.getTime() < 86400000)
if (created.getMinutes() < 10 )
dtString = created.getHours()+":0"+created.getMinutes();
else
dtString = created.getHours()+":"+created.getMinutes();
else
dtString = created.getDate()+"/"+created.getMonth()+"/"+created.getFullYear();
retBuff += fl.td+dtString+'';
}
if (preferences.modified =='1'){
var modified = new Date();
modified.setTime(file.modifd*1000);
if (file.modifd != "")
if (now.getTime() - modified.getTime() < 86400000)
if (modified.getMinutes() < 10)
dtString = modified.getHours()+":0"+modified.getMinutes();
else
dtString = modified.getHours()+":"+modified.getMinutes();
else
dtString = modified.getDate()+"/"+modified.getMonth()+"/"+modified.getFullYear();
else
dtString = "";
retBuff += fl.td+dtString+'';
}
if (preferences.owner =='1') retBuff += fl.td+file.owner+'';
if (preferences.createdby_id =='1') retBuff += fl.td+file.creatdby+'';
if (preferences.modifiedby_id =='1') retBuff += fl.td+file.modifdby+'';
if (preferences.comment =='1') retBuff += fl.td+'';
if (preferences.version =='1') retBuff += fl.td+''+file.vers+'';
return retBuff;
}
folderList.prototype.updateQuota = function(quotaSize,usedSpace){
if (parseInt(quotaSize) != 0){
var contentQuota = document.getElementById('content_quota');
if (contentQuota != null)
contentQuota.innerHTML = '';
}
}
folderList.prototype.drawFiles = function(data){
var fl = folderList;
var returnData = unserialize(data);
loadPermissions(returnData.permissions);
var files = returnData.files;
fl.init();
fl.clear();
var newpage;
var sp_hd = '';
if (files != null)
for (var i=0; i < files.length; i++)
{
newpage += '';
newpage += fl.createLine(files[i]);
newpage += '
';
}
else
newpage = ""+get_lang('no files in this directory.')+"";
fl.element.innerHTML = newpage;
header = document.getElementsByName('head');
for (var i=0; i < header.length; i++)
{
if (header[i].id == criteria){
header[i].style.fontWeight = 'bold';
arrow = document.createElement('IMG');
if (order_type == '1')
arrow.src = templatePath+'images/arrow_ascendant.gif';
else
arrow.src = templatePath+'images/arrow_descendant.gif';
header[i].appendChild(arrow);
}
}
fl.drawStripes();
folderList.updateQuota(returnData.quota.quotaSize,returnData.quota.usedSpace);
}
folderList.prototype.drawStripes = function(){
var classTr = "tr_msg_read";
folderList.init();
var elements = folderList.element.firstChild.firstChild.childNodes;
for (var i = 1; i < elements.length; i++){
elements[i].className = classTr;
classTr = (classTr == "tr_msg_read"?"tr_msg_read2":"tr_msg_read");
}
}
var folderList = new folderList();
function toolbar()
{
var element;
}
toolbar.prototype.clear = function (){
this.element.innerHTML = "";
}
toolbar.prototype.load = function (){
this.element = document.getElementById('fmMenu');
if (permissions['read'] == 0)
return;
var pageContent = '';
var createButton = function(name) { return ' '+get_lang(name.replace('_',' '))+' | '; }
if (permissions['edit'] != 0){
pageContent += createButton('edit');
pageContent += createButton('rename');
}
if (permissions['delete'] != 0){
pageContent += createButton('delete');
pageContent += createButton('move_to');
}
pageContent += createButton('copy_to');
this.element.innerHTML = pageContent+'
';
}
toolbar.prototype.control = function (arg)
{
//Used to get button position
var button = document.getElementsByName(arg);
button = button[0];
switch (arg) {
case 'new':
elements = new Array();
elements[0] = { 'text': get_lang('empty file'),
'url': 'javascript:newEmptyFile()'};
elements[1] = new Array();
elements[1]['text'] = get_lang('File from model');
address = document.location.toString();
address = address.split("?");
elements[1]['url'] = address[0]+"?menuaction=filemanager.uifilemanager.fileModels";
elements[2] = { 'text' : get_lang('Upload'),
'url': 'javascript:newUpload()'};
draw_menu(arg,elements);
break;
case 'rename':
var one_checked = false;
files=document.getElementsByName('fileman');
for (i = 0; i < files.length; i++)
if (files[i].checked){
one_checked = true;
files[i].checked = false;
var nameLink = document.getElementById('name_'+files[i].value);
var inputName = document.createElement('INPUT');
inputName.id = 'input_'+files[i].value;
var filename = nameLink.innerHTML;
inputName.value = filename;
inputName.onclick = function () { oldValue = inputName.value; }
inputName.onblur = function () { if (inputName.value == oldValue) handler.rename(); else cExecute('./index.php?menuaction=filemanager.vfs_functions.rename&file='+base64_encode(this.id.substr(6))+'&to='+base64_encode(this.value)+"&path="+base64_encode(currentPath),handler.rename) };
inputName.onkeydown=function (event) {if (event.keyCode == KEY_ENTER) this.blur(); };
nameLink.parentNode.appendChild(inputName);
nameLink.parentNode.removeChild(nameLink);
}
if (!one_checked)
write_msg(get_lang('Please select a file'));
break;
case 'edit':
var one_checked = false;
files=document.getElementsByName('fileman');
for (i = 0; i < files.length; i++)
if (files[i].checked){
one_checked = true;
var filename=files[i].value;
}
if (one_checked){
address = document.location.toString();
address = address.split("&");
document.location = address[0]+"&"+arg+".x=1&filename="+base64_encode(filename)+".&path="+base64_encode(currentPath);
}
else
{
write_msg(get_lang('Please select a file'));
return;
}
break;
case 'delete':
filesUrl = "";
var one_checked = false;
files=document.getElementsByName('fileman');
var j=0;
for (i = 0; i < files.length; i++)
if (files[i].checked){
one_checked = true;
filesUrl += "&fileman["+j+"]="+base64_encode(files[i].value);
j++;
}
if (!one_checked)
{
write_msg(get_lang('Please select a file'));
return;
}
cExecute('./index.php?menuaction=filemanager.vfs_functions.delete&path='+
base64_encode(currentPath)+filesUrl,handler.del);
break;
case 'archive':
filesUrl = "";
var one_checked = false;
files=document.getElementsByName('fileman');
var j=0;
for (i = 0; i < files.length; i++)
if (files[i].checked){
one_checked = true;
filesUrl += "&fileman["+j+"]="+base64_encode(files[i].value);
j++;
}
if (!one_checked)
{
write_msg(get_lang('Please select a file'));
return;
}
password = prompt(get_lang('Please, type a strong password (suggestion: at least 8 characters, letters and numbers) or leave it empty to archive only'));
if (password == null)
return;
if (password.length > 0)
{
password2 = prompt(get_lang('Please, retype your password'));
if (password != password2)
{
alert(get_lang('Error:')+get_lang('passwords are differents'));
return;
}
}
// TODO use DES, or something strong
var pswd = crypt(password,currentPath);
cExecute('./index.php?menuaction=filemanager.vfs_functions.archive&pswd='+base64_encode(pswd.toString())+'&path='+base64_encode(currentPath)+filesUrl,handler.archive);
break;
case 'move_to':
case 'copy_to':
filesUrl = "";
var one_checked = false;
files=document.getElementsByName('fileman');
var j=0;
for (i = 0; i < files.length; i++)
if (files[i].checked){
one_checked = true;
filesUrl += "&fileman["+j+"]="+files[i].value;
j++;
}
if (!one_checked)
{
write_msg(get_lang('Please select a file'));
return;
}
var elements = new Array();
inputEl = document.getElementById('content_folders');
for(i=0; i< inputEl.childNodes.length; i++)
{
if (inputEl.childNodes[i].nodeName != 'SPAN')
continue;
elements[i] = new Array();
elements[i]['text']=inputEl.childNodes[i].innerHTML;
address = document.location.toString();
address = address.split("&");
elements[i]['url'] = address[0]+
"&"+escape(arg)+".x=10"+
"&from="+base64_encode(currentPath)+
"&to="+base64_encode(inputEl.childNodes[i].innerHTML)+
filesUrl;
}
draw_menu(arg,elements);
break;
case 'reload':
cExecute('./index.php?menuaction=filemanager.uifilemanager.dir_ls&path='+base64_encode(currentPath)+'&criteria='+criteria+'&otype='+order_type,folderList.drawFiles);
return;
case 'tools':
elements = new Array();
elements[0] = new Array();
elements[0]['text'] = get_lang('Preferences');
elements[0]['url'] = 'preferences/preferences.php?appname=filemanager';
elements[0]['img'] = templatePath+'images/preferences.png';
elements[1] = new Array();
elements[1]['text'] = get_lang('Search');
elements[1]['url'] = 'javascript:\
document.getElementById("menu_newFiletools").style.visibility="hidden";\
document.getElementById("em_message_search").focus();';
elements[1]['img'] = templatePath+'images/search.gif';
/*
elements[2] = new Array();
elements[2]['text'] = get_lang('Edit Folders');
elements[2]['url'] = 'javascript:EditFolders()';
elements[2]['img'] = 'images/mime16_directory.png';
*/
elements[3] = new Array();
elements[3]['text'] = get_lang('Share Folders');
elements[3]['url'] = "./index.php?menuaction=preferences.uiaclprefs.index&acl_app=filemanager";
elements[3]['img'] = templatePath+'images/mime16_directory.png';
elements[4] = new Array();
elements[4]['text'] = get_lang('Edit Columns');
elements[4]['url'] = "javascript:EditColumns()";
elements[4]['img'] = templatePath+'images/editpaste.png';
elements[5] = new Array();
elements[5]['text'] = get_lang('Archive');
elements[5]['url'] = "javascript:toolbar.control('archive')";
elements[5]['img'] = templatePath+'images/button_zip.png';
draw_menu(arg,elements);
break;
default:
return;
}
}
var toolbar = new toolbar();
function unarchive(filename){
password = prompt(get_lang('Please, type archive password or leave it empty if it is not encrypted'));
if (password == null)
return;
var pswd = crypt(password,currentPath);
cExecute('./index.php?menuaction=filemanager.vfs_functions.unarchive&pswd='+base64_encode(pswd)+'&path='+base64_encode(currentPath)+'&file='+base64_encode(filename),handler.archive);
}
function draw_card(filename){
draw_window_card('preview','./index.php?menuaction=filemanager.vfs_functions.summary&file='+base64_encode(filename)+"&path="+base64_encode(currentPath));
}
function draw_window_card(id,url){
var menu = document.getElementById('menu_newFile'+id);
if (menu == null){
menu = document.createElement('DIV');
menu.className = 'menubox';
menu.id = "menu_newFile"+id;
menu.style.left = DocX;
menu.style.top = (DocY+20)+"px";
menu.width = "100%";
menu.innerHTML = '
';
menu.onmouseout = function () { menuTimeout = setTimeout("hide_preview()",50);}
menu.onmouseover = function () { clearTimeout(menuTimeout); };
menu.style.zIndex='1';
document.getElementById('tdAppbox').appendChild(menu);
}
else
{
menu.style.left = DocX;
menu.style.top = (DocY+20)+"px";
menu.innerHTML = '
';
}
menu.style.visibility = 'visible';
clearTimeout(menuTimeout);
menuTimeout = setTimeout("hide_preview()",4000);
}
function hide_preview(){
var e=document.getElementById('menu_newFilepreview');
if (e!=null)
e.style.visibility = 'hidden';
}